Search in sources :

Example 1 with UserInfoClaimRetriever

use of org.wso2.carbon.identity.oauth.user.UserInfoClaimRetriever in project identity-inbound-auth-oauth by wso2-extensions.

the class UserInfoEndpointConfigTest method testGetUserInfoClaimRetriever.

@Test(dataProvider = "getUserUserInfoClaimRetriever")
public void testGetUserInfoClaimRetriever(String validatorClass, Class validatorClassType, boolean isClassExisting) throws Exception {
    mockStatic(EndpointUtil.class);
    when(EndpointUtil.getUserInfoClaimRetriever()).thenReturn(validatorClass);
    UserInfoClaimRetriever userInfoClaimRetriever = UserInfoEndpointConfig.getInstance().getUserInfoClaimRetriever();
    if (isClassExisting) {
        assertNotNull(userInfoClaimRetriever, "UserInfoResponseBuilder should not be null for class " + validatorClass);
        assertEquals(validatorClassType, userInfoClaimRetriever.getClass(), "Expected type of " + "UserInfoClaimRetriever was not found");
    } else {
        assertNull(userInfoClaimRetriever, "Non-existing or invalid class passed. Hence validator should be " + "null");
    }
}
Also used : UserInfoClaimRetriever(org.wso2.carbon.identity.oauth.user.UserInfoClaimRetriever) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with UserInfoClaimRetriever

use of org.wso2.carbon.identity.oauth.user.UserInfoClaimRetriever in project identity-inbound-auth-oauth by wso2-extensions.

the class UserInfoResponseBaseTest method prepareUserInfoEndpointConfig.

protected void prepareUserInfoEndpointConfig() {
    UserInfoClaimRetriever claimsRetriever = mock(UserInfoClaimRetriever.class);
    mockStatic(UserInfoEndpointConfig.class);
    when(UserInfoEndpointConfig.getInstance()).thenReturn(userInfoEndpointConfig);
    when(claimsRetriever.getClaimsMap(any(Map.class))).thenReturn(new HashMap());
    when(userInfoEndpointConfig.getUserInfoClaimRetriever()).thenReturn(claimsRetriever);
}
Also used : HashMap(java.util.HashMap) UserInfoClaimRetriever(org.wso2.carbon.identity.oauth.user.UserInfoClaimRetriever) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap)

Example 3 with UserInfoClaimRetriever

use of org.wso2.carbon.identity.oauth.user.UserInfoClaimRetriever in project identity-inbound-auth-oauth by wso2-extensions.

the class ClaimUtil method getUserClaimsUsingTokenResponse.

public static Map<String, Object> getUserClaimsUsingTokenResponse(OAuth2TokenValidationResponseDTO tokenResponse) throws UserInfoEndpointException {
    Map<ClaimMapping, String> userAttributes = getUserAttributesFromCache(tokenResponse);
    Map<String, Object> userClaimsInOIDCDialect;
    if (isEmpty(userAttributes)) {
        if (log.isDebugEnabled()) {
            log.debug("User attributes not found in cache against the token. Retrieved claims from user store.");
        }
        userClaimsInOIDCDialect = getClaimsFromUserStore(tokenResponse);
    } else {
        UserInfoClaimRetriever retriever = UserInfoEndpointConfig.getInstance().getUserInfoClaimRetriever();
        userClaimsInOIDCDialect = retriever.getClaimsMap(userAttributes);
    }
    if (isEmpty(userClaimsInOIDCDialect)) {
        userClaimsInOIDCDialect = new HashMap<>();
    }
    return userClaimsInOIDCDialect;
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) UserInfoClaimRetriever(org.wso2.carbon.identity.oauth.user.UserInfoClaimRetriever)

Aggregations

UserInfoClaimRetriever (org.wso2.carbon.identity.oauth.user.UserInfoClaimRetriever)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matchers.anyMap (org.mockito.Matchers.anyMap)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)1