use of org.wso2.micro.gateway.jwt.generator.ClaimDTO in project carbon-identity-framework by wso2.
the class ChallengeQuestionProcessor method setChallengesOfUser.
/**
* @param userName
* @param tenantId
* @param challengesDTOs
* @throws IdentityException
*/
public void setChallengesOfUser(String userName, int tenantId, UserChallengesDTO[] challengesDTOs) throws IdentityException {
try {
if (log.isDebugEnabled()) {
log.debug("Challenge Question from the user profile.");
}
List<String> challengesUris = new ArrayList<String>();
String challengesUrisValue = "";
String separator = IdentityMgtConfig.getInstance().getChallengeQuestionSeparator();
Map<String, String> oldClaims = new HashMap<String, String>();
Map<String, String> newClaims = new HashMap<String, String>();
String[] requestclaims = new String[challengesDTOs.length];
int x = 0;
for (UserChallengesDTO claimDto : challengesDTOs) {
requestclaims[x++] = claimDto.getId();
}
// Getting user store manager here to reduce the calls for claim retrieval.
// TODO need to put into a new method in a new release version. Used to avoid API changes in patch.
org.wso2.carbon.user.core.UserStoreManager userStoreManager = null;
RealmService realmService = IdentityMgtServiceComponent.getRealmService();
try {
if (realmService.getTenantUserRealm(tenantId) != null) {
userStoreManager = (org.wso2.carbon.user.core.UserStoreManager) realmService.getTenantUserRealm(tenantId).getUserStoreManager();
}
} catch (Exception e) {
String msg = "Error retrieving the user store manager for the tenant";
log.error(msg, e);
throw IdentityException.error(msg, e);
}
if (userStoreManager != null) {
oldClaims = userStoreManager.getUserClaimValues(userName, requestclaims, null);
}
if (!ArrayUtils.isEmpty(challengesDTOs)) {
for (UserChallengesDTO dto : challengesDTOs) {
if (dto.getId() != null && dto.getQuestion() != null && dto.getAnswer() != null) {
String oldClaimValue = oldClaims.get(dto.getId());
if ((oldClaimValue != null) && oldClaimValue.contains(separator)) {
String oldAnswer = oldClaimValue.split(separator)[1];
if (!oldAnswer.trim().equals(dto.getAnswer().trim())) {
String claimValue = dto.getQuestion().trim() + separator + Utils.doHash(dto.getAnswer().trim().toLowerCase());
if (!oldClaimValue.equals(claimValue)) {
newClaims.put(dto.getId().trim(), claimValue);
}
}
} else {
String claimValue = dto.getQuestion().trim() + separator + Utils.doHash(dto.getAnswer().trim().toLowerCase());
newClaims.put(dto.getId().trim(), claimValue);
}
challengesUris.add(dto.getId().trim());
}
}
for (String challengesUri : challengesUris) {
if ("".equals(challengesUrisValue)) {
challengesUrisValue = challengesUri;
} else {
challengesUrisValue = challengesUrisValue + IdentityMgtConfig.getInstance().getChallengeQuestionSeparator() + challengesUri;
}
}
newClaims.put("http://wso2.org/claims/challengeQuestionUris", challengesUrisValue);
// Single call to save all challenge questions.
userStoreManager.setUserClaimValues(userName, newClaims, UserCoreConstants.DEFAULT_PROFILE);
}
} catch (org.wso2.carbon.user.api.UserStoreException e) {
String msg = "No associated challenge question found for the user";
throw IdentityException.error(msg, e);
}
}
use of org.wso2.micro.gateway.jwt.generator.ClaimDTO in project identity-governance by wso2-extensions.
the class ClaimsApiServiceImpl method claimsGet.
@Override
public Response claimsGet(String tenantDomain) {
if (IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT) != null) {
tenantDomain = (String) IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT);
}
if (StringUtils.isBlank(tenantDomain)) {
tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
} else if (!RecoveryUtil.isValidTenantDomain(tenantDomain)) {
RecoveryUtil.handleBadRequest("Invalid tenant domain :" + tenantDomain, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_TENANT.getCode());
}
String dialect = IdentityRecoveryConstants.WSO2CARBON_CLAIM_DIALECT;
NotificationUsernameRecoveryManager notificationBasedUsernameRecoveryManager = RecoveryUtil.getNotificationBasedUsernameRecoveryManager();
ClaimDTO[] claimDTOs = new ClaimDTO[0];
try {
Claim[] userClaims = notificationBasedUsernameRecoveryManager.getIdentitySupportedClaims(dialect, tenantDomain);
claimDTOs = RecoveryUtil.getClaimDTOs(userClaims);
} catch (IdentityRecoveryClientException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Client Error while getting all identity claims ", e);
}
RecoveryUtil.handleBadRequest(e.getMessage(), e.getErrorCode());
} catch (IdentityRecoveryException e) {
RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, null);
} catch (Throwable throwable) {
RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
}
return Response.ok(claimDTOs).build();
}
use of org.wso2.micro.gateway.jwt.generator.ClaimDTO in project identity-governance by wso2-extensions.
the class MeApiServiceImplTest method selfUserRegistrationRequestDTO.
private SelfUserRegistrationRequestDTO selfUserRegistrationRequestDTO() {
SelfUserRegistrationRequestDTO selfUserRegistrationRequestDTO = new SelfUserRegistrationRequestDTO();
List<ClaimDTO> listClaimDTO = new ArrayList<>();
listClaimDTO.add(buildClaimDTO());
buildSelfRegistartion().setClaims(listClaimDTO);
List<PropertyDTO> listPropertyDTOs = new ArrayList<>();
listPropertyDTOs.add(buildSelfUserRegistrationRequestDTO());
selfUserRegistrationRequestDTO.setProperties(listPropertyDTOs);
selfUserRegistrationRequestDTO.setUser(buildSelfRegistartion());
return selfUserRegistrationRequestDTO;
}
use of org.wso2.micro.gateway.jwt.generator.ClaimDTO in project product-is by wso2.
the class UserInformationRecoveryServiceTestCase method testInit.
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
@BeforeClass(alwaysRun = true)
public void testInit() throws Exception {
super.init();
String carbonHome = Utils.getResidentCarbonHome();
identityMgtServerFile = new File(carbonHome + File.separator + "repository" + File.separator + "conf" + File.separator + "identity" + File.separator + "identity-mgt.properties");
File identityMgtConfigFile = new File(getISResourceLocation() + File.separator + "identityMgt" + File.separator + "identity-mgt-enabled.properties");
axisServerFile = new File(carbonHome + File.separator + "repository" + File.separator + "conf" + File.separator + "axis2" + File.separator + "axis2.xml");
File axisConfigFile = new File(getISResourceLocation() + File.separator + "identityMgt" + File.separator + "axis2.xml");
scm = new ServerConfigurationManager(isServer);
scm.applyConfigurationWithoutRestart(identityMgtConfigFile, identityMgtServerFile, true);
scm.applyConfigurationWithoutRestart(axisConfigFile, axisServerFile, true);
scm.restartGracefully();
super.init();
loginManger = new AuthenticatorClient(backendURL);
userMgtClient = new UserManagementClient(backendURL, sessionCookie);
infoRecoveryClient = new UserInformationRecoveryServiceClient(backendURL, sessionCookie);
profileClient = new UserProfileMgtServiceClient(backendURL, sessionCookie);
loginManger.login(isServer.getSuperTenant().getTenantAdmin().getUserName(), isServer.getSuperTenant().getTenantAdmin().getPassword(), isServer.getInstance().getHosts().get("default"));
claimMgtClient = new ClaimManagementServiceClient(backendURL, sessionCookie);
ClaimDTO claim1 = new ClaimDTO();
claim1.setDialectURI("http://wso2.org/claims");
claim1.setClaimUri("http://wso2.org/claims/identity/unlockTime");
claim1.setDescription("Account Unlock time");
ClaimDTO claim2 = new ClaimDTO();
claim2.setDialectURI("http://wso2.org/claims");
claim2.setClaimUri("http://wso2.org/claims/identity/failedLoginAttempts");
claim2.setDescription("Failed login attempts");
ClaimMappingDTO claimMapping1 = new ClaimMappingDTO();
claimMapping1.setClaim(claim1);
claimMapping1.setMappedAttribute("description");
claimMgtClient.addNewClaimMapping(claimMapping1);
ClaimMappingDTO claimMapping2 = new ClaimMappingDTO();
claimMapping2.setClaim(claim2);
claimMapping2.setMappedAttribute("employeeType");
claimMgtClient.addNewClaimMapping(claimMapping2);
userMgtClient.addUser("user11", "passWord1@", null, "default");
userMgtClient.addRole("umRole11", new String[] { "user11" }, new String[] { "/permission/admin/login" }, false);
}
use of org.wso2.micro.gateway.jwt.generator.ClaimDTO in project product-is by wso2.
the class ClaimManagementServiceTestCase method testUpdateCliamMapping.
@Test(alwaysRun = true, description = "Update claim mapping", dependsOnMethods = "testAddNewCliamMapping")
public void testUpdateCliamMapping() {
ClaimMappingDTO mapping = new ClaimMappingDTO();
ClaimDTO claim = new ClaimDTO();
claim.setClaimUri(CLAIM_URI_NEW);
claim.setDisplayTag(DISPLAY_NAME_NEW);
claim.setDescription(DESCRIPTION_NEW);
claim.setDialectURI(DIALECT);
claim.setRegEx(REGEX);
claim.setDisplayOrder(DISPLAY_ORDER);
claim.setRequired(REQUIRED);
claim.setSupportedByDefault(SUPPORTED);
claim.setReadOnly(READONLY);
mapping.setClaim(claim);
if (ATTRIBUTE != null) {
String[] attributes = ATTRIBUTE.split(";");
List<ClaimAttributeDTO> attrList = new ArrayList<ClaimAttributeDTO>();
for (int i = 0; i < attributes.length; i++) {
int index = 0;
if ((index = attributes[i].indexOf("/")) > 1 && attributes[i].indexOf("/") == attributes[i].lastIndexOf("/")) {
String domain = attributes[i].substring(0, index);
String attrName = attributes[i].substring(index + 1);
ClaimAttributeDTO attr = new ClaimAttributeDTO();
attr.setAttributeName(attrName);
attr.setDomainName(domain);
attrList.add(attr);
} else {
mapping.setMappedAttribute(attributes[i]);
}
}
if (attrList.size() > 0) {
mapping.setMappedAttributes(attrList.toArray(new ClaimAttributeDTO[attrList.size()]));
}
}
try {
adminClient.updateClaimMapping(mapping);
ClaimDialectDTO dialectDTO = adminClient.getClaimMappingByDialect(DIALECT);
Assert.assertNotNull(dialectDTO, "Claim mapping adding failed.");
for (ClaimMappingDTO mappingDTO : dialectDTO.getClaimMappings()) {
if (CLAIM_URI_NEW.equals(mappingDTO.getClaim().getClaimUri())) {
Assert.assertEquals(DESCRIPTION_NEW, mappingDTO.getClaim().getDescription(), "Claim mapping update failed.");
Assert.assertEquals(DISPLAY_NAME_NEW, mappingDTO.getClaim().getDisplayTag(), "Claim mapping update failed.");
break;
}
}
} catch (Exception e) {
Assert.fail("Error while trying to update claim mapping", e);
}
}
Aggregations