Search in sources :

Example 21 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion in project product-is by wso2.

the class ServerChallengeTestCase method updateChallengeQuestionPUTTest.

/**
 * This test method validate update challenge question api response.
 *
 * @throws JSONException thrown to indicate a problem with the JSON.
 */
@Test(dependsOnMethods = { "addsNewChallengeQuestionSetTest" })
public void updateChallengeQuestionPUTTest() throws JSONException {
    String locale = "en_UK";
    String questionID = "question6";
    String challengeQuestion = "What is the name of your first pet?";
    ServerChallengeModel.Questions question = new ServerChallengeModel.Questions(locale, challengeQuestion, questionID);
    List<ServerChallengeModel.Questions> questions = new ArrayList<>();
    questions.add(question);
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    String request = gson.toJson(questions);
    given().auth().preemptive().basic(USER_NAME, PASSWORD).contentType(ContentType.JSON).header(HttpHeaders.ACCEPT, ContentType.JSON).body(request).log().ifValidationFails().when().put(RESOURCE_PATH + "/{challenge-set-id}", QUESTION_SET_ID).then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_OK).log().ifValidationFails();
    getsChallengeQuestionTest(QUESTION_SET_ID, challengeQuestion, questionID);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) ServerChallengeModel(org.wso2.identity.integration.test.rest.api.server.challenge.v1.model.ServerChallengeModel) Gson(com.google.gson.Gson) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 22 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion in project identity-api-server by wso2.

the class ServerChallengeService method getChallengeSetDTO.

private ChallengeSetDTO getChallengeSetDTO(String questionSetId, List<ChallengeQuestion> questions) {
    ChallengeSetDTO challenge = new ChallengeSetDTO();
    challenge.setQuestionSetId(questionSetId);
    List<ChallengeQuestionDTO> questionDTOs = questions.stream().map(new ChallengeQuestionToExternal()).collect(Collectors.toList());
    challenge.setQuestions(questionDTOs);
    return challenge;
}
Also used : ChallengeSetDTO(org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeSetDTO) ChallengeQuestionToExternal(org.wso2.carbon.identity.rest.api.server.challenge.v1.core.functions.ChallengeQuestionToExternal) ChallengeQuestionDTO(org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeQuestionDTO)

Example 23 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion in project identity-api-server by wso2.

the class ServerChallengeService method buildChallengeQuestionSets.

private ChallengeQuestion[] buildChallengeQuestionSets(List<ChallengeSetDTO> challengeSets) {
    List<ChallengeQuestion> questions = new ArrayList<>();
    for (ChallengeSetDTO challengeSet : challengeSets) {
        String setId = challengeSet.getQuestionSetId();
        questions = buildChallengeQuestions(challengeSet.getQuestions(), setId);
    }
    return questions.toArray(new ChallengeQuestion[0]);
}
Also used : ChallengeSetDTO(org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeSetDTO) ArrayList(java.util.ArrayList) ChallengeQuestion(org.wso2.carbon.identity.recovery.model.ChallengeQuestion)

Example 24 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion in project identity-api-server by wso2.

the class ChallengeQuestionToExternal method apply.

@Override
public ChallengeQuestionDTO apply(ChallengeQuestion challengeQuestion) {
    ChallengeQuestionDTO question = new ChallengeQuestionDTO();
    question.setLocale(challengeQuestion.getLocale());
    question.setQuestion(challengeQuestion.getQuestion());
    question.setQuestionId(challengeQuestion.getQuestionId());
    return question;
}
Also used : ChallengeQuestionDTO(org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeQuestionDTO)

Example 25 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion 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);
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) UserRealm(org.wso2.carbon.user.core.UserRealm) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) RealmService(org.wso2.carbon.user.core.service.RealmService) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) Vector(java.util.Vector) PostAuthnHandlerFlowStatus(org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus) ChallengeQuestion(org.wso2.carbon.identity.recovery.model.ChallengeQuestion) Test(org.testng.annotations.Test)

Aggregations

ChallengeQuestion (org.wso2.carbon.identity.recovery.model.ChallengeQuestion)26 ArrayList (java.util.ArrayList)14 Test (org.testng.annotations.Test)8 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)8 UserChallengeAnswer (org.wso2.carbon.identity.recovery.model.UserChallengeAnswer)7 ChallengeQuestion (org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion)6 UserStoreException (org.wso2.carbon.user.api.UserStoreException)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 IdentityRecoveryClientException (org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)5 IdentityException (org.wso2.carbon.identity.base.IdentityException)3 ChallengeQuestionManager (org.wso2.carbon.identity.recovery.ChallengeQuestionManager)3 ChallengeQuestionResponse (org.wso2.carbon.identity.recovery.bean.ChallengeQuestionResponse)3 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)3 UserRecoveryDataStore (org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore)3 ChallengeQuestionDTO (org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeQuestionDTO)3 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 Map (java.util.Map)2