Search in sources :

Example 6 with UniversalUserToken

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

the class TokenServiceTest method issueAccessCode.

private String issueAccessCode(String perryToken) {
    OAuth2AccessToken accessToken = new DefaultOAuth2AccessToken(ACCESS_TOKEN);
    UniversalUserToken universalUserToken = new UniversalUserToken();
    universalUserToken.setUserId(USER_ID);
    universalUserToken.setToken(perryToken);
    return tokenService.issueAccessCode(universalUserToken, accessToken);
}
Also used : UniversalUserToken(gov.ca.cwds.UniversalUserToken) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)

Example 7 with UniversalUserToken

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

the class BaseScriptTest method test.

public void test(String script, String json, String userAuthorization) throws Exception {
    IdentityMappingScript identityMappingScript = loadScript(script);
    UniversalUserToken user = new UniversalUserToken();
    UserAuthorization authorization = MAPPER.readValue(fixture(userAuthorization), UserAuthorization.class);
    user.setAuthorization(authorization);
    String result = identityMappingScript.map(user);
    System.out.println(result);
    String expectedResult = readResource(json);
    Assert.assertEquals(expectedResult, result);
}
Also used : UniversalUserToken(gov.ca.cwds.UniversalUserToken) UserAuthorization(gov.ca.cwds.rest.api.domain.auth.UserAuthorization)

Example 8 with UniversalUserToken

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

the class IdentityMappingServiceTest method test.

@Test
public void test() {
    IdentityMappingService identityMappingService = new IdentityMappingService();
    PerryProperties configuration = new PerryProperties();
    identityMappingService.setConfiguration(configuration);
    UniversalUserToken universalUserToken = new UniversalUserToken();
    universalUserToken.setUserId("user");
    String user = identityMappingService.map(universalUserToken, "test");
    assert user.equals("user");
}
Also used : UniversalUserToken(gov.ca.cwds.UniversalUserToken) PerryProperties(gov.ca.cwds.PerryProperties) Test(org.junit.Test)

Example 9 with UniversalUserToken

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

the class IdpMappingScriptTest method testGroovyMapping.

@Test
public void testGroovyMapping() throws Exception {
    String path = Paths.get(getClass().getResource("/idp.groovy").toURI()).toString();
    IdpMappingScript idpMappingScript = new IdpMappingScript(path);
    Map<String, Object> userInfo = new HashMap<>();
    userInfo.put("safid.racfid", "racfid");
    userInfo.put("ok", "true");
    UniversalUserToken userToken = idpMappingScript.map(userInfo);
    assertEquals("racfid", userToken.getUserId());
}
Also used : UniversalUserToken(gov.ca.cwds.UniversalUserToken) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 10 with UniversalUserToken

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

the class UniversalUserTokenExtractorTest method test.

@Test
public void test() throws Exception {
    PerryProperties perryProperties = new PerryProperties();
    PerryProperties.IdentityProviderConfiguration identityProviderConfiguration = new PerryProperties.IdentityProviderConfiguration();
    String path = Paths.get(getClass().getResource("/idp.groovy").toURI()).toString();
    identityProviderConfiguration.setIdpMapping(path);
    perryProperties.setIdentityProvider(identityProviderConfiguration);
    UniversalUserTokenExtractor userTokenExtractor = new UniversalUserTokenExtractor();
    userTokenExtractor.setConfiguration(perryProperties);
    Map<String, Object> userInfo = new HashMap<>();
    userInfo.put("safid.racfid", "racfid");
    userInfo.put("ok", "true");
    UniversalUserToken token = userTokenExtractor.extractPrincipal(userInfo);
    assertEquals("racfid", token.getUserId());
}
Also used : UniversalUserToken(gov.ca.cwds.UniversalUserToken) HashMap(java.util.HashMap) PerryProperties(gov.ca.cwds.PerryProperties) UniversalUserTokenExtractor(gov.ca.cwds.service.oauth.UniversalUserTokenExtractor) Test(org.junit.Test)

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