use of org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade 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);
}
use of org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade in project identity-governance by wso2-extensions.
the class PostAuthnMissingChallengeQuestionsHandlerTest method testBeforeRequestingChallengeQuestionFlow.
@Test(description = "Test the flow of challenge question post authentication handler before requesting challenge " + "questions from the user")
public void testBeforeRequestingChallengeQuestionFlow() throws Exception {
AuthenticationContext context = spy(new AuthenticationContext());
when(context.getTenantDomain()).thenReturn("carbon.super");
IdentityProvider residentIdp = spy(new IdentityProvider());
IdentityProviderProperty[] idpProperties = new IdentityProviderProperty[1];
IdentityProviderProperty idpProp = new IdentityProviderProperty();
idpProp.setName(IdentityRecoveryConstants.ConnectorConfig.FORCE_ADD_PW_RECOVERY_QUESTION);
idpProp.setValue("true");
idpProperties[0] = idpProp;
residentIdp.setIdpProperties(idpProperties);
mockedIdentityProviderManager.when(IdentityProviderManager::getInstance).thenReturn(identityProviderManager);
when(identityProviderManager.getResidentIdP("carbon.super")).thenReturn(residentIdp);
SequenceConfig sequenceConfig = spy(new SequenceConfig());
AuthenticatedUser user = spy(new AuthenticatedUser());
user.setUserName("admin");
when(sequenceConfig.getAuthenticatedUser()).thenReturn(user);
context.setSequenceConfig(sequenceConfig);
mockedMultitenantUtils.when(() -> MultitenantUtils.getTenantDomain("admin")).thenReturn("carbon.super");
mockedUtils.when(() -> Utils.getTenantId("carbon.super")).thenReturn(-1234);
mockedIdentityRecoveryServiceDataHolder.when(IdentityRecoveryServiceDataHolder::getInstance).thenReturn(frameworkServiceDataHolder);
RealmService realmService = mock(RealmService.class);
UserStoreManager userStoreManager = mock(UserStoreManager.class);
UserRealm userRealm = mock(UserRealm.class);
when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
when(frameworkServiceDataHolder.getRealmService()).thenReturn(realmService);
when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
Map<String, String> claimsMap = new HashMap<>();
when(userStoreManager.getUserClaimValues("admin", new String[] { IdentityRecoveryConstants.CHALLENGE_QUESTION_URI }, UserCoreConstants.DEFAULT_PROFILE)).thenReturn(claimsMap);
List<ChallengeQuestion> challengeQuestions = new ArrayList<>();
ChallengeQuestion challengeQuestion = spy(new ChallengeQuestion());
challengeQuestion.setQuestionSetId("dummy_set");
challengeQuestion.setQuestionId("dummy_id");
challengeQuestion.setQuestion("dummy_question");
challengeQuestions.add(challengeQuestion);
when(challengeQuestionManager.getAllChallengeQuestions("carbon.super")).thenReturn(challengeQuestions);
mockedChallengeQuestionManager.when(ChallengeQuestionManager::getInstance).thenReturn(challengeQuestionManager);
doNothing().doThrow(Exception.class).when(httpServletResponse).sendRedirect((String) any());
when(configurationFacade.getAuthenticationEndpointURL()).thenReturn("");
when(ConfigurationFacade.getInstance()).thenReturn(configurationFacade);
PostAuthnHandlerFlowStatus flowStatus = PostAuthnMissingChallengeQuestionsHandler.getInstance().handle(httpServletRequest, httpServletResponse, context);
String expectedResult = PostAuthnHandlerFlowStatus.INCOMPLETE.name();
assertEquals(flowStatus.name(), expectedResult);
}
use of org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade in project carbon-identity-framework by wso2.
the class JITProvisioningPostAuthenticationHandlerTest method setupSuite.
@BeforeClass
protected void setupSuite() throws XMLStreamException, IdentityProviderManagementException {
configurationLoader = new UIBasedConfigurationLoader();
mockStatic(FrameworkUtils.class);
mockStatic(ConfigurationFacade.class);
ConfigurationFacade configurationFacade = mock(ConfigurationFacade.class);
PowerMockito.when(ConfigurationFacade.getInstance()).thenReturn(configurationFacade);
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();
request = mock(HttpServletRequest.class);
response = mock(HttpServletResponse.class);
postJITProvisioningHandler = JITProvisioningPostAuthenticationHandler.getInstance();
sp = getTestServiceProvider("default-sp-1.xml");
}
use of org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade in project identity-governance by wso2-extensions.
the class PostAuthnMissingChallengeQuestionsHandlerTest method testAfterRequestingChallengeQuestionFlow.
@Test(description = "Test the flow of challenge question post authentication handler after requesting challenge " + "questions from the user")
public void testAfterRequestingChallengeQuestionFlow() throws Exception {
AuthenticationContext context = spy(new AuthenticationContext());
when(context.getTenantDomain()).thenReturn("carbon.super");
IdentityProvider residentIdp = spy(new IdentityProvider());
IdentityProviderProperty[] idpProperties = new IdentityProviderProperty[1];
IdentityProviderProperty idpProp = new IdentityProviderProperty();
idpProp.setName(IdentityRecoveryConstants.ConnectorConfig.FORCE_ADD_PW_RECOVERY_QUESTION);
idpProp.setValue("true");
idpProperties[0] = idpProp;
residentIdp.setIdpProperties(idpProperties);
mockedIdentityProviderManager.when(IdentityProviderManager::getInstance).thenReturn(identityProviderManager);
when(identityProviderManager.getResidentIdP("carbon.super")).thenReturn(residentIdp);
SequenceConfig sequenceConfig = spy(new SequenceConfig());
AuthenticatedUser user = spy(new AuthenticatedUser());
user.setUserName("admin");
when(sequenceConfig.getAuthenticatedUser()).thenReturn(user);
context.setSequenceConfig(sequenceConfig);
mockedMultitenantUtils.when(() -> MultitenantUtils.getTenantDomain("admin")).thenReturn("carbon.super");
mockedUtils.when(() -> Utils.getTenantId("carbon.super")).thenReturn(-1234);
mockedIdentityRecoveryServiceDataHolder.when(IdentityRecoveryServiceDataHolder::getInstance).thenReturn(frameworkServiceDataHolder);
RealmService realmService = mock(RealmService.class);
UserStoreManager userStoreManager = mock(UserStoreManager.class);
UserRealm userRealm = mock(UserRealm.class);
when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
when(frameworkServiceDataHolder.getRealmService()).thenReturn(realmService);
when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
Map<String, String> claimsMap = new HashMap<>();
when(userStoreManager.getUserClaimValues("admin", new String[] { IdentityRecoveryConstants.CHALLENGE_QUESTION_URI }, UserCoreConstants.DEFAULT_PROFILE)).thenReturn(claimsMap);
List<ChallengeQuestion> challengeQuestions = new ArrayList<>();
ChallengeQuestion challengeQuestion = spy(new ChallengeQuestion());
challengeQuestion.setQuestionSetId("dummy_set");
challengeQuestion.setQuestionId("dummy_id");
challengeQuestion.setQuestion("dummy_question");
challengeQuestions.add(challengeQuestion);
when(challengeQuestionManager.getAllChallengeQuestions("carbon.super")).thenReturn(challengeQuestions);
mockedChallengeQuestionManager.when(ChallengeQuestionManager::getInstance).thenReturn(challengeQuestionManager);
doNothing().doThrow(Exception.class).when(httpServletResponse).sendRedirect((String) any());
when(configurationFacade.getAuthenticationEndpointURL()).thenReturn("");
mockedConfigurationFacade.when(ConfigurationFacade::getInstance).thenReturn(configurationFacade);
when(context.getParameter(CHALLENGE_QUESTIONS_REQUESTED)).thenReturn(true);
Vector<String> set = new Vector<>();
set.add("Q-dummy_question");
set.add("A-dummy_answer");
Enumeration<String> paramNames = new Vector(set).elements();
when(httpServletRequest.getParameterNames()).thenReturn(paramNames);
when(httpServletRequest.getParameter(anyString())).thenReturn("dummy_question");
PostAuthnHandlerFlowStatus flowStatus = PostAuthnMissingChallengeQuestionsHandler.getInstance().handle(httpServletRequest, httpServletResponse, context);
String expectedResult = PostAuthnHandlerFlowStatus.SUCCESS_COMPLETED.name();
assertEquals(flowStatus.name(), expectedResult);
}
Aggregations