Search in sources :

Example 1 with UserStoreConfigService

use of org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService in project identity-api-server by wso2.

the class ServerUserStoreService method getUserStoreList.

/**
 * To retrieve the configured user store lists.
 *
 * @param limit  items per page.
 * @param offset 0 based index to get the results starting from this index + 1.
 * @param filter to specify the filtering capabilities.
 * @param sort   to specify the sorting order.
 * @return List<UserStoreListResponse>.
 */
public List<UserStoreListResponse> getUserStoreList(Integer limit, Integer offset, String filter, String sort, String requiredAttributes) {
    handleNotImplementedBehaviour(limit, offset, filter, sort);
    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
    try {
        UserStoreDTO[] userStoreDTOS = userStoreConfigService.getUserStores();
        return buildUserStoreListResponse(userStoreDTOS, requiredAttributes);
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_USER_STORE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) UserStoreConfigService(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)

Example 2 with UserStoreConfigService

use of org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService in project identity-api-server by wso2.

the class ServerUserStoreService method getUserStoreAttributeMappings.

/**
 * Get user store attributes mappings for a given user store type id.
 *
 * @param typeId                       String user store type id.
 * @param includeIdentityClaimMappings Whether to include claim mapping for identity claims with other userstore.
 *                                     attributes.
 * @return UserStoreAttributeMapping user store attribute mappings.
 */
public UserStoreAttributeMappingResponse getUserStoreAttributeMappings(String typeId, boolean includeIdentityClaimMappings) {
    Set<String> classNames;
    String userStoreName = getUserStoreType(base64URLDecodeId(typeId));
    if (StringUtils.isBlank(userStoreName)) {
        throw handleException(Response.Status.BAD_REQUEST, UserStoreConstants.ErrorMessage.ERROR_CODE_INVALID_INPUT);
    }
    try {
        UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
        classNames = userStoreConfigService.getAvailableUserStoreClasses();
        if (CollectionUtils.isEmpty(classNames) || !classNames.contains(userStoreName)) {
            throw handleException(Response.Status.NOT_FOUND, UserStoreConstants.ErrorMessage.ERROR_CODE_NOT_FOUND);
        }
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_USER_STORE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
    UserStoreAttributeMappingResponse userStoreAttributeMappingResponse = new UserStoreAttributeMappingResponse();
    List<UserStoreAttribute> attributeMappings = getAttributeMappings(userStoreName, includeIdentityClaimMappings);
    userStoreAttributeMappingResponse = userStoreAttributeMappingResponse.attributeMappings(new AttributeMappingsToApiModel().apply(attributeMappings)).typeId(typeId).typeName(userStoreName);
    try {
        boolean isLocal = UserStoreManagerRegistry.isLocalUserStore(userStoreName);
        userStoreAttributeMappingResponse.setIsLocal(isLocal);
    } catch (UserStoreException e) {
        LOG.error(String.format("Userstore type is not found for %s", userStoreName), e);
    }
    return userStoreAttributeMappingResponse;
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) UserStoreAttributeMappingResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreAttributeMappingResponse) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserStoreConfigService(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService) UserStoreAttribute(org.wso2.carbon.identity.user.store.configuration.model.UserStoreAttribute) AttributeMappingsToApiModel(org.wso2.carbon.identity.api.server.userstore.v1.core.functions.userstore.AttributeMappingsToApiModel)

Example 3 with UserStoreConfigService

use of org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService in project identity-api-server by wso2.

the class ServerUserStoreService method testRDBMSConnection.

/**
 * Check the connection heath for JDBC userstores.
 *
 * @param rdBMSConnectionReq {@link RDBMSConnectionReq}.
 * @return ConnectionEstablishedResponse.
 */
public ConnectionEstablishedResponse testRDBMSConnection(RDBMSConnectionReq rdBMSConnectionReq) {
    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
    ConnectionEstablishedResponse connectionEstablishedResponse = new ConnectionEstablishedResponse();
    boolean isConnectionEstablished;
    connectionEstablishedResponse.setConnection(false);
    try {
        isConnectionEstablished = userStoreConfigService.testRDBMSConnection(rdBMSConnectionReq.getDomain(), rdBMSConnectionReq.getDriverName(), rdBMSConnectionReq.getConnectionURL(), rdBMSConnectionReq.getUsername(), rdBMSConnectionReq.getConnectionPassword(), DUMMY_MESSAGE_ID);
        if (isConnectionEstablished) {
            connectionEstablishedResponse.setConnection(true);
        }
    } catch (IdentityUserStoreMgtException e) {
        connectionEstablishedResponse.setConnection(false);
    }
    return connectionEstablishedResponse;
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) UserStoreConfigService(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService) ConnectionEstablishedResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.ConnectionEstablishedResponse)

Example 4 with UserStoreConfigService

use of org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService in project identity-api-server by wso2.

the class ServerUserStoreService method deleteUserStore.

/**
 * Delete a userStore by its domainId.
 *
 * @param userstoreDomainId base64 encoded url value of userStore domain Id.
 */
public void deleteUserStore(String userstoreDomainId) {
    try {
        UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
        userStoreConfigService.deleteUserStore(base64URLDecodeId(userstoreDomainId));
    } catch (IdentityUserStoreClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(e);
        }
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_DELETING_USER_STORE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) IdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException) UserStoreConfigService(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)

Example 5 with UserStoreConfigService

use of org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService 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)

Aggregations

UserStoreConfigService (org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)12 IdentityUserStoreMgtException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException)11 ArrayList (java.util.ArrayList)5 UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)4 ClaimAttributeMapping (org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping)3 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)2 PropertyDTO (org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO)2 UserStoreAttribute (org.wso2.carbon.identity.user.store.configuration.model.UserStoreAttribute)2 UserStoreException (org.wso2.carbon.user.api.UserStoreException)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BundleContext (org.osgi.framework.BundleContext)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1 Activate (org.osgi.service.component.annotations.Activate)1 AttributeMappingsToApiModel (org.wso2.carbon.identity.api.server.userstore.v1.core.functions.userstore.AttributeMappingsToApiModel)1 AddUserStorePropertiesRes (org.wso2.carbon.identity.api.server.userstore.v1.model.AddUserStorePropertiesRes)1 AvailableUserStoreClassesRes (org.wso2.carbon.identity.api.server.userstore.v1.model.AvailableUserStoreClassesRes)1 ConnectionEstablishedResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.ConnectionEstablishedResponse)1 PatchDocument (org.wso2.carbon.identity.api.server.userstore.v1.model.PatchDocument)1 UserStoreAttributeMappingResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreAttributeMappingResponse)1