Search in sources :

Example 1 with ClaimHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler in project carbon-identity-framework by wso2.

the class FrameworkUtils method getClaimHandler.

/**
 * @return
 */
public static ClaimHandler getClaimHandler() {
    ClaimHandler claimHandler = null;
    Object obj = ConfigurationFacade.getInstance().getExtensions().get(FrameworkConstants.Config.QNAME_EXT_CLAIM_HANDLER);
    if (obj instanceof ClaimHandler) {
        claimHandler = (ClaimHandler) obj;
    } else {
        claimHandler = DefaultClaimHandler.getInstance();
    }
    return claimHandler;
}
Also used : JSONObject(org.json.JSONObject) ClaimHandler(org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler) DefaultClaimHandler(org.wso2.carbon.identity.application.authentication.framework.handler.claims.impl.DefaultClaimHandler)

Example 2 with ClaimHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler in project carbon-identity-framework by wso2.

the class PostAuthAssociationHandlerTest method setupSuite.

@BeforeMethod
protected void setupSuite() throws Exception {
    configurationLoader = new UIBasedConfigurationLoader();
    mockStatic(FrameworkUtils.class);
    mockStatic(ConfigurationFacade.class);
    mockStatic(ClaimMetadataHandler.class);
    mockStatic(IdentityTenantUtil.class);
    ConfigurationFacade configurationFacade = mock(ConfigurationFacade.class);
    PowerMockito.when(ConfigurationFacade.getInstance()).thenReturn(configurationFacade);
    ClaimMetadataHandler claimMetadataHandler = mock(ClaimMetadataHandler.class);
    PowerMockito.when(ClaimMetadataHandler.getInstance()).thenReturn(claimMetadataHandler);
    Map<String, String> emptyMap = new HashMap<>();
    PowerMockito.when(ClaimMetadataHandler.getInstance().getMappingsMapFromOtherDialectToCarbon(Mockito.anyString(), Mockito.anySet(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(emptyMap);
    IdentityProvider identityProvider = getTestIdentityProvider("default-tp-1.xml");
    ExternalIdPConfig externalIdPConfig = new ExternalIdPConfig(identityProvider);
    Mockito.doReturn(externalIdPConfig).when(configurationFacade).getIdPConfigByName(Mockito.anyString(), Mockito.anyString());
    when(FrameworkUtils.isStepBasedSequenceHandlerExecuted(Mockito.any(AuthenticationContext.class))).thenCallRealMethod();
    when(FrameworkUtils.prependUserStoreDomainToName(Mockito.anyString())).thenCallRealMethod();
    when(FrameworkUtils.buildClaimMappings(Mockito.anyMap())).thenCallRealMethod();
    when(FrameworkUtils.getStandardDialect(Mockito.anyString(), Mockito.any(ApplicationConfig.class))).thenCallRealMethod();
    request = mock(HttpServletRequest.class);
    response = mock(HttpServletResponse.class);
    postAuthAssociationHandler = PostAuthAssociationHandler.getInstance();
    sp = getTestServiceProvider("default-sp-1.xml");
    PowerMockito.when(FrameworkUtils.getMultiAttributeSeparator()).thenReturn(",");
    ClaimHandler claimHandler = PowerMockito.mock(ClaimHandler.class);
    Map<String, String> claims = new HashMap<>();
    claims.put("claim1", "value1");
    claims.put(FrameworkConstants.LOCAL_ROLE_CLAIM_URI, String.format("%s,%s", ORI_ROLE_1, ORI_ROLE_2));
    PowerMockito.doReturn(claims).when(claimHandler).handleClaimMappings(any(StepConfig.class), any(AuthenticationContext.class), any(Map.class), anyBoolean());
    PowerMockito.when(FrameworkUtils.getClaimHandler()).thenReturn(claimHandler);
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) ConfigurationFacade(org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade) ClaimMetadataHandler(org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataHandler) HashMap(java.util.HashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) Matchers.anyString(org.mockito.Matchers.anyString) ClaimHandler(org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) UIBasedConfigurationLoader(org.wso2.carbon.identity.application.authentication.framework.config.loader.UIBasedConfigurationLoader) ApplicationConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig) ExternalIdPConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig) Map(java.util.Map) HashMap(java.util.HashMap) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with ClaimHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler in project carbon-identity-framework by wso2.

the class DefaultRequestPathBasedSequenceHandlerTest method testHandleClaimMappingsErrorFlow.

@Test
public void testHandleClaimMappingsErrorFlow() throws Exception {
    ClaimHandler claimHandler = mock(ClaimHandler.class);
    doThrow(new FrameworkException("ERROR")).when(claimHandler).handleClaimMappings(any(StepConfig.class), any(AuthenticationContext.class), any(Map.class), anyBoolean());
    mockStatic(FrameworkUtils.class);
    when(FrameworkUtils.getClaimHandler()).thenReturn(claimHandler);
    Map<String, String> claims = requestPathBasedSequenceHandler.handleClaimMappings(new AuthenticationContext());
    assertNotNull(claims);
    assertEquals(claims.size(), 0);
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) FrameworkException(org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) ClaimHandler(org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with ClaimHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler in project carbon-identity-framework by wso2.

the class DefaultRequestPathBasedSequenceHandlerTest method testHandleClaimMappingsFailed.

@Test
public void testHandleClaimMappingsFailed() throws Exception {
    ClaimHandler claimHandler = mock(ClaimHandler.class);
    doThrow(new FrameworkException("Claim Handling failed")).when(claimHandler).handleClaimMappings(any(StepConfig.class), any(AuthenticationContext.class), any(Map.class), anyBoolean());
    mockStatic(FrameworkUtils.class);
    when(FrameworkUtils.getClaimHandler()).thenReturn(claimHandler);
    Map<String, String> claims = requestPathBasedSequenceHandler.handleClaimMappings(new AuthenticationContext());
    assertNotNull(claims);
    assertEquals(claims.size(), 0);
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) FrameworkException(org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) ClaimHandler(org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with ClaimHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler in project carbon-identity-framework by wso2.

the class Util method mockClaimHandler.

public static ClaimHandler mockClaimHandler() throws FrameworkException {
    ClaimHandler claimHandler = mock(ClaimHandler.class);
    Map<String, String> claims = new HashMap<>();
    claims.put("claim1", "value1");
    doReturn(claims).when(claimHandler).handleClaimMappings(any(StepConfig.class), any(AuthenticationContext.class), any(Map.class), anyBoolean());
    return claimHandler;
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) HashMap(java.util.HashMap) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) ClaimHandler(org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ClaimHandler (org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 Test (org.testng.annotations.Test)7 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)6 Matchers.anyString (org.mockito.Matchers.anyString)3 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)3 BeforeTest (org.testng.annotations.BeforeTest)2 DefaultClaimHandler (org.wso2.carbon.identity.application.authentication.framework.handler.claims.impl.DefaultClaimHandler)2 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 JSONObject (org.json.JSONObject)1 Matchers.anyMap (org.mockito.Matchers.anyMap)1 Mockito.anyObject (org.mockito.Mockito.anyObject)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 ConfigurationFacade (org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade)1 UIBasedConfigurationLoader (org.wso2.carbon.identity.application.authentication.framework.config.loader.UIBasedConfigurationLoader)1