Search in sources :

Example 26 with OrcidProfileUserDetails

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

the class FundingsControllerTest method getAuthentication.

@Override
protected Authentication getAuthentication() {
    orcidProfile = orcidProfileManager.retrieveOrcidProfile("4444-4444-4444-4443");
    List<OrcidWebRole> roles = Arrays.asList(OrcidWebRole.ROLE_USER);
    OrcidProfileUserDetails details = new OrcidProfileUserDetails(orcidProfile.retrieveOrcidPath(), orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue(), null, roles);
    UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("4444-4444-4444-4443", details.getPassword(), 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 27 with OrcidProfileUserDetails

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

the class GetMyDataControllerTest method getAuthentication.

private Authentication getAuthentication() {
    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 28 with OrcidProfileUserDetails

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

the class LoginApplicationListener method onApplicationEvent.

/**
 * Handle an application event.
 *
 * @param event
 *            the event to respond to
 */
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof AuthenticationSuccessEvent) {
        Object source = event.getSource();
        if (source instanceof UsernamePasswordAuthenticationToken) {
            UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) source;
            Object principal = token.getPrincipal();
            if (principal instanceof OrcidProfileUserDetails) {
                OrcidProfileUserDetails userDetails = (OrcidProfileUserDetails) principal;
                String orcid = userDetails.getOrcid();
                String email = userDetails.getPrimaryEmail();
                String sessionId = RequestContextHolder.currentRequestAttributes().getSessionId();
                LOGGER.info("User logged in with orcid={}, email={}, sessionid={}", new Object[] { orcid, email, sessionId });
            }
        }
    }
}
Also used : OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails) AuthenticationSuccessEvent(org.springframework.security.authentication.event.AuthenticationSuccessEvent) 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