diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2020-01-24 13:25:54 +0100 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2020-01-24 13:25:54 +0100 |
commit | 24a25144eaaf1c0a13b7fe746a1e453010dd14cf (patch) | |
tree | 628679309b075430d5e837de1ead78dfe2bbcb30 /src/main/java/eu | |
parent | 55c42a59a51c35b3148d6da8d3a8c510b2dcdc85 (diff) |
Enable authentication via Keycloak.
Change-Id: I81a05d2e965394b13d7344f4f20475b4e468c761
Diffstat (limited to 'src/main/java/eu')
-rw-r--r-- | src/main/java/eu/mulk/mulkcms2/cms/web/ExampleResource.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/cms/web/ExampleResource.java b/src/main/java/eu/mulk/mulkcms2/cms/web/ExampleResource.java index fc504c8..76602c8 100644 --- a/src/main/java/eu/mulk/mulkcms2/cms/web/ExampleResource.java +++ b/src/main/java/eu/mulk/mulkcms2/cms/web/ExampleResource.java @@ -1,14 +1,31 @@ package eu.mulk.mulkcms2.cms.web; +import io.quarkus.security.Authenticated; +import io.quarkus.security.identity.SecurityIdentity; +import io.smallrye.jwt.auth.principal.JWTCallerPrincipal; +import javax.inject.Inject; import javax.ws.rs.GET; +import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import org.jboss.logging.Logger; +@Path("/example") public class ExampleResource { + private static Logger log = Logger.getLogger(ExampleResource.class); + + @Inject + SecurityIdentity identity; + @GET @Produces({MediaType.TEXT_PLAIN}) + @Authenticated public String hello() { + if (!identity.isAnonymous()) { + var jwtCallerPrincipal = (JWTCallerPrincipal) identity.getPrincipal(); + log.infof("Logged in as user: %s", jwtCallerPrincipal.getName()); + } return "hello!"; } } |