Search in sources :

Example 11 with UserChallengesDTO

use of org.wso2.carbon.identity.mgt.stub.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");
}
Also used : UserChallengesDTO(org.wso2.carbon.identity.mgt.stub.dto.UserChallengesDTO) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 12 with UserChallengesDTO

use of org.wso2.carbon.identity.mgt.stub.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];
    }
}
Also used : UserChallengesDTO(org.wso2.carbon.identity.mgt.dto.UserChallengesDTO) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.core.UserStoreException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 13 with UserChallengesDTO

use of org.wso2.carbon.identity.mgt.stub.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;
}
Also used : UserChallengesDTO(org.wso2.carbon.identity.mgt.dto.UserChallengesDTO) UserStoreException(org.wso2.carbon.user.core.UserStoreException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 14 with UserChallengesDTO

use of org.wso2.carbon.identity.mgt.stub.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;
}
Also used : UserChallengesDTO(org.wso2.carbon.identity.mgt.dto.UserChallengesDTO) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.core.UserStoreException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 15 with UserChallengesDTO

use of org.wso2.carbon.identity.mgt.stub.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;
}
Also used : UserChallengesDTO(org.wso2.carbon.identity.mgt.stub.dto.UserChallengesDTO)

Aggregations

UserChallengesDTO (org.wso2.carbon.identity.mgt.dto.UserChallengesDTO)17 IdentityException (org.wso2.carbon.identity.base.IdentityException)16 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)8 UserStoreException (org.wso2.carbon.user.core.UserStoreException)8 ArrayList (java.util.ArrayList)6 ChallengeQuestionProcessor (org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor)6 IdentityMgtServiceException (org.wso2.carbon.identity.mgt.IdentityMgtServiceException)6 RecoveryProcessor (org.wso2.carbon.identity.mgt.RecoveryProcessor)6 VerificationBean (org.wso2.carbon.identity.mgt.beans.VerificationBean)6 UserDTO (org.wso2.carbon.identity.mgt.dto.UserDTO)6 HashMap (java.util.HashMap)4 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)4 Map (java.util.Map)3 UserChallengesDTO (org.wso2.carbon.identity.mgt.stub.dto.UserChallengesDTO)3 Test (org.testng.annotations.Test)2 SetEnvironment (org.wso2.carbon.automation.engine.annotations.SetEnvironment)2 ChallengeQuestionDTO (org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO)2 AuthorizationManager (org.wso2.carbon.user.api.AuthorizationManager)2 UserStoreException (org.wso2.carbon.user.api.UserStoreException)2 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)2