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);
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations