-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Require logging in for secure area
- Loading branch information
1 parent
a3c7224
commit 292d3d0
Showing
14 changed files
with
193 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/adapters/web/src/main/java/it/mulders/traqqr/web/security/OidcConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package it.mulders.traqqr.web.security; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Named; | ||
|
||
@ApplicationScoped | ||
@Named("oidcConfig") | ||
public class OidcConfig { | ||
private final String clientId; | ||
private final String clientSecret; | ||
|
||
public OidcConfig() { | ||
var environment = System.getenv(); | ||
this.clientId = environment.get("OPENID_CLIENT_ID"); | ||
this.clientSecret = environment.get("OPENID_CLIENT_SECRET"); | ||
} | ||
|
||
public String getClientId() { | ||
return clientId; | ||
} | ||
|
||
public String getClientSecret() { | ||
return clientSecret; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/adapters/web/src/main/java/it/mulders/traqqr/web/security/SecurityConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package it.mulders.traqqr.web.security; | ||
|
||
import jakarta.security.enterprise.authentication.mechanism.http.OpenIdAuthenticationMechanismDefinition; | ||
import jakarta.security.enterprise.authentication.mechanism.http.openid.ClaimsDefinition; | ||
import jakarta.security.enterprise.authentication.mechanism.http.openid.LogoutDefinition; | ||
|
||
@OpenIdAuthenticationMechanismDefinition( | ||
claimsDefinition = @ClaimsDefinition( | ||
callerNameClaim = "sub" | ||
), | ||
clientId = "${oidcConfig.clientId}", | ||
clientSecret = "${oidcConfig.clientSecret}", | ||
logout = @LogoutDefinition( | ||
redirectURI = "${baseURL}" | ||
), | ||
providerURI = "https://accounts.google.com/.well-known/openid-configuration", | ||
redirectURI = "${baseURL}/auth/callback/google", | ||
redirectToOriginalResource = true, | ||
useNonce = true, | ||
useSession = true | ||
) | ||
public class SecurityConfiguration { | ||
} |
26 changes: 26 additions & 0 deletions
26
app/adapters/web/src/main/java/it/mulders/traqqr/web/security/TraqqrIdentityStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package it.mulders.traqqr.web.security; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.security.enterprise.identitystore.CredentialValidationResult; | ||
import jakarta.security.enterprise.identitystore.IdentityStore; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.EnumSet; | ||
import java.util.Set; | ||
|
||
@ApplicationScoped | ||
public class TraqqrIdentityStore implements IdentityStore { | ||
private static final Logger log = LoggerFactory.getLogger(TraqqrIdentityStore.class); | ||
|
||
@Override | ||
public Set<String> getCallerGroups(final CredentialValidationResult validationResult) { | ||
log.info("Assigning groups; caller_unique_id={}", validationResult.getCallerUniqueId()); | ||
return Set.of("user"); | ||
} | ||
|
||
@Override | ||
public Set<ValidationType> validationTypes() { | ||
return EnumSet.of(ValidationType.PROVIDE_GROUPS); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/adapters/web/src/main/java/it/mulders/traqqr/web/user/UserInfoBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package it.mulders.traqqr.web.user; | ||
|
||
import jakarta.enterprise.context.SessionScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Named; | ||
import jakarta.security.enterprise.SecurityContext; | ||
import jakarta.security.enterprise.identitystore.openid.OpenIdContext; | ||
|
||
import java.io.Serializable; | ||
|
||
@Named | ||
@SessionScoped | ||
public class UserInfoBean implements Serializable { | ||
private final String displayName; | ||
private final String profilePictureUrl; | ||
|
||
@Inject | ||
public UserInfoBean(final SecurityContext securityContext, | ||
final OpenIdContext openIdContext) { | ||
var claims = openIdContext.getClaims(); | ||
this.displayName = claims.getName().orElse("unknown user"); | ||
this.profilePictureUrl = claims.getPicture().orElse(null); | ||
} | ||
|
||
public String getUsername() {// name, picture, email | ||
return displayName; | ||
} | ||
|
||
public String getProfilePictureUrl() { | ||
return profilePictureUrl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd" | ||
version="4.0" | ||
bean-discovery-mode="all"> | ||
</beans> |
24 changes: 24 additions & 0 deletions
24
app/adapters/web/src/main/webapp/WEB-INF/layout-closed.xhtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:h="http://xmlns.jcp.org/jsf/html" | ||
xmlns:ui="http://xmlns.jcp.org/jsf/facelets" | ||
xmlns:p="http://primefaces.org/ui"> | ||
<h:head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||
<title><ui:insert name="title">Default Title</ui:insert> | Traqqr</title> | ||
</h:head> | ||
<body> | ||
<ui:debug/> | ||
|
||
<div class="content"> | ||
<ui:insert name="content"/> | ||
</div> | ||
|
||
<hr /> | ||
<!-- alleen als ingelogd --> | ||
<p:outputPanel> | ||
Traqqr ${systemInfo.applicationVersion} (revision <code>${systemInfo.gitVersion}</code>) is made with ❤️ + ☕ + <a href="https://dev.java/" target="_blank">Java ${systemInfo.javaVersion}</a> + <a href="https://jakarta.ee/" target="_blank">Jakarta EE 10</a>. | ||
Proudly running on ${systemInfo.javaRuntime}. | ||
</p:outputPanel> | ||
</body> | ||
</html> |
3 changes: 2 additions & 1 deletion
3
.../web/src/main/webapp/WEB-INF/layout.xhtml → ...src/main/webapp/WEB-INF/layout-open.xhtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<ui:composition | ||
xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:f="http://xmlns.jcp.org/jsf/core" | ||
xmlns:ui="http://xmlns.jcp.org/jsf/facelets" | ||
xmlns:p="http://primefaces.org/ui" | ||
template="/WEB-INF/layout-closed.xhtml"> | ||
<ui:define name="title">Start</ui:define> | ||
|
||
<ui:define name="content"> | ||
<p:card> | ||
<f:facet name="title">Secure Dashboard</f:facet> | ||
|
||
<p>Hi ${userInfoBean.username}!</p> | ||
</p:card> | ||
</ui:define> | ||
</ui:composition> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters