use of org.wso2.carbon.identity.recovery.endpoint.dto.InitiateAllQuestionResponseDTO in project identity-governance by wso2-extensions.
the class RecoveryUtil method getInitiateQuestionResponseDTO.
public static InitiateAllQuestionResponseDTO getInitiateQuestionResponseDTO(ChallengeQuestionsResponse challengeQuestionsResponse) {
InitiateAllQuestionResponseDTO initiateAllQuestionResponseDTO = new InitiateAllQuestionResponseDTO();
List<QuestionDTO> questionDTOs = new ArrayList<>();
for (ChallengeQuestion challengeQuestion : challengeQuestionsResponse.getQuestion()) {
QuestionDTO questionDTO = new QuestionDTO();
questionDTO.setQuestion(challengeQuestion.getQuestion());
questionDTO.setQuestionSetId(challengeQuestion.getQuestionSetId());
questionDTOs.add(questionDTO);
}
initiateAllQuestionResponseDTO.setQuestions(questionDTOs);
initiateAllQuestionResponseDTO.setKey(challengeQuestionsResponse.getCode());
LinkDTO linkDTO = new LinkDTO();
linkDTO.setRel("validate-answer");
linkDTO.setUri("/api/identity/recovery/v0.9");
initiateAllQuestionResponseDTO.setLink(linkDTO);
return initiateAllQuestionResponseDTO;
}
use of org.wso2.carbon.identity.recovery.endpoint.dto.InitiateAllQuestionResponseDTO in project identity-governance by wso2-extensions.
the class SecurityQuestionsApiServiceImpl method securityQuestionsGet.
@Override
public Response securityQuestionsGet(String username, String realm, String tenantDomain) {
if (IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT) != null) {
tenantDomain = (String) IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT);
}
User user = new User();
user.setUserName(username);
if (StringUtils.isBlank(tenantDomain)) {
user.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
} else {
user.setTenantDomain(tenantDomain);
}
int tenantId = IdentityTenantUtil.getTenantId(user.getTenantDomain());
if (StringUtils.isBlank(realm)) {
String[] userList = RecoveryUtil.getUserList(tenantId, username);
if (ArrayUtils.isEmpty(userList)) {
String msg = "Unable to find an user with username: " + username + " in the system.";
LOG.error(msg);
} else if (userList.length == 1) {
user.setUserStoreDomain(IdentityUtil.extractDomainFromName(userList[0]));
} else {
String msg = "There are multiple users with username: " + username + " in the system, " + "please send the correct user-store domain along with the username.";
LOG.error(msg);
RecoveryUtil.handleBadRequest(msg, Constants.ERROR_CODE_MULTIPLE_USERS_MATCHING);
}
}
InitiateAllQuestionResponseDTO initiateAllQuestionResponseDTO = null;
SecurityQuestionPasswordRecoveryManager securityQuestionBasedPwdRecoveryManager = RecoveryUtil.getSecurityQuestionBasedPwdRecoveryManager();
try {
ChallengeQuestionsResponse challengeQuestionResponse = securityQuestionBasedPwdRecoveryManager.initiateUserChallengeQuestionAtOnce(user);
initiateAllQuestionResponseDTO = RecoveryUtil.getInitiateQuestionResponseDTO(challengeQuestionResponse);
} catch (IdentityRecoveryClientException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Client Error while initiating password recovery flow at once using security questions ", e);
}
if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_CHALLENGE_QUESTION_NOT_FOUND.getCode().equals(e.getErrorCode())) {
return Response.noContent().build();
}
RecoveryUtil.handleBadRequest(e.getMessage(), e.getErrorCode());
} catch (IdentityRecoveryException e) {
RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
} catch (Throwable throwable) {
RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
}
return Response.ok(initiateAllQuestionResponseDTO).build();
}
Aggregations