use of org.wso2.carbon.identity.mgt.dto.UserChallengesDTO in project product-is by wso2.
the class UserIdentityManagementServiceTestCase method testGetChallengeQuestionsOfUser.
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
@Test(groups = "wso2.is", description = "Getting challenge questions of a user")
public void testGetChallengeQuestionsOfUser() throws Exception {
UserChallengesDTO userChallengesDTO = new UserChallengesDTO();
userChallengesDTO.setId("http://wso2.org/claims/challengeQuestion1");
userChallengesDTO.setQuestion("Favorite food ?");
userChallengesDTO.setOrder(0);
userChallengesDTO.setAnswer("answer1");
UserChallengesDTO[] userChallengesDTOs = new UserChallengesDTO[] { userChallengesDTO };
userIdentityManagementAdminServiceClient.setChallengeQuestionsOfUser(TEST_USER_USERNAME, userChallengesDTOs);
UserChallengesDTO[] userChallengesDTOsReceived = userIdentityManagementAdminServiceClient.getChallengeQuestionsOfUser(TEST_USER_USERNAME);
Assert.assertEquals(1, userChallengesDTOsReceived.length);
Assert.assertEquals(userChallengesDTOsReceived[0].getQuestion(), "Favorite food ?");
Assert.assertNotNull(userChallengesDTOsReceived[0].getAnswer(), "Answer of the challenge question is null");
}
use of org.wso2.carbon.identity.mgt.dto.UserChallengesDTO in project carbon-identity-framework by wso2.
the class ChallengeQuestionProcessor method getPrimaryChallengeQuestionsOfUser.
/**
* @param userName
* @param tenantId
* @return
*/
public UserChallengesDTO[] getPrimaryChallengeQuestionsOfUser(String userName, int tenantId) {
List<UserChallengesDTO> challengesDTOs = new ArrayList<>();
try {
if (log.isDebugEnabled()) {
log.debug("Challenge Question from the user profile.");
}
String claimValue;
claimValue = Utils.getClaimFromUserStoreManager(userName, tenantId, "http://wso2.org/claims/primaryChallengeQuestion");
String[] challenges = claimValue.split(IdentityMgtConfig.getInstance().getChallengeQuestionSeparator());
for (String challenge : challenges) {
UserChallengesDTO dto = new UserChallengesDTO();
String question = challenge.substring(0, challenge.indexOf("="));
dto.setQuestion(question);
dto.setPrimary(true);
challengesDTOs.add(dto);
}
} catch (Exception e) {
String msg = "No associated challenge question found for the user";
log.debug(msg, e);
}
if (!challengesDTOs.isEmpty()) {
return challengesDTOs.toArray(new UserChallengesDTO[challengesDTOs.size()]);
} else {
return new UserChallengesDTO[0];
}
}
use of org.wso2.carbon.identity.mgt.dto.UserChallengesDTO in project carbon-identity-framework by wso2.
the class ChallengeQuestionProcessor method verifyUserChallengeAnswers.
/**
* Verifies challenge question answers.
*
* @param userName username of the user
* @param tenantId tenant user belongs to
* @param userChallengesDTOs an array of UserChallengesDTO instances which holds the answer and the question id
* @return true if answers are correct and false otherwise
*/
public boolean verifyUserChallengeAnswers(String userName, int tenantId, UserChallengesDTO[] userChallengesDTOs) {
boolean verification = true;
try {
if (log.isDebugEnabled()) {
log.debug("verifying challenge question answers");
}
UserChallengesDTO[] storedUserChallengeDTOs = getChallengeQuestionsOfUser(userName, tenantId, true);
int count = 0;
for (UserChallengesDTO storedUserChallengesDTO : storedUserChallengeDTOs) {
for (UserChallengesDTO receivedUserChallengesDTO : userChallengesDTOs) {
if (storedUserChallengesDTO.getId().equals(receivedUserChallengesDTO.getId())) {
count++;
String hashedAnswer = Utils.doHash(receivedUserChallengesDTO.getAnswer().trim().toLowerCase());
if (!hashedAnswer.equals(storedUserChallengesDTO.getAnswer())) {
verification = false;
break;
}
}
}
}
if (verification) {
verification = (storedUserChallengeDTOs.length == count);
}
} catch (Exception e) {
log.error("Error while verifying challenge question answers", e);
verification = false;
}
return verification;
}
use of org.wso2.carbon.identity.mgt.dto.UserChallengesDTO in project carbon-identity-framework by wso2.
the class ChallengeQuestionProcessor method getUserChallengeQuestion.
public UserChallengesDTO getUserChallengeQuestion(String userName, int tenantId, boolean adminService) throws IdentityMgtServiceException {
UserChallengesDTO dto = null;
List<UserChallengesDTO> challengesDTOs = new ArrayList<UserChallengesDTO>();
try {
if (log.isDebugEnabled()) {
log.debug("Retrieving Challenge question from the user profile.");
}
List<String> challengesUris = getChallengeQuestionUris(userName, tenantId);
for (int i = 0; i < challengesUris.size(); i++) {
String challengesUri = challengesUris.get(i).trim();
String challengeValue = Utils.getClaimFromUserStoreManager(userName, tenantId, challengesUri);
String[] challengeValues = challengeValue.split(IdentityMgtConfig.getInstance().getChallengeQuestionSeparator());
if (challengeValues != null && challengeValues.length == 2) {
dto = new UserChallengesDTO();
dto.setId(challengesUri);
dto.setQuestion(challengeValues[0].trim());
if (adminService) {
dto.setAnswer(challengeValues[1].trim());
}
dto.setOrder(i);
dto.setPrimary(false);
challengesDTOs.add(dto);
}
}
} catch (Exception e) {
String msg = "No associated challenge question found for the user";
if (log.isDebugEnabled()) {
log.debug(msg, e);
}
}
return dto;
}
use of org.wso2.carbon.identity.mgt.dto.UserChallengesDTO in project carbon-identity-framework by wso2.
the class IdentityManagementClient method verifyChallengeQuestion.
public VerificationBean verifyChallengeQuestion(String userId, String userKey, String question, String answer) throws AxisFault {
try {
UserChallengesDTO dto = new UserChallengesDTO();
dto.setQuestion(question);
dto.setAnswer(answer);
return stub.verifyChallengeQuestion(userId, userKey, new UserChallengesDTO[] { dto });
} catch (Exception e) {
handleException(e.getMessage(), e);
}
return null;
}
Aggregations