Search in sources :

Example 1 with UniversalUserToken

use of gov.ca.cwds.UniversalUserToken in project perry by ca-cwds.

the class DevAuthenticationProvider method authenticate.

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    tryAuthenticate(authentication);
    String json = authentication.getName();
    String userName = getUserName(json);
    UniversalUserToken userToken = new UniversalUserToken();
    userToken.setToken(UUID.randomUUID().toString());
    userToken.setUserId(userName);
    userToken.setParameter(IDENTITY, json);
    return new UsernamePasswordAuthenticationToken(userToken, "N/A", Collections.singletonList(new SimpleGrantedAuthority("ROLE_USER")));
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) UniversalUserToken(gov.ca.cwds.UniversalUserToken) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 2 with UniversalUserToken

use of gov.ca.cwds.UniversalUserToken in project perry by ca-cwds.

the class LoginServiceDev method issueAccessCode.

@Override
public String issueAccessCode(String providerId) {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken("test");
    accessToken.setAdditionalInformation(new HashMap<>());
    UniversalUserToken userToken = (UniversalUserToken) securityContext.getAuthentication().getPrincipal();
    accessToken.getAdditionalInformation().put(Constants.IDENTITY, userToken.getParameter(IDENTITY));
    return tokenService.issueAccessCode(userToken, accessToken);
}
Also used : UniversalUserToken(gov.ca.cwds.UniversalUserToken) SecurityContext(org.springframework.security.core.context.SecurityContext) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)

Example 3 with UniversalUserToken

use of gov.ca.cwds.UniversalUserToken in project perry by ca-cwds.

the class LoginServiceImpl method issueAccessCode.

@Override
public String issueAccessCode(String providerId) {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    OAuth2Authentication authentication = (OAuth2Authentication) securityContext.getAuthentication();
    UniversalUserToken userToken = (UniversalUserToken) authentication.getPrincipal();
    OAuth2AccessToken accessToken = clientContext.getAccessToken();
    String identity = identityMappingService.map(userToken, providerId);
    accessToken.getAdditionalInformation().put(Constants.IDENTITY, identity);
    return tokenService.issueAccessCode(userToken, accessToken);
}
Also used : UniversalUserToken(gov.ca.cwds.UniversalUserToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext)

Example 4 with UniversalUserToken

use of gov.ca.cwds.UniversalUserToken in project perry by ca-cwds.

the class UniversalUserTokenExtractor method extractPrincipal.

@Override
public UniversalUserToken extractPrincipal(Map<String, Object> map) {
    try {
        UniversalUserToken userToken = configuration.getIdentityProvider().getIdpMapping().map(map);
        userToken.setToken(generateToken());
        return userToken;
    } catch (ScriptException e) {
        throw new RuntimeException(e);
    }
}
Also used : ScriptException(javax.script.ScriptException) UniversalUserToken(gov.ca.cwds.UniversalUserToken)

Example 5 with UniversalUserToken

use of gov.ca.cwds.UniversalUserToken in project perry by ca-cwds.

the class IdpMappingScript method map.

public UniversalUserToken map(Map idpToken) throws ScriptException {
    UniversalUserToken universalUserToken = new UniversalUserToken();
    eval(universalUserToken, idpToken);
    return universalUserToken;
}
Also used : UniversalUserToken(gov.ca.cwds.UniversalUserToken)

Aggregations

UniversalUserToken (gov.ca.cwds.UniversalUserToken)10 Test (org.junit.Test)3 PerryProperties (gov.ca.cwds.PerryProperties)2 HashMap (java.util.HashMap)2 SecurityContext (org.springframework.security.core.context.SecurityContext)2 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)2 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)2 UserAuthorization (gov.ca.cwds.rest.api.domain.auth.UserAuthorization)1 UniversalUserTokenExtractor (gov.ca.cwds.service.oauth.UniversalUserTokenExtractor)1 ScriptException (javax.script.ScriptException)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)1