use of org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder in project identity-governance by wso2-extensions.
the class PostAuthnMissingChallengeQuestionsHandlerTest method testAlreadyChallengeQuestionProvidedUserFlow.
@Test(description = "Test the flow for the user who has already given the challenge questions")
public void testAlreadyChallengeQuestionProvidedUserFlow() 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<>();
claimsMap.put(IdentityRecoveryConstants.CHALLENGE_QUESTION_URI, "dummy_data");
when(userStoreManager.getUserClaimValues("admin", new String[] { IdentityRecoveryConstants.CHALLENGE_QUESTION_URI }, UserCoreConstants.DEFAULT_PROFILE)).thenReturn(claimsMap);
PostAuthnHandlerFlowStatus flowStatus = PostAuthnMissingChallengeQuestionsHandler.getInstance().handle(httpServletRequest, httpServletResponse, context);
String expectedResult = PostAuthnHandlerFlowStatus.SUCCESS_COMPLETED.name();
assertEquals(flowStatus.name(), expectedResult);
}
use of org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder 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.internal.FrameworkServiceDataHolder in project carbon-identity-framework by wso2.
the class GraphBasedSequenceHandler method executeFunction.
private void executeFunction(String outcomeName, DynamicDecisionNode dynamicDecisionNode, AuthenticationContext context) {
SerializableJsFunction fn = dynamicDecisionNode.getFunctionMap().get(outcomeName);
FrameworkServiceDataHolder dataHolder = FrameworkServiceDataHolder.getInstance();
JsGraphBuilderFactory jsGraphBuilderFactory = dataHolder.getJsGraphBuilderFactory();
JsGraphBuilder graphBuilder = jsGraphBuilderFactory.createBuilder(context, context.getSequenceConfig().getAuthenticationGraph().getStepMap(), dynamicDecisionNode);
JsGraphBuilder.JsBasedEvaluator jsBasedEvaluator = graphBuilder.new JsBasedEvaluator(fn);
jsBasedEvaluator.evaluate(context, (jsConsumer) -> jsConsumer.call(null, new JsAuthenticationContext(context)));
if (dynamicDecisionNode.getDefaultEdge() == null) {
dynamicDecisionNode.setDefaultEdge(new EndStep());
}
}
use of org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder in project carbon-identity-framework by wso2.
the class GraphBasedSequenceHandler method evaluateHandler.
private Object evaluateHandler(String outcomeName, ShowPromptNode dynamicDecisionNode, AuthenticationContext context, Object stepId) {
SerializableJsFunction fn = dynamicDecisionNode.getHandlerMap().get(outcomeName);
FrameworkServiceDataHolder dataHolder = FrameworkServiceDataHolder.getInstance();
JsGraphBuilderFactory jsGraphBuilderFactory = dataHolder.getJsGraphBuilderFactory();
JsGraphBuilder graphBuilder = jsGraphBuilderFactory.createBuilder(context, context.getSequenceConfig().getAuthenticationGraph().getStepMap(), dynamicDecisionNode);
JsGraphBuilder.JsBasedEvaluator jsBasedEvaluator = graphBuilder.new JsBasedEvaluator(fn);
return jsBasedEvaluator.evaluate(context, (jsFunction) -> jsFunction.call(null, stepId, new JsAuthenticationContext(context)));
}
use of org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder in project carbon-identity-framework by wso2.
the class JITProvisioningPostAuthenticationHandlerTest method testHandleWithAuthenticatedUserWithFederatedIdp.
@Test(description = "This test case tests the Post JIT provisioning handling flow with an authenticated user")
public void testHandleWithAuthenticatedUserWithFederatedIdp() throws FrameworkException, FederatedAssociationManagerException, AccountLockServiceException, UserStoreException {
AuthenticationContext context = processAndGetAuthenticationContext(sp, true, true);
FederatedAssociationManager federatedAssociationManager = mock(FederatedAssociationManagerImpl.class);
when(FrameworkUtils.getFederatedAssociationManager()).thenReturn(federatedAssociationManager);
doReturn("test").when(federatedAssociationManager).getUserForFederatedAssociation(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
when(FrameworkUtils.getStepBasedSequenceHandler()).thenReturn(Mockito.mock(StepBasedSequenceHandler.class));
mockStatic(FrameworkServiceDataHolder.class);
PowerMockito.when(FrameworkServiceDataHolder.getInstance()).thenReturn(frameworkServiceDataHolder);
mockStatic(AccountLockService.class);
when(frameworkServiceDataHolder.getAccountLockService()).thenReturn(accountLockService);
when(accountLockService.isAccountLocked(anyString(), anyString())).thenReturn(false);
RealmService mockRealmService = mock(RealmService.class);
PowerMockito.when(FrameworkServiceDataHolder.getInstance().getRealmService()).thenReturn(mockRealmService);
UserRealm mockUserRealm = mock(UserRealm.class);
UserStoreManager mockUserStoreManager = mock(UserStoreManager.class);
Map<String, String> mockClaimValues = mock(HashMap.class);
mockStatic(IdentityTenantUtil.class);
when(IdentityTenantUtil.getTenantId(anyString())).thenReturn(1);
when(mockRealmService.getTenantUserRealm(anyInt())).thenReturn(mockUserRealm);
when(mockUserRealm.getUserStoreManager()).thenReturn(mockUserStoreManager);
when(mockUserStoreManager.getUserClaimValues(anyString(), eq(new String[] { AccountConstants.ACCOUNT_DISABLED_CLAIM }), eq(UserCoreConstants.DEFAULT_PROFILE))).thenReturn(mockClaimValues);
when(mockClaimValues.get(AccountConstants.ACCOUNT_DISABLED_CLAIM)).thenReturn("false");
PostAuthnHandlerFlowStatus postAuthnHandlerFlowStatus = postJITProvisioningHandler.handle(request, response, context);
Assert.assertEquals(postAuthnHandlerFlowStatus, PostAuthnHandlerFlowStatus.SUCCESS_COMPLETED, "Post JIT provisioning handler executed while having a authenticated user without federated " + "authenticator");
}
Aggregations