From 4d8139fbbdcbaaac2d6b8e0b7ad379cc4d0eb62d Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Thu, 10 Sep 2020 15:39:10 +0200 Subject: KB56 Add login button and status box. Change-Id: I72658014b2198a1a01ffa02ad4bafcdf9d66ab2b --- .../mulk/mulkcms2/benki/login/LoginResource.java | 24 ++++++++++++++++++++++ .../eu/mulk/mulkcms2/benki/login/LoginStatus.java | 23 +++++++++++++++++++++ .../eu/mulk/mulkcms2/benki/wiki/WikiResource.java | 6 +++--- .../resources/META-INF/resources/cms2/base.css | 13 ++++++++++-- src/main/resources/application.properties | 2 ++ src/main/resources/templates/tags/navbar.html | 12 +++++++++++ 6 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 src/main/java/eu/mulk/mulkcms2/benki/login/LoginResource.java create mode 100644 src/main/java/eu/mulk/mulkcms2/benki/login/LoginStatus.java (limited to 'src') diff --git a/src/main/java/eu/mulk/mulkcms2/benki/login/LoginResource.java b/src/main/java/eu/mulk/mulkcms2/benki/login/LoginResource.java new file mode 100644 index 0000000..53fbcf6 --- /dev/null +++ b/src/main/java/eu/mulk/mulkcms2/benki/login/LoginResource.java @@ -0,0 +1,24 @@ +package eu.mulk.mulkcms2.benki.login; + +import io.quarkus.security.Authenticated; +import java.net.URI; +import java.net.URISyntaxException; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; +import org.jboss.logging.Logger; + +@Path("/login") +public class LoginResource { + + private static final Logger log = Logger.getLogger(LoginResource.class); + + @GET + @Authenticated + public Response getRoot(@HeaderParam("referer") @DefaultValue("/posts") String referer) + throws URISyntaxException { + return Response.seeOther(new URI(referer)).build(); + } +} diff --git a/src/main/java/eu/mulk/mulkcms2/benki/login/LoginStatus.java b/src/main/java/eu/mulk/mulkcms2/benki/login/LoginStatus.java new file mode 100644 index 0000000..06a184c --- /dev/null +++ b/src/main/java/eu/mulk/mulkcms2/benki/login/LoginStatus.java @@ -0,0 +1,23 @@ +package eu.mulk.mulkcms2.benki.login; + +import io.quarkus.qute.TemplateData; +import io.quarkus.security.identity.SecurityIdentity; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.inject.Named; + +@Named("LoginStatus") +@RequestScoped +@TemplateData +public class LoginStatus { + + @Inject SecurityIdentity identity; + + public boolean loggedIn() { + return !identity.isAnonymous(); + } + + public String getUserName() { + return identity.getPrincipal().getName(); + } +} diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java index 2ffcdd5..7b2395d 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java @@ -64,7 +64,7 @@ public class WikiResource { } @GET - @Path("/{pageName}") + @Path("{pageName}") @Produces(TEXT_HTML) @Authenticated public TemplateInstance getPage(@PathParam("pageName") String pageName) { @@ -82,7 +82,7 @@ public class WikiResource { } @POST - @Path("/{pageName}") + @Path("{pageName}") @Authenticated @Transactional @Produces(APPLICATION_JSON) @@ -136,7 +136,7 @@ public class WikiResource { } @GET - @Path("/{pageName}/revisions") + @Path("{pageName}/revisions") @Produces(TEXT_HTML) @Authenticated public TemplateInstance getPageRevisions(@PathParam("pageName") String pageName) { diff --git a/src/main/resources/META-INF/resources/cms2/base.css b/src/main/resources/META-INF/resources/cms2/base.css index bad03b6..06873d5 100644 --- a/src/main/resources/META-INF/resources/cms2/base.css +++ b/src/main/resources/META-INF/resources/cms2/base.css @@ -125,7 +125,7 @@ body > nav > ol > li.this-page { z-index: 1; } -body > nav > ol > li > a { +body > nav > ol > li > * { text-decoration: none; display: block; padding: 5px; @@ -136,10 +136,19 @@ body > nav a:hover { background-color: #f8f8f8; } -body > nav li[data-site-section="About"] { +body > nav li[data-site-section="About"], body > nav li[data-site-section="Login"] { margin-top: 1em; } +.login-text { + font-style: italic; +} + +.login-name { + font-style: normal; + font-family: cursive; +} + body > main { grid-area: main; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a38af40..e966bda 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -28,6 +28,8 @@ quarkus.liquibase.migrate-at-start = true %prod.quarkus.hibernate-orm.log.sql = false # Authentication +quarkus.http.auth.proactive = true + quarkus.oidc.auth-server-url = https://login.benkard.de/auth/realms/master quarkus.oidc.client-id = mulkcms quarkus.oidc.application-type = web-app diff --git a/src/main/resources/templates/tags/navbar.html b/src/main/resources/templates/tags/navbar.html index a6ba163..0259362 100644 --- a/src/main/resources/templates/tags/navbar.html +++ b/src/main/resources/templates/tags/navbar.html @@ -5,5 +5,17 @@
  • Bookmarks
  • Lazy Chat
  • Wiki
  • +
  • Contact Info
  • + + {#if inject:LoginStatus.loggedIn} +
  • + +
  • + {#else} +
  • + + Log In +
  • + {/if} -- cgit v1.2.3