-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
ProtectedJwtResource.java
52 lines (42 loc) · 1.27 KB
/
ProtectedJwtResource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package io.quarkus.it.keycloak;
import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.SecurityContext;
import org.eclipse.microprofile.jwt.JsonWebToken;
import io.quarkus.security.Authenticated;
import io.quarkus.security.identity.SecurityIdentity;
@Path("/web-app")
@Authenticated
public class ProtectedJwtResource {
@Inject
SecurityIdentity identity;
@Inject
JsonWebToken accessToken;
@Context
SecurityContext securityContext;
@GET
@Path("test-security")
@RolesAllowed("viewer")
public String testSecurity() {
return securityContext.getUserPrincipal().getName();
}
@POST
@Path("test-security")
@Consumes("application/json")
@RolesAllowed("viewer")
public String testSecurityJson(User user) {
return user.getName() + ":" + securityContext.getUserPrincipal().getName();
}
@GET
@Path("test-security-jwt")
@RolesAllowed("viewer")
public String testSecurityJwt() {
return accessToken.getName() + ":" + accessToken.getGroups().iterator().next()
+ ":" + accessToken.getClaim("email");
}
}