Search in sources :

Example 1 with ClaimAttributeMapping

use of org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping in project identity-api-server by wso2.

the class ServerUserStoreService method getUserStoreByDomainId.

/**
 * Retrieve user store by its domain id.
 *
 * @param domainId the user store domain id.
 * @return UserStoreConfigurationsRes.
 */
public UserStoreConfigurationsRes getUserStoreByDomainId(String domainId) {
    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
    List<AddUserStorePropertiesRes> propertiesTobeAdd = new ArrayList<>();
    try {
        UserStoreDTO userStoreDTO = userStoreConfigService.getUserStore(base64URLDecodeId(domainId));
        if (userStoreDTO == null) {
            throw handleException(Response.Status.NOT_FOUND, UserStoreConstants.ErrorMessage.ERROR_CODE_NOT_FOUND);
        }
        List<ClaimAttributeMapping> claimAttributeMappings = getClaimAttributeMappings(ContextLoader.getTenantDomainFromContext(), base64URLDecodeId(domainId));
        UserStoreConfigurationsRes userStoreConfigurations = new UserStoreConfigurationsRes();
        userStoreConfigurations.setClassName(userStoreDTO.getClassName());
        userStoreConfigurations.setDescription(userStoreDTO.getDescription());
        userStoreConfigurations.setName(userStoreDTO.getDomainId());
        userStoreConfigurations.setTypeId(base64URLEncodeId(Objects.requireNonNull(getUserStoreTypeName(userStoreDTO.getClassName()))));
        userStoreConfigurations.setTypeName(getUserStoreTypeName(userStoreDTO.getClassName()));
        PropertyDTO[] dtoProperties = userStoreDTO.getProperties();
        for (PropertyDTO propertyDTO : dtoProperties) {
            AddUserStorePropertiesRes userStorePropertiesRes = new AddUserStorePropertiesRes();
            userStorePropertiesRes.setName(propertyDTO.getName());
            userStorePropertiesRes.setValue(propertyDTO.getValue());
            propertiesTobeAdd.add(userStorePropertiesRes);
        }
        userStoreConfigurations.setProperties(propertiesTobeAdd);
        try {
            userStoreConfigurations.setIsLocal(UserStoreManagerRegistry.isLocalUserStore(userStoreDTO.getClassName()));
            userStoreConfigurations.setClaimAttributeMappings(claimAttributeMappings);
        } catch (UserStoreException e) {
            LOG.error(String.format("Cannot found user store manager type for user store manager: %s", getUserStoreType(userStoreDTO.getClassName())), e);
        }
        return userStoreConfigurations;
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_USER_STORE_BY_DOMAIN_ID;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) ClaimAttributeMapping(org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping) ArrayList(java.util.ArrayList) AddUserStorePropertiesRes(org.wso2.carbon.identity.api.server.userstore.v1.model.AddUserStorePropertiesRes) UserStoreConfigService(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserStoreConfigurationsRes(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreConfigurationsRes) PropertyDTO(org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO)

Example 2 with ClaimAttributeMapping

use of org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping in project identity-api-server by wso2.

the class ServerUserStoreService method addUserStore.

/**
 * Add a userStore {@link UserStoreReq}.
 *
 * @param userStoreReq {@link UserStoreReq} to insert.
 * @return UserStoreResponse
 */
public UserStoreResponse addUserStore(UserStoreReq userStoreReq) {
    try {
        validateMandatoryProperties(userStoreReq);
        if (!isAvailableUserStoreTypes(getAvailableUserStoreTypes(), userStoreReq.getTypeId())) {
            throw handleException(Response.Status.BAD_REQUEST, UserStoreConstants.ErrorMessage.ERROR_CODE_INVALID_USERSTORE_TYPE);
        }
        String userstoreDomain = userStoreReq.getName();
        String tenantDomain = ContextLoader.getTenantDomainFromContext();
        List<LocalClaim> localClaimList = new ArrayList<>();
        List<ClaimAttributeMapping> claimAttributeMappingList = userStoreReq.getClaimAttributeMappings();
        if (claimAttributeMappingList != null) {
            localClaimList = createLocalClaimList(userstoreDomain, claimAttributeMappingList);
            validateClaimMappings(tenantDomain, localClaimList);
        }
        UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
        UserStoreDTO userStoreDTO = createUserStoreDTO(userStoreReq);
        userStoreConfigService.addUserStore(userStoreDTO);
        if (claimAttributeMappingList != null) {
            updateClaimMappings(userstoreDomain, tenantDomain, localClaimList);
        }
        return buildUserStoreResponseDTO(userStoreReq);
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_ADDING_USER_STORE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) ClaimAttributeMapping(org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) ArrayList(java.util.ArrayList) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) UserStoreConfigService(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)

Example 3 with ClaimAttributeMapping

use of org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping in project identity-api-server by wso2.

the class ServerUserStoreService method editUserStore.

/**
 * Update the user store by its domain Id.
 *
 * @param domainId     the domain name to be replaced
 * @param userStoreReq {@link UserStoreReq} to edit.
 * @return UserStoreResponse.
 */
public UserStoreResponse editUserStore(String domainId, UserStoreReq userStoreReq) {
    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
    /*
        domainName and typeName are not allowed to edit. iF domain name wanted to update then use
        userStoreConfigService.updateUserStoreByDomainName(base64URLDecodeId(domainId),
        createUserStoreDTO(userStoreReq, domainId));
         */
    try {
        validateUserstoreUpdateRequest(domainId, userStoreReq);
        String userstoreDomain = userStoreReq.getName();
        String tenantDomain = ContextLoader.getTenantDomainFromContext();
        List<LocalClaim> localClaimList = new ArrayList<>();
        List<ClaimAttributeMapping> claimAttributeMappingList = userStoreReq.getClaimAttributeMappings();
        if (claimAttributeMappingList != null) {
            localClaimList = createLocalClaimList(userstoreDomain, claimAttributeMappingList);
            validateClaimMappings(tenantDomain, localClaimList);
        }
        userStoreConfigService.updateUserStore(createUserStoreDTO(userStoreReq), false);
        if (claimAttributeMappingList != null) {
            updateClaimMappings(userstoreDomain, tenantDomain, localClaimList);
        }
        return buildUserStoreResponseDTO(userStoreReq);
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_USER_STORE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) ClaimAttributeMapping(org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping) ArrayList(java.util.ArrayList) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) UserStoreConfigService(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)

Example 4 with ClaimAttributeMapping

use of org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping in project identity-api-server by wso2.

the class ServerUserStoreService method createLocalClaimList.

/**
 * To create Local claim list from a claim attribute mapping list.
 *
 * @param userStoreId user store domain Id.
 * @param claimAttributeMappingList list of claim attribute mappings.
 * @return List<LocalClaim>.
 */
private List<LocalClaim> createLocalClaimList(String userStoreId, List<ClaimAttributeMapping> claimAttributeMappingList) {
    List<LocalClaim> localClaimList = new ArrayList<>();
    for (ClaimAttributeMapping claimAttributeMapping : claimAttributeMappingList) {
        AttributeMapping attributeMapping = new AttributeMapping(userStoreId, claimAttributeMapping.getMappedAttribute());
        LocalClaim localClaim = new LocalClaim(claimAttributeMapping.getClaimURI());
        localClaim.setMappedAttribute(attributeMapping);
        localClaimList.add(localClaim);
    }
    return localClaimList;
}
Also used : ClaimAttributeMapping(org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping) AttributeMapping(org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping) ClaimAttributeMapping(org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping) ArrayList(java.util.ArrayList) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)

Example 5 with ClaimAttributeMapping

use of org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping in project identity-api-server by wso2.

the class ServerUserStoreService method getPrimaryUserStore.

/**
 * Retrieve primary user store.
 *
 * @return UserStoreConfigurationsRes.
 */
public UserStoreConfigurationsRes getPrimaryUserStore() {
    RealmService realmService = UserStoreConfigServiceHolder.getInstance().getRealmService();
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    RealmConfiguration realmConfiguration;
    try {
        realmConfiguration = realmService.getTenantUserRealm(tenantId).getRealmConfiguration();
    } catch (UserStoreException exception) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Error occurred while getting the RealmConfiguration for tenant: " + tenantId, exception);
        }
        throw handleException(Response.Status.INTERNAL_SERVER_ERROR, UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_REALM_CONFIG, Integer.toString(tenantId));
    }
    if (realmConfiguration == null) {
        throw handleException(Response.Status.INTERNAL_SERVER_ERROR, UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_PRIMARY_USERSTORE);
    }
    List<AddUserStorePropertiesRes> propertiesTobeAdd = new ArrayList<>();
    UserStoreConfigurationsRes primaryUserstoreConfigs = new UserStoreConfigurationsRes();
    primaryUserstoreConfigs.setClassName(realmConfiguration.getUserStoreClass());
    primaryUserstoreConfigs.setDescription(realmConfiguration.getDescription());
    primaryUserstoreConfigs.setName(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME);
    primaryUserstoreConfigs.setTypeId(base64URLEncodeId(Objects.requireNonNull(getUserStoreTypeName(realmConfiguration.getUserStoreClass()))));
    primaryUserstoreConfigs.setTypeName(getUserStoreTypeName(realmConfiguration.getUserStoreClass()));
    Map<String, String> userstoreProps = realmConfiguration.getUserStoreProperties();
    if (MapUtils.isNotEmpty(userstoreProps)) {
        for (Map.Entry<String, String> entry : userstoreProps.entrySet()) {
            AddUserStorePropertiesRes userStorePropertiesRes = new AddUserStorePropertiesRes();
            userStorePropertiesRes.setName(entry.getKey());
            if (UserStoreConfigConstants.connectionPassword.equals(entry.getKey())) {
                userStorePropertiesRes.setValue(UserStoreConstants.USER_STORE_PROPERTY_MASK);
            } else {
                userStorePropertiesRes.setValue(entry.getValue());
            }
            propertiesTobeAdd.add(userStorePropertiesRes);
        }
    }
    primaryUserstoreConfigs.setProperties(propertiesTobeAdd);
    try {
        primaryUserstoreConfigs.setIsLocal(UserStoreManagerRegistry.isLocalUserStore(realmConfiguration.getUserStoreClass()));
        List<ClaimAttributeMapping> claimAttributeMappings = getClaimAttributeMappings(ContextLoader.getTenantDomainFromContext(), UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME);
        primaryUserstoreConfigs.setClaimAttributeMappings(claimAttributeMappings);
    } catch (UserStoreException e) {
        LOG.error(String.format("Cannot found user store manager type for user store manager: %s", getUserStoreType(realmConfiguration.getUserStoreClass())), e);
    }
    return primaryUserstoreConfigs;
}
Also used : ClaimAttributeMapping(org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping) ArrayList(java.util.ArrayList) AddUserStorePropertiesRes(org.wso2.carbon.identity.api.server.userstore.v1.model.AddUserStorePropertiesRes) RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserStoreConfigurationsRes(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreConfigurationsRes) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ArrayList (java.util.ArrayList)6 ClaimAttributeMapping (org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping)6 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)4 UserStoreConfigService (org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)3 IdentityUserStoreMgtException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException)3 AddUserStorePropertiesRes (org.wso2.carbon.identity.api.server.userstore.v1.model.AddUserStorePropertiesRes)2 UserStoreConfigurationsRes (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreConfigurationsRes)2 UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)2 UserStoreException (org.wso2.carbon.user.api.UserStoreException)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ClaimMetadataManagementService (org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService)1 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)1 AttributeMapping (org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping)1 PropertyDTO (org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO)1 RealmConfiguration (org.wso2.carbon.user.api.RealmConfiguration)1 RealmService (org.wso2.carbon.user.core.service.RealmService)1