Search in sources :

Example 6 with OrcidProfileUserDetails

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

the class OrcidTogglzConfiguration method getUserProvider.

@Override
public UserProvider getUserProvider() {
    return new UserProvider() {

        @Override
        public FeatureUser getCurrentUser() {
            boolean isAdmin = false;
            String userOrcid = null;
            SecurityContext context = SecurityContextHolder.getContext();
            if (context != null && context.getAuthentication() != null) {
                Authentication authentication = context.getAuthentication();
                if (authentication != null) {
                    Object principal = authentication.getDetails();
                    if (principal instanceof OrcidProfileUserDetails) {
                        OrcidProfileUserDetails userDetails = (OrcidProfileUserDetails) principal;
                        isAdmin = userDetails.getAuthorities().contains(OrcidWebRole.ROLE_ADMIN);
                        userOrcid = userDetails.getOrcid();
                    }
                }
            }
            return new SimpleFeatureUser(userOrcid, isAdmin);
        }
    };
}
Also used : UserProvider(org.togglz.core.user.UserProvider) SimpleFeatureUser(org.togglz.core.user.SimpleFeatureUser) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails)

Example 7 with OrcidProfileUserDetails

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

the class OrcidUserDetailsServiceImpl method createUserDetails.

private OrcidProfileUserDetails createUserDetails(ProfileEntity profile) {
    String primaryEmail = retrievePrimaryEmail(profile);
    OrcidProfileUserDetails userDetails = null;
    if (profile.getOrcidType() != null) {
        OrcidType orcidType = OrcidType.fromValue(profile.getOrcidType().value());
        userDetails = new OrcidProfileUserDetails(profile.getId(), primaryEmail, profile.getEncryptedPassword(), buildAuthorities(orcidType, profile.getGroupType()));
    } else {
        userDetails = new OrcidProfileUserDetails(profile.getId(), primaryEmail, profile.getEncryptedPassword());
    }
    if (!salesForceManager.retrieveAccountIdsByOrcid(profile.getId()).isEmpty()) {
        userDetails.getAuthorities().add(OrcidWebRole.ROLE_SELF_SERVICE);
    }
    return userDetails;
}
Also used : OrcidType(org.orcid.jaxb.model.v3.dev1.common.OrcidType) OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails)

Example 8 with OrcidProfileUserDetails

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

the class ManageProfileControllerTest method getAuthentication.

protected Authentication getAuthentication(String orcid) {
    List<OrcidWebRole> roles = Arrays.asList(OrcidWebRole.ROLE_USER);
    OrcidProfileUserDetails details = new OrcidProfileUserDetails(orcid, "user_1@test.orcid.org", null, roles);
    UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(orcid, null, roles);
    auth.setDetails(details);
    return auth;
}
Also used : OrcidWebRole(org.orcid.core.security.OrcidWebRole) OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 9 with OrcidProfileUserDetails

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

the class AdminControllerTest method getAuthentication.

@Override
protected Authentication getAuthentication() {
    orcidProfile = orcidProfileManager.retrieveOrcidProfile("4444-4444-4444-4440");
    List<OrcidWebRole> roles = getRole();
    OrcidProfileUserDetails details = new OrcidProfileUserDetails(orcidProfile.retrieveOrcidPath(), orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue(), null, roles);
    UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(orcidProfile.retrieveOrcidPath(), orcidProfile.getPassword(), getRole());
    auth.setDetails(details);
    return auth;
}
Also used : OrcidWebRole(org.orcid.core.security.OrcidWebRole) OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 10 with OrcidProfileUserDetails

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

the class BaseControllerUtilTest method getCurrentUserPreAuthenticatedAuthenticationToken.

@Test
public void getCurrentUserPreAuthenticatedAuthenticationToken() {
    SecurityContext context = mock(SecurityContext.class);
    PreAuthenticatedAuthenticationToken usernamePasswordAuthenticationToken = mock(PreAuthenticatedAuthenticationToken.class);
    OrcidProfileUserDetails orcidProfileUserDetails = mock(OrcidProfileUserDetails.class);
    when(context.getAuthentication()).thenReturn(usernamePasswordAuthenticationToken);
    when(usernamePasswordAuthenticationToken.getDetails()).thenReturn(orcidProfileUserDetails);
    assertNotNull(baseControllerUtil.getCurrentUser(context));
}
Also used : SecurityContext(org.springframework.security.core.context.SecurityContext) OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)

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