-
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.
WIP
- Loading branch information
Showing
7 changed files
with
208 additions
and
3,747 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
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
24 changes: 24 additions & 0 deletions
24
pac4j-module/src/main/java/net/unicon/shibui/pac4j/SAML2ModelAuthorizationGenerator.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,24 @@ | ||
package net.unicon.shibui.pac4j; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.security.model.User; | ||
import edu.internet2.tier.shibboleth.admin.ui.security.repository.UserRepository; | ||
import org.pac4j.core.authorization.generator.AuthorizationGenerator; | ||
import org.pac4j.core.context.WebContext; | ||
import org.pac4j.saml.profile.SAML2Profile; | ||
|
||
import java.util.Optional; | ||
|
||
public class SAML2ModelAuthorizationGenerator implements AuthorizationGenerator<SAML2Profile> { | ||
private final UserRepository userRepository; | ||
|
||
public SAML2ModelAuthorizationGenerator(UserRepository userRepository) { | ||
this.userRepository = userRepository; | ||
} | ||
|
||
@Override | ||
public SAML2Profile generate(WebContext context, SAML2Profile profile) { | ||
Optional<User> user = userRepository.findByUsername(profile.getUsername()); | ||
user.ifPresent( u -> profile.addRole(u.getRole())); | ||
return profile; | ||
} | ||
} |
141 changes: 141 additions & 0 deletions
141
pac4j-module/src/main/java/org/pac4j/core/profile/CommonProfile.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,141 @@ | ||
package org.pac4j.core.profile; | ||
|
||
import org.pac4j.core.context.Pac4jConstants; | ||
import org.pac4j.core.profile.definition.CommonProfileDefinition; | ||
|
||
import java.net.URI; | ||
import java.security.Principal; | ||
import java.util.Collection; | ||
import java.util.Locale; | ||
|
||
/** | ||
* This class is the base implementation with the default attribute getters which can be retrieved for most profiles. | ||
* | ||
* @author Jerome Leleu | ||
* @since 1.3.0 | ||
*/ | ||
public class CommonProfile extends UserProfile { | ||
|
||
private static final long serialVersionUID = -1856159870249261877L; | ||
|
||
public CommonProfile() { | ||
//default constructor for backwards compatibility | ||
} | ||
|
||
/** | ||
* Create a profile with possibility to merge attributes with the same name and collection-type values | ||
* @param canMergeAttributes if true - merge attributes with the same name and collection-type values, if false - overwrite them | ||
* @since 3.1.0 | ||
*/ | ||
public CommonProfile( boolean canMergeAttributes ) { | ||
super( canMergeAttributes ); | ||
} | ||
|
||
/** | ||
* Return the email of the user. | ||
* | ||
* @return the email of the user | ||
*/ | ||
public String getEmail() { | ||
return (String) getAttribute(CommonProfileDefinition.EMAIL); | ||
} | ||
|
||
/** | ||
* Return the first name of the user. | ||
* | ||
* @return the first name of the user | ||
*/ | ||
public String getFirstName() { | ||
return (String) getAttribute(CommonProfileDefinition.FIRST_NAME); | ||
} | ||
|
||
/** | ||
* Return the family name of the user. | ||
* | ||
* @return the family name of the user | ||
*/ | ||
public String getFamilyName() { | ||
return (String) getAttribute(CommonProfileDefinition.FAMILY_NAME); | ||
} | ||
|
||
/** | ||
* Return the displayed name of the user. It can be the username or the first and last names (separated by a space). | ||
* | ||
* @return the displayed name of the user | ||
*/ | ||
public String getDisplayName() { | ||
return (String) getAttribute(CommonProfileDefinition.DISPLAY_NAME); | ||
} | ||
|
||
/** | ||
* Return the username of the user. It can be a login or a specific username. | ||
* | ||
* @return the username of the user | ||
*/ | ||
public String getUsername() { | ||
Object username = getAttribute(Pac4jConstants.USERNAME); | ||
if (username instanceof Collection) { | ||
return (String) ((Collection)username).toArray()[0]; | ||
} else { | ||
return (String) username; | ||
} | ||
} | ||
|
||
/** | ||
* Return the gender of the user. | ||
* | ||
* @return the gender of the user | ||
*/ | ||
public Gender getGender() { | ||
final Gender gender = (Gender) getAttribute(CommonProfileDefinition.GENDER); | ||
if (gender == null) { | ||
return Gender.UNSPECIFIED; | ||
} else { | ||
return gender; | ||
} | ||
} | ||
|
||
/** | ||
* Return the locale of the user. | ||
* | ||
* @return the locale of the user | ||
*/ | ||
public Locale getLocale() { | ||
return (Locale) getAttribute(CommonProfileDefinition.LOCALE); | ||
} | ||
|
||
/** | ||
* Return the url of the picture of the user. | ||
* | ||
* @return the url of the picture of the user. | ||
*/ | ||
public URI getPictureUrl() { | ||
return (URI) getAttribute(CommonProfileDefinition.PICTURE_URL); | ||
} | ||
|
||
/** | ||
* Return the url of the profile of the user. | ||
* | ||
* @return the url of the profile of the user. | ||
*/ | ||
public URI getProfileUrl() { | ||
return (URI) getAttribute(CommonProfileDefinition.PROFILE_URL); | ||
} | ||
|
||
/** | ||
* Return the location of the user. | ||
* | ||
* @return the location of the user | ||
*/ | ||
public String getLocation() { | ||
return (String) getAttribute(CommonProfileDefinition.LOCATION); | ||
} | ||
|
||
public Principal asPrincipal() { | ||
return new Pac4JPrincipal(this); | ||
} | ||
|
||
public boolean isExpired() { | ||
return false; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
spring: | ||
profiles: | ||
include: dev | ||
server: | ||
port: 8443 | ||
ssl: | ||
|
Oops, something went wrong.