Search in sources :

Example 21 with OrcidProfileUserDetails

use of org.orcid.core.oauth.OrcidProfileUserDetails 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.getDetails() instanceof OrcidProfileUserDetails) {
                        return ((OrcidProfileUserDetails) sourceAuthentication.getDetails()).getAuthorities().contains(OrcidWebRole.ROLE_ADMIN);
                    }
                }
            }
        }
    }
    return false;
}
Also used : OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SwitchUserGrantedAuthority(org.springframework.security.web.authentication.switchuser.SwitchUserGrantedAuthority) OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) SwitchUserGrantedAuthority(org.springframework.security.web.authentication.switchuser.SwitchUserGrantedAuthority)

Example 22 with OrcidProfileUserDetails

use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.

the class PeerReviewsControllerTest method getAuthentication.

@Override
protected Authentication getAuthentication() {
    orcidProfile = orcidProfileManager.retrieveOrcidProfile("4444-4444-4444-4446");
    OrcidProfileUserDetails details = (OrcidProfileUserDetails) orcidUserDetailsService.loadUserByUsername(orcidProfile.retrieveOrcidPath());
    UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("4444-4444-4444-4446", null, Arrays.asList(OrcidWebRole.ROLE_USER));
    auth.setDetails(details);
    return auth;
}
Also used : OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 23 with OrcidProfileUserDetails

use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.

the class BaseControllerTest method getAuthentication.

protected Authentication getAuthentication(String orcid) {
    if (orcidProfile == null) {
        orcidProfile = getOrcidProfile();
    }
    OrcidProfileUserDetails details = (OrcidProfileUserDetails) orcidUserDetailsService.loadUserByUsername(orcidProfile.retrieveOrcidPath());
    UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(orcid, details.getPassword(), Arrays.asList(OrcidWebRole.ROLE_USER));
    auth.setDetails(details);
    return auth;
}
Also used : OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 24 with OrcidProfileUserDetails

use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.

the class ClientsControllerTest method getAuthentication.

@Override
protected Authentication getAuthentication() {
    OrcidProfileUserDetails details = new OrcidProfileUserDetails("5555-5555-5555-5558", "5555-5555-5555-5558@user.com", "e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA=");
    UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("5555-5555-5555-5558", null, Arrays.asList(OrcidWebRole.ROLE_PREMIUM_INSTITUTION));
    auth.setDetails(details);
    return auth;
}
Also used : OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 25 with OrcidProfileUserDetails

use of org.orcid.core.oauth.OrcidProfileUserDetails in project ORCID-Source by ORCID.

the class CustomEmailControllerTest method getAuthentication.

@Override
protected Authentication getAuthentication() {
    orcidProfile = orcidProfileManager.retrieveOrcidProfile("5555-5555-5555-5558");
    OrcidProfileUserDetails details = (OrcidProfileUserDetails) orcidUserDetailsService.loadUserByUsername(orcidProfile.retrieveOrcidPath());
    UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("5555-5555-5555-5558", details.getPassword(), getRole());
    auth.setDetails(details);
    return auth;
}
Also used : OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Aggregations

OrcidProfileUserDetails (org.orcid.core.oauth.OrcidProfileUserDetails)28 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)18 Authentication (org.springframework.security.core.Authentication)7 OrcidWebRole (org.orcid.core.security.OrcidWebRole)5 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)5 GrantedAuthority (org.springframework.security.core.GrantedAuthority)4 SecurityContext (org.springframework.security.core.context.SecurityContext)4 SwitchUserGrantedAuthority (org.springframework.security.web.authentication.switchuser.SwitchUserGrantedAuthority)4 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)3 Email (org.orcid.jaxb.model.message.Email)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 SimpleFeatureUser (org.togglz.core.user.SimpleFeatureUser)2 UserProvider (org.togglz.core.user.UserProvider)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Test (org.junit.Test)1 OrcidOauth2UserAuthentication (org.orcid.core.oauth.OrcidOauth2UserAuthentication)1 OrcidType (org.orcid.jaxb.model.common_v2.OrcidType)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1 OrcidType (org.orcid.jaxb.model.message.OrcidType)1 OrcidType (org.orcid.jaxb.model.v3.dev1.common.OrcidType)1