-
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.
merge gone bad resolution
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...main/java/net/unicon/shibui/pac4j/authenticator/ShibuiPac4JHeaderClientAuthenticator.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,40 @@ | ||
package net.unicon.shibui.pac4j.authenticator; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.security.service.UserService; | ||
import lombok.AllArgsConstructor; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.pac4j.core.context.WebContext; | ||
import org.pac4j.core.credentials.Credentials; | ||
import org.pac4j.core.credentials.TokenCredentials; | ||
import org.pac4j.core.credentials.authenticator.Authenticator; | ||
import org.pac4j.core.exception.CredentialsException; | ||
import org.pac4j.core.profile.CommonProfile; | ||
|
||
/** | ||
* Handles parsing the header tokens when using the Pac4J Header client | ||
*/ | ||
@AllArgsConstructor | ||
public class ShibuiPac4JHeaderClientAuthenticator implements Authenticator { | ||
private UserService userService; | ||
|
||
@Override | ||
public void validate(Credentials credentials, WebContext context) { | ||
{ | ||
if (credentials instanceof TokenCredentials) { | ||
TokenCredentials creds = (TokenCredentials) credentials; | ||
String token = creds.getToken(); | ||
if (StringUtils.isAllBlank(token)) { | ||
throw new CredentialsException("Supplied token value in header was missing or blank"); | ||
} | ||
} else { | ||
throw new CredentialsException("Invalid Credentials object generated by HeaderClient"); | ||
} | ||
final CommonProfile profile = new CommonProfile(); | ||
String token = ((TokenCredentials) credentials).getToken(); | ||
profile.setId(token); | ||
profile.addAttribute("username", token); | ||
profile.setRoles(userService.getUserRoles(token)); | ||
credentials.setUserProfile(profile); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...-module/src/main/java/net/unicon/shibui/pac4j/authenticator/ShibuiSAML2Authenticator.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 net.unicon.shibui.pac4j.authenticator; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.security.service.UserService; | ||
import lombok.AllArgsConstructor; | ||
import org.pac4j.core.context.WebContext; | ||
import org.pac4j.core.profile.CommonProfile; | ||
import org.pac4j.saml.credentials.SAML2Credentials; | ||
import org.pac4j.saml.credentials.authenticator.SAML2Authenticator; | ||
|
||
import java.util.Map; | ||
|
||
public class ShibuiSAML2Authenticator extends SAML2Authenticator { | ||
private final UserService userService; | ||
|
||
public ShibuiSAML2Authenticator(final String attributeAsId, final Map<String, String> mappedAttributes, UserService userService) { | ||
super(attributeAsId, mappedAttributes); | ||
this.userService = userService; | ||
} | ||
|
||
/** | ||
* After setting up the information for the user from the SAML, add user roles from the DB if they exist | ||
* @param credentials | ||
* @param context | ||
*/ | ||
@Override | ||
public void validate(final SAML2Credentials credentials, final WebContext context) { | ||
super.validate(credentials, context); | ||
CommonProfile profile = credentials.getUserProfile(); | ||
profile.setRoles(userService.getUserRoles(profile.getUsername())); | ||
credentials.setUserProfile(profile); | ||
} | ||
} |