Search in sources :

Example 6 with UserStoreConfigService

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

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

the class ServerUserStoreService method getAvailableUserStoreTypes.

/**
 * To retrieve the available user store classes.
 *
 * @return List<AvailableUserStoreClassesRes>.
 */
public List<AvailableUserStoreClassesRes> getAvailableUserStoreTypes() {
    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
    Set<String> classNames;
    try {
        classNames = userStoreConfigService.getAvailableUserStoreClasses();
        List<AvailableUserStoreClassesRes> propertiesToAdd = new ArrayList<>();
        Map<String, Boolean> userStoreManagersType = UserStoreManagerRegistry.getUserStoreManagersType();
        for (String className : classNames) {
            AvailableUserStoreClassesRes availableUserStoreClassesResDTO = new AvailableUserStoreClassesRes();
            String typeId = base64URLEncodeId(Objects.requireNonNull(getUserStoreTypeName(className)));
            availableUserStoreClassesResDTO.setClassName(className);
            availableUserStoreClassesResDTO.setTypeName(getUserStoreTypeName(className));
            availableUserStoreClassesResDTO.setTypeId(typeId);
            availableUserStoreClassesResDTO.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + UserStoreConstants.USER_STORE_PATH_COMPONENT + "/meta/types/%s", typeId)).toString());
            if (userStoreManagersType.containsKey(className)) {
                availableUserStoreClassesResDTO.setIsLocal(userStoreManagersType.get(className));
            }
            propertiesToAdd.add(availableUserStoreClassesResDTO);
        }
        return propertiesToAdd;
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_RETRIEVING_USER_STORE_TYPE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) AvailableUserStoreClassesRes(org.wso2.carbon.identity.api.server.userstore.v1.model.AvailableUserStoreClassesRes) ArrayList(java.util.ArrayList) UserStoreConfigService(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)

Example 8 with UserStoreConfigService

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

the class UserStoreConfigComponent method activate.

/**
 * @param ctxt
 */
@Activate
protected void activate(ComponentContext ctxt) {
    if (log.isDebugEnabled()) {
        log.debug("Identity User Store bundle is activated.");
    }
    try {
        BundleContext bundleContext = ctxt.getBundleContext();
        AbstractUserStoreDAOFactory fileBasedUserStoreDAOFactory = new FileBasedUserStoreDAOFactory();
        AbstractUserStoreDAOFactory databaseBasedUserStoreDAOFactory = new DatabaseBasedUserStoreDAOFactory();
        ServiceRegistration serviceRegistration = bundleContext.registerService(AbstractUserStoreDAOFactory.class.getName(), fileBasedUserStoreDAOFactory, null);
        bundleContext.registerService(AbstractUserStoreDAOFactory.class.getName(), databaseBasedUserStoreDAOFactory, null);
        UserStoreConfigService userStoreConfigService = new UserStoreConfigServiceImpl();
        ctxt.getBundleContext().registerService(UserStoreConfigService.class.getName(), userStoreConfigService, null);
        UserStoreConfigListenersHolder.getInstance().setUserStoreConfigService(userStoreConfigService);
        UserStoreHashProviderConfigListenerImpl userStoreHashProviderListener = new UserStoreHashProviderConfigListenerImpl();
        ctxt.getBundleContext().registerService(UserStoreConfigListener.class.getName(), userStoreHashProviderListener, null);
        UserStoreConfigListenersHolder.getInstance().setUserStoreConfigListenerService(userStoreHashProviderListener);
        if (serviceRegistration != null) {
            if (log.isDebugEnabled()) {
                log.debug("FileBasedUserStoreDAOFactory is successfully registered.");
            }
        } else {
            log.error("FileBasedUserStoreDAOFactory could not be registered.");
        }
        readAllowedUserstoreConfiguration();
        readUserStoreAttributeMappingConfigs();
    } catch (Throwable e) {
        log.error("Failed to load user store org.wso2.carbon.identity.user.store.configuration details.", e);
    }
    if (log.isDebugEnabled()) {
        log.debug("Identity User Store-Config bundle is activated.");
    }
}
Also used : AbstractUserStoreDAOFactory(org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory) UserStoreHashProviderConfigListenerImpl(org.wso2.carbon.identity.user.store.configuration.listener.UserStoreHashProviderConfigListenerImpl) UserStoreConfigServiceImpl(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigServiceImpl) UserStoreConfigListener(org.wso2.carbon.identity.user.store.configuration.listener.UserStoreConfigListener) FileBasedUserStoreDAOFactory(org.wso2.carbon.identity.user.store.configuration.dao.impl.FileBasedUserStoreDAOFactory) UserStoreConfigService(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService) DatabaseBasedUserStoreDAOFactory(org.wso2.carbon.identity.user.store.configuration.dao.impl.DatabaseBasedUserStoreDAOFactory) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration) Activate(org.osgi.service.component.annotations.Activate)

Example 9 with UserStoreConfigService

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

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

the class ServerUserStoreService method buildUserStoreForPatch.

private UserStoreDTO buildUserStoreForPatch(String domainId, List<PatchDocument> patchDocuments) {
    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
    UserStoreDTO userStoreDTO;
    try {
        userStoreDTO = userStoreConfigService.getUserStore(base64URLDecodeId(domainId));
        if (userStoreDTO == null) {
            throw handleException(Response.Status.NOT_FOUND, UserStoreConstants.ErrorMessage.ERROR_CODE_NOT_FOUND);
        }
        PropertyDTO[] propertyDTOS = userStoreDTO.getProperties();
        for (PatchDocument patchDocument : patchDocuments) {
            String path = patchDocument.getPath();
            String value = patchDocument.getValue();
            if (StringUtils.isBlank(path)) {
                throw handleException(Response.Status.BAD_REQUEST, UserStoreConstants.ErrorMessage.ERROR_CODE_INVALID_INPUT);
            }
            if (path.startsWith(UserStoreConstants.USER_STORE_PROPERTIES)) {
                String propName = extractPropertyName(path);
                if (StringUtils.isNotEmpty(propName)) {
                    for (PropertyDTO propertyDTO : propertyDTOS) {
                        if (propName.equals(propertyDTO.getName())) {
                            propertyDTO.setValue(value);
                        }
                    }
                }
            } else if (path.equals(UserStoreConstants.USER_STORE_DESCRIPTION)) {
                userStoreDTO.setDescription(value);
            } else {
                throw handleException(Response.Status.BAD_REQUEST, UserStoreConstants.ErrorMessage.ERROR_CODE_INVALID_INPUT);
            }
        }
        userStoreDTO.setProperties(propertyDTOS);
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_USER_STORE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
    return userStoreDTO;
}
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) PropertyDTO(org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO) PatchDocument(org.wso2.carbon.identity.api.server.userstore.v1.model.PatchDocument)

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