Search in sources :

Example 6 with ChallengeQuestionProcessor

use of org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor in project carbon-identity-framework by wso2.

the class UserInformationRecoveryService method getAllChallengeQuestions.

/**
 * Get all challenge questions
 *
 * @return array of questions
 * @throws IdentityMgtServiceException if fails
 */
public ChallengeQuestionDTO[] getAllChallengeQuestions() throws IdentityMgtServiceException {
    ChallengeQuestionProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor().getQuestionProcessor();
    List<ChallengeQuestionDTO> questionDTOs = null;
    try {
        questionDTOs = processor.getAllChallengeQuestions();
    } catch (IdentityException e) {
        log.error("Error while loading user challenges", e);
        throw new IdentityMgtServiceException("Error while loading user challenges");
    }
    return questionDTOs.toArray(new ChallengeQuestionDTO[questionDTOs.size()]);
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) ChallengeQuestionProcessor(org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor) IdentityException(org.wso2.carbon.identity.base.IdentityException) ChallengeQuestionDTO(org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO)

Example 7 with ChallengeQuestionProcessor

use of org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor in project carbon-identity-framework by wso2.

the class UserIdentityManagementAdminService method getChallengeQuestionsOfUser.

/**
 * get challenges of user
 *
 * @param userName bean class that contains user and tenant Information
 * @return array of challenges  if null, return empty array
 * @throws org.wso2.carbon.identity.mgt.IdentityMgtServiceException if fails
 */
public UserChallengesDTO[] getChallengeQuestionsOfUser(String userName) throws IdentityMgtServiceException {
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    String loggedInName = CarbonContext.getThreadLocalCarbonContext().getUsername();
    if (userName != null && !userName.equals(loggedInName)) {
        AuthorizationManager authzManager = null;
        try {
            authzManager = IdentityMgtServiceComponent.getRealmService().getTenantUserRealm(tenantId).getAuthorizationManager();
        } catch (UserStoreException e) {
            throw new IdentityMgtServiceException("Error occurred while retrieving AuthorizationManager for tenant " + tenantDomain, e);
        }
        boolean isAuthorized = false;
        try {
            isAuthorized = authzManager.isUserAuthorized(loggedInName, "/permission/admin/manage/identity/identitymgt/view", CarbonConstants.UI_PERMISSION_ACTION);
        } catch (UserStoreException e) {
            throw new IdentityMgtServiceException("Error occurred while checking access level for " + "user " + userName + " in tenant " + tenantDomain, e);
        }
        if (!isAuthorized) {
            throw new IdentityMgtServiceException("Unauthorized access!! Possible violation of confidentiality. " + "User " + loggedInName + " trying to get challenge questions for user " + userName);
        }
    } else if (userName == null) {
        userName = loggedInName;
    }
    ChallengeQuestionProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor().getQuestionProcessor();
    return processor.getChallengeQuestionsOfUser(userName, tenantId, true);
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) ChallengeQuestionProcessor(org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor) UserStoreException(org.wso2.carbon.user.api.UserStoreException) AuthorizationManager(org.wso2.carbon.user.api.AuthorizationManager)

Example 8 with ChallengeQuestionProcessor

use of org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor in project carbon-identity-framework by wso2.

the class UserIdentityManagementAdminService method getAllChallengeQuestions.

/**
 * get all challenge questions
 *
 * @return array of questions
 * @throws IdentityMgtServiceException if fails
 */
public ChallengeQuestionDTO[] getAllChallengeQuestions() throws IdentityMgtServiceException {
    ChallengeQuestionProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor().getQuestionProcessor();
    List<ChallengeQuestionDTO> questionDTOs = null;
    try {
        questionDTOs = processor.getAllChallengeQuestions();
    } catch (IdentityException e) {
        String errorMessage = "Error while loading user challenge questions";
        log.error(errorMessage, e);
        throw new IdentityMgtServiceException(errorMessage);
    }
    return questionDTOs.toArray(new ChallengeQuestionDTO[questionDTOs.size()]);
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) ChallengeQuestionProcessor(org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor) IdentityException(org.wso2.carbon.identity.base.IdentityException) ChallengeQuestionDTO(org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO)

Aggregations

ChallengeQuestionProcessor (org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor)8 IdentityException (org.wso2.carbon.identity.base.IdentityException)7 IdentityMgtServiceException (org.wso2.carbon.identity.mgt.IdentityMgtServiceException)6 ChallengeQuestionDTO (org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO)4 RecoveryProcessor (org.wso2.carbon.identity.mgt.RecoveryProcessor)3 VerificationBean (org.wso2.carbon.identity.mgt.beans.VerificationBean)3 UserChallengesDTO (org.wso2.carbon.identity.mgt.dto.UserChallengesDTO)3 UserDTO (org.wso2.carbon.identity.mgt.dto.UserDTO)3 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)2 AuthorizationManager (org.wso2.carbon.user.api.AuthorizationManager)2 UserStoreException (org.wso2.carbon.user.api.UserStoreException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 UserChallengesSetDTO (org.wso2.carbon.identity.mgt.dto.UserChallengesSetDTO)1