Search in sources :

Example 21 with ClaimValue

use of org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue in project identity-inbound-auth-oauth by wso2-extensions.

the class UserInfoJSONResponseBuilderTest method testLongClaimInUserInfoResponse.

private void testLongClaimInUserInfoResponse(String claimUri, String claimValue) throws Exception {
    initSingleClaimTest(claimUri, claimValue);
    mockDataSource();
    mockObjectsRelatedToTokenValidation();
    mockStatic(FrameworkUtils.class);
    when(FrameworkUtils.resolveUserIdFromUsername(anyInt(), anyString(), anyString())).thenReturn(AUTHORIZED_USER_ID);
    AuthenticatedUser authenticatedUser = new AuthenticatedUser();
    authenticatedUser.setUserName(AUTHORIZED_USER_NAME);
    authenticatedUser.setTenantDomain(TENANT_DOT_COM);
    authenticatedUser.setUserStoreDomain(JDBC_DOMAIN);
    authenticatedUser.setUserId(AUTHORIZED_USER_ID);
    authenticatedUser.setAuthenticatedSubjectIdentifier(AUTHORIZED_USER_ID);
    mockAccessTokenDOInOAuth2Util(authenticatedUser);
    String responseString = userInfoJSONResponseBuilder.getResponseString(getTokenResponseDTO(AUTHORIZED_USER_FULL_QUALIFIED));
    Map<String, Object> claimsInResponse = JSONUtils.parseJSON(responseString);
    assertSubjectClaimPresent(claimsInResponse);
    assertNotNull(claimsInResponse.get(claimUri));
    assertTrue(claimsInResponse.get(claimUri) instanceof Integer || claimsInResponse.get(claimUri) instanceof Long);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)

Example 22 with ClaimValue

use of org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue in project identity-inbound-auth-oauth by wso2-extensions.

the class ClaimProviderImpl method getAdditionalClaims.

@Override
public Map<String, Object> getAdditionalClaims(OAuthAuthzReqMessageContext oAuthAuthzReqMessageContext, OAuth2AuthorizeRespDTO oAuth2AuthorizeRespDTO) throws IdentityOAuth2Exception {
    Map<String, Object> additionalClaims = new HashMap<>();
    String claimValue;
    OIDCSessionState previousSession = getSessionState(oAuthAuthzReqMessageContext);
    if (previousSession == null) {
        // If there is no previous browser session, generate new sid value.
        claimValue = UUID.randomUUID().toString();
        if (log.isDebugEnabled()) {
            log.debug("sid claim is generated for auth request. ");
        }
    } else {
        // Previous browser session exists, get sid claim from OIDCSessionState.
        claimValue = previousSession.getSidClaim();
        if (log.isDebugEnabled()) {
            log.debug("sid claim is found in the session state");
        }
    }
    additionalClaims.put(OAuthConstants.OIDCClaims.SESSION_ID_CLAIM, claimValue);
    oAuth2AuthorizeRespDTO.setOidcSessionId(claimValue);
    return additionalClaims;
}
Also used : HashMap(java.util.HashMap) OIDCSessionState(org.wso2.carbon.identity.oidc.session.OIDCSessionState)

Example 23 with ClaimValue

use of org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue in project identity-governance by wso2-extensions.

the class IdentityUserMetadataMgtHandler method setUserClaim.

private void setUserClaim(UserStoreManager userStoreManager, Map<String, Object> eventProperties, String claimURI, String claimValue, String eventName) throws IdentityEventException {
    String username = (String) eventProperties.get(IdentityEventConstants.EventProperty.USER_NAME);
    Map<String, String> userClaims = new HashMap<>();
    userClaims.put(claimURI, claimValue);
    try {
        userStoreManager.setUserClaimValues(username, userClaims, null);
        if (log.isDebugEnabled()) {
            log.debug(String.format("Successfully updated the user claims related to %s event.", eventName));
        }
    } catch (UserStoreException e) {
        throw new IdentityEventException(String.format("Error occurred while updating user claims related to %s event.", eventName), e);
    }
}
Also used : HashMap(java.util.HashMap) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) UserStoreException(org.wso2.carbon.user.core.UserStoreException)

Example 24 with ClaimValue

use of org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue in project identity-governance by wso2-extensions.

the class UserEmailVerificationHandler method setUserClaim.

protected void setUserClaim(String claimName, String claimValue, UserStoreManager userStoreManager, User user) throws IdentityEventException {
    HashMap<String, String> userClaims = new HashMap<>();
    userClaims.put(claimName, claimValue);
    try {
        userStoreManager.setUserClaimValues(user.getUserName(), userClaims, null);
    } catch (UserStoreException e) {
        throw new IdentityEventException("Error while setting user claim value :" + user.getUserName(), e);
    }
}
Also used : HashMap(java.util.HashMap) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) UserStoreException(org.wso2.carbon.user.core.UserStoreException)

Example 25 with ClaimValue

use of org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue in project identity-governance by wso2-extensions.

the class ChallengeQuestionManager method setChallengesOfUser.

/**
 * @param user
 * @param userChallengeAnswers
 * @throws IdentityException
 */
