use of org.springframework.security.web.authentication.switchuser.SwitchUserGrantedAuthority in project ORCID-Source by ORCID.
the class SourceManagerImpl method isDelegatedByAnAdmin.
@Override
public boolean isDelegatedByAnAdmin() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null) {
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
if (authorities != null) {
for (GrantedAuthority authority : authorities) {
if (authority instanceof SwitchUserGrantedAuthority) {
SwitchUserGrantedAuthority suga = (SwitchUserGrantedAuthority) authority;
Authentication sourceAuthentication = suga.getSource();
if (sourceAuthentication instanceof UsernamePasswordAuthenticationToken && sourceAuthentication.getPrincipal() instanceof OrcidProfileUserDetails) {
org.orcid.jaxb.model.message.OrcidType legacyOrcidType = ((OrcidProfileUserDetails) sourceAuthentication.getPrincipal()).getOrcidType();
OrcidType sourceUserType = legacyOrcidType == null ? null : OrcidType.fromValue(legacyOrcidType.value());
return OrcidType.ADMIN.equals(sourceUserType);
}
}
}
}
}
return false;
}
use of org.springframework.security.web.authentication.switchuser.SwitchUserGrantedAuthority in project ORCID-Source by ORCID.
the class SourceManagerImpl method getRealUserIfInDelegationMode.
private String getRealUserIfInDelegationMode(Authentication authentication) {
if (authentication != null) {
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
if (authorities != null) {
for (GrantedAuthority authority : authorities) {
if (authority instanceof SwitchUserGrantedAuthority) {
SwitchUserGrantedAuthority suga = (SwitchUserGrantedAuthority) authority;
Authentication sourceAuthentication = suga.getSource();
if ((sourceAuthentication instanceof UsernamePasswordAuthenticationToken || sourceAuthentication instanceof PreAuthenticatedAuthenticationToken) && sourceAuthentication.getPrincipal() instanceof OrcidProfileUserDetails) {
return ((OrcidProfileUserDetails) sourceAuthentication.getPrincipal()).getOrcid();
}
}
}
}
}
return null;
}
Aggregations