Search in sources :

Example 1 with UserStoreResponse

use of org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse 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 2 with UserStoreResponse

use of org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse 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 UserStoreResponse

use of org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse 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 UserStoreResponse

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

the class ServerUserStoreService method buildUserStoreResponseDTO.

/**
 * To create UserStoreResponse object for the put request.
 *
 * @param userStoreReq {@link UserStoreReq}.
 * @return UserStoreResponse.
 */
private UserStoreResponse buildUserStoreResponseDTO(UserStoreReq userStoreReq) {
    UserStoreResponse userStoreResponseDTO = new UserStoreResponse();
    userStoreResponseDTO.setId((base64URLEncodeId(userStoreReq.getName())));
    userStoreResponseDTO.setName(userStoreReq.getName());
    userStoreResponseDTO.setTypeId(userStoreReq.getTypeId());
    userStoreResponseDTO.setTypeName(base64URLDecodeId(userStoreReq.getTypeId()));
    userStoreResponseDTO.setDescription(userStoreReq.getDescription());
    userStoreResponseDTO.setProperties(buildUserStorePropertiesRes(userStoreReq));
    userStoreResponseDTO.setClaimAttributeMappings(userStoreReq.getClaimAttributeMappings());
    return userStoreResponseDTO;
}
Also used : UserStoreResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse)

Aggregations

ArrayList (java.util.ArrayList)2 ClaimAttributeMapping (org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping)2 UserStoreResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse)2 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)2 UserStoreConfigService (org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)2 IdentityUserStoreMgtException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException)2 UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)1