Search in sources :

Example 21 with UserStoreDTO

use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO 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 22 with UserStoreDTO

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

the class ServerUserStoreService method buildResponseForPatchReplace.

/**
 * Construct the response for patch replace.
 *
 * @param userStoreDTO {@link UserStoreDTO}.
 * @param propertyDTOS array of {@link PropertyDTO}.
 * @return UserStoreResponse.
 */
private UserStoreResponse buildResponseForPatchReplace(UserStoreDTO userStoreDTO, PropertyDTO[] propertyDTOS) {
    UserStoreResponse userStoreResponseDTO = new UserStoreResponse();
    userStoreResponseDTO.setId((base64URLEncodeId(userStoreDTO.getDomainId())));
    userStoreResponseDTO.setName(userStoreDTO.getDomainId());
    userStoreResponseDTO.setTypeId(base64URLEncodeId(Objects.requireNonNull(getUserStoreTypeName(userStoreDTO.getClassName()))));
    userStoreResponseDTO.setTypeName(getUserStoreTypeName(userStoreDTO.getClassName()));
    userStoreResponseDTO.setDescription(userStoreDTO.getDescription());
    userStoreResponseDTO.setProperties(patchUserStoreProperties(propertyDTOS));
    return userStoreResponseDTO;
}
Also used : UserStoreResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse)

Example 23 with UserStoreDTO

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

the class ServerUserStoreService method createUserStoreDTO.

/**
 * To create UserStoreDTO object for this request.
 *
 * @param userStoreReq {@link UserStoreReq}.
 * @return UserStoreDTO.
 */
private UserStoreDTO createUserStoreDTO(UserStoreReq userStoreReq) {
    UserStoreDTO userStoreDTO = new UserStoreDTO();
    userStoreDTO.setDomainId(userStoreReq.getName());
    userStoreDTO.setClassName(getUserStoreType(base64URLDecodeId(userStoreReq.getTypeId())));
    userStoreDTO.setDescription(userStoreReq.getDescription());
    userStoreDTO.setProperties(createPropertyListDTO(userStoreReq));
    return userStoreDTO;
}
Also used : UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)

Example 24 with UserStoreDTO

use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO 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 25 with UserStoreDTO

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

the class ServerUserStoreService method addUserstoreProperties.

/**
 * Add requested user store properties to the response.
 *
 * @param userStoreDTO            userStoreDTO object.
 * @param userStoreListResponse   userStoreListResponse object.
 * @param requestedAttributesList Requested user store properties name list.
 */
private void addUserstoreProperties(UserStoreDTO userStoreDTO, UserStoreListResponse userStoreListResponse, List<String> requestedAttributesList) {
    for (PropertyDTO propertyDTO : userStoreDTO.getProperties()) {
        if (requestedAttributesList.contains(propertyDTO.getName()) && StringUtils.isNotBlank(propertyDTO.getValue())) {
            AddUserStorePropertiesRes addUserStorePropertiesRes = new AddUserStorePropertiesRes();
            addUserStorePropertiesRes.setName(propertyDTO.getName());
            addUserStorePropertiesRes.setValue(propertyDTO.getValue());
            userStoreListResponse.addPropertiesItem(addUserStorePropertiesRes);
        }
    }
}
Also used : AddUserStorePropertiesRes(org.wso2.carbon.identity.api.server.userstore.v1.model.AddUserStorePropertiesRes) PropertyDTO(org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO)

Aggregations

UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)21 UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO)14 IdentityUserStoreMgtException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException)13 UserStoreException (org.wso2.carbon.user.api.UserStoreException)11 ArrayList (java.util.ArrayList)9 AbstractUserStoreDAOFactory (org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory)8 Test (org.testng.annotations.Test)7 PropertyDTO (org.wso2.carbon.identity.user.store.configuration.stub.dto.PropertyDTO)7 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)7 UserStorePersistanceDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStorePersistanceDTO)6 IdentityUserStoreClientException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException)6 PropertyDTO (org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO)5 File (java.io.File)4 UserStoreConfigService (org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)4 UserStoreConfigListener (org.wso2.carbon.identity.user.store.configuration.listener.UserStoreConfigListener)4 SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException (org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException)4 UserStoreClientException (org.wso2.carbon.user.api.UserStoreClientException)4 H2DataBaseManager (org.wso2.carbon.automation.test.utils.dbutils.H2DataBaseManager)3 MaskedProperty (org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty)3 Property (org.wso2.carbon.user.api.Property)3