-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Spring Session to store the Manage applications for institutionAdmin
- Loading branch information
Showing
7 changed files
with
122 additions
and
80 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
54 changes: 54 additions & 0 deletions
54
server/src/main/java/access/security/CustomOidcUserService.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,54 @@ | ||
package access.security; | ||
|
||
import access.manage.Manage; | ||
import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserRequest; | ||
import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserService; | ||
import org.springframework.security.oauth2.client.userinfo.OAuth2UserService; | ||
import org.springframework.security.oauth2.core.OAuth2AuthenticationException; | ||
import org.springframework.security.oauth2.core.oidc.OidcUserInfo; | ||
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser; | ||
import org.springframework.security.oauth2.core.oidc.user.OidcUser; | ||
import org.springframework.util.StringUtils; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static access.security.InstitutionAdmin.*; | ||
|
||
public class CustomOidcUserService implements OAuth2UserService<OidcUserRequest, OidcUser> { | ||
private final Manage manage; | ||
private final String entitlement; | ||
private final String organizationGuidPrefix; | ||
private final OidcUserService delegate; | ||
|
||
public CustomOidcUserService(Manage manage, String entitlement, String organizationGuidPrefix) { | ||
this.manage = manage; | ||
this.entitlement = entitlement; | ||
this.organizationGuidPrefix = organizationGuidPrefix; | ||
delegate = new OidcUserService(); | ||
} | ||
|
||
@Override | ||
public OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2AuthenticationException { | ||
// Delegate to the default implementation for loading a user | ||
OidcUser oidcUser = delegate.loadUser(userRequest); | ||
Map<String, Object> claims = oidcUser.getUserInfo().getClaims(); | ||
Map<String, Object> newClaims = new HashMap<>(claims); | ||
|
||
boolean institutionAdmin = InstitutionAdmin.isInstitutionAdmin(claims, entitlement); | ||
newClaims.put(INSTITUTION_ADMIN, institutionAdmin); | ||
|
||
String organizationGuid = InstitutionAdmin.getOrganizationGuid(claims, organizationGuidPrefix).orElse(null); | ||
newClaims.put(ORGANIZATION_GUID, organizationGuid); | ||
|
||
if (institutionAdmin && StringUtils.hasText(organizationGuid)) { | ||
List<Map<String, Object>> applications = manage.providersByInstitutionalGUID(organizationGuid); | ||
newClaims.put(APPLICATIONS, applications); | ||
} | ||
OidcUserInfo oidcUserInfo = new OidcUserInfo(newClaims); | ||
oidcUser = new DefaultOidcUser(oidcUser.getAuthorities(), oidcUser.getIdToken(), oidcUserInfo); | ||
return oidcUser; | ||
|
||
} | ||
} |
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