public void setChallengesOfUser(User user, UserChallengeAnswer[] userChallengeAnswers) throws IdentityRecoveryException {
    validateUser(user);
    if (log.isDebugEnabled()) {
        log.debug(String.format("Setting user challenge question answers in %s's profile.", user.toString()));
    }
    try {
        String tenantDomain = StringUtils.isBlank(user.getTenantDomain()) ? MultitenantConstants.SUPER_TENANT_DOMAIN_NAME : user.getTenantDomain();
        // validate whether two questions from the same set has been answered.
        validateSecurityQuestionDuplicate(userChallengeAnswers);
        // check whether the answered questions exist in the tenant domain
        checkChallengeQuestionExists(userChallengeAnswers, tenantDomain);
        // Get the existing challenge questions and answers for the user.
        Map<String, String> existingQuestionAndAnswers = retrieveAnsweredChallenges(user, userChallengeAnswers);
        triggerChallengeAnswersValidation(user, userChallengeAnswers, existingQuestionAndAnswers, IdentityEventConstants.Event.PRE_SET_CHALLENGE_QUESTION_ANSWERS);
        List<String> challengesUris = new ArrayList<String>();
        String challengesUrisValue = "";
        String separator = getChallengeSeparator();
        Map<String, String> challengeQuestionToUpdate = new HashMap<>();
        if (!ArrayUtils.isEmpty(userChallengeAnswers)) {
            for (UserChallengeAnswer userChallengeAnswer : userChallengeAnswers) {
                if (StringUtils.isNotBlank(userChallengeAnswer.getQuestion().getQuestionSetId()) && StringUtils.isNotBlank(userChallengeAnswer.getQuestion().getQuestion()) && StringUtils.isNotBlank(userChallengeAnswer.getAnswer())) {
                    // Get the previous answer for the question.
                    String oldValue = existingQuestionAndAnswers.get(userChallengeAnswer.getQuestion().getQuestionSetId().trim());
                    if (oldValue != null && oldValue.contains(separator)) {
                        String oldAnswer = oldValue.split(separator)[1];
                        if (!oldAnswer.trim().equals(userChallengeAnswer.getAnswer().trim())) {
                            String claimValue = userChallengeAnswer.getQuestion().getQuestion().trim() + separator + Utils.doHash(userChallengeAnswer.getAnswer().trim().toLowerCase());
                            challengeQuestionToUpdate.put(userChallengeAnswer.getQuestion().getQuestionSetId().trim(), claimValue);
                        }
                    } else {
                        String claimValue = userChallengeAnswer.getQuestion().getQuestion().trim() + separator + Utils.doHash(userChallengeAnswer.getAnswer().trim().toLowerCase());
                        challengeQuestionToUpdate.put(userChallengeAnswer.getQuestion().getQuestionSetId().trim(), claimValue);
                    }
                    challengesUris.add(userChallengeAnswer.getQuestion().getQuestionSetId().trim());
                }
            }
            for (String challengesUri : challengesUris) {
                if ("".equals(challengesUrisValue)) {
                    challengesUrisValue = challengesUri;
                } else {
                    challengesUrisValue = challengesUrisValue + separator + challengesUri;
                }
            }
            challengeQuestionToUpdate.put(IdentityRecoveryConstants.CHALLENGE_QUESTION_URI, challengesUrisValue);
            if (MapUtils.isNotEmpty(challengeQuestionToUpdate)) {
                Utils.setClaimsListOfUser(user, challengeQuestionToUpdate);
            }
            triggerChallengeAnswersValidation(user, userChallengeAnswers, existingQuestionAndAnswers, IdentityEventConstants.Event.POST_SET_CHALLENGE_QUESTION_ANSWERS);
        }
    } catch (org.wso2.carbon.user.api.UserStoreException e) {
        throw Utils.handleServerException(ERROR_CODE_REMOVING_CHALLENGE_QUESTIONS, user.getUserName(), e);
    }
}
Also used : HashMap(java.util.HashMap) UserStoreException(org.wso2.carbon.user.api.UserStoreException) ArrayList(java.util.ArrayList) UserChallengeAnswer(org.wso2.carbon.identity.recovery.model.UserChallengeAnswer)

Aggregations

ClaimValue (org.wso2.carbon.um.ws.api.stub.ClaimValue)23 HashMap (java.util.HashMap)21 Test (org.testng.annotations.Test)19 UserStoreException (org.wso2.carbon.user.core.UserStoreException)14 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)14 Map (java.util.Map)13 ArrayList (java.util.ArrayList)11 RemoteException (java.rmi.RemoteException)9 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)9 UserStoreException (org.wso2.carbon.user.api.UserStoreException)9 ClaimValue (org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue)9 IdentityException (org.wso2.carbon.identity.base.IdentityException)8 WorkflowAdminServiceWorkflowException (org.wso2.carbon.identity.workflow.mgt.stub.WorkflowAdminServiceWorkflowException)8 Association (org.wso2.carbon.identity.workflow.mgt.stub.metadata.Association)8 Matchers.anyString (org.mockito.Matchers.anyString)7 FlaggedName (org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName)7 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)6 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)5 ClaimValue (org.wso2.carbon.user.mgt.common.ClaimValue)5 HashSet (java.util.HashSet)4