Search in sources :

Example 6 with ClaimDTO

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);
    }
}
Also used : UserChallengesDTO(org.wso2.carbon.identity.mgt.dto.UserChallengesDTO) HashMap(java.util.HashMap) 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) RealmService(org.wso2.carbon.user.core.service.RealmService)

Example 7 with ClaimDTO

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();
}
Also used : ClaimDTO(org.wso2.carbon.identity.recovery.endpoint.dto.ClaimDTO) NotificationUsernameRecoveryManager(org.wso2.carbon.identity.recovery.username.NotificationUsernameRecoveryManager) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) Claim(org.wso2.carbon.user.api.Claim) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 8 with ClaimDTO

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;
}
Also used : SelfUserRegistrationRequestDTO(org.wso2.carbon.identity.user.endpoint.dto.SelfUserRegistrationRequestDTO) ClaimDTO(org.wso2.carbon.identity.user.endpoint.dto.ClaimDTO) ArrayList(java.util.ArrayList) PropertyDTO(org.wso2.carbon.identity.user.endpoint.dto.PropertyDTO)

Example 9 with ClaimDTO

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);
}
Also used : UserProfileMgtServiceClient(org.wso2.identity.integration.common.clients.UserProfileMgtServiceClient) ClaimMappingDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimMappingDTO) UserIdentityClaimDTO(org.wso2.carbon.identity.mgt.stub.dto.UserIdentityClaimDTO) ClaimDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimDTO) ClaimManagementServiceClient(org.wso2.identity.integration.common.clients.ClaimManagementServiceClient) AuthenticatorClient(org.wso2.carbon.integration.common.admin.client.AuthenticatorClient) ServerConfigurationManager(org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager) UserManagementClient(org.wso2.identity.integration.common.clients.UserManagementClient) File(java.io.File) UserInformationRecoveryServiceClient(org.wso2.identity.integration.common.clients.mgt.UserInformationRecoveryServiceClient) BeforeClass(org.testng.annotations.BeforeClass) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment)

Example 10 with ClaimDTO

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);
    }
}
Also used : ClaimMappingDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimMappingDTO) ClaimDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimDTO) ArrayList(java.util.ArrayList) ClaimAttributeDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimAttributeDTO) ClaimDialectDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimDialectDTO) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Aggregations

ArrayList (java.util.ArrayList)9 ClaimDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimDTO)7 ClaimMappingDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimMappingDTO)7 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)5 Test (org.testng.annotations.Test)4 ClaimDialectDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimDialectDTO)4 Claim (org.wso2.carbon.user.api.Claim)4 HashMap (java.util.HashMap)3 ClaimAttributeDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimAttributeDTO)3 ClaimDTO (org.wso2.carbon.identity.test.integration.service.stub.ClaimDTO)3 ClaimDTO (org.wso2.carbon.identity.user.endpoint.dto.ClaimDTO)3 ClaimDTO (org.wso2.carbon.um.ws.api.stub.ClaimDTO)3 UserIdentityClaimDTO (org.wso2.carbon.identity.mgt.dto.UserIdentityClaimDTO)2 ClaimDTO (org.wso2.carbon.identity.recovery.endpoint.dto.ClaimDTO)2 ClaimValue (org.wso2.carbon.identity.test.integration.service.stub.ClaimValue)2 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Map (java.util.Map)1 BPackage (org.ballerinalang.jvm.types.BPackage)1 BArray (org.ballerinalang.jvm.values.api.BArray)1