use of org.wso2.carbon.identity.recovery.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);
}
use of org.wso2.carbon.identity.recovery.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;
}
use of org.wso2.carbon.identity.recovery.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]);
}
use of org.wso2.carbon.identity.recovery.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;
}
use of org.wso2.carbon.identity.recovery.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);
}
Aggregations