Search in sources :

Example 1 with UserStoreConfigurationsRes

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

the class UserStoreSuccessTest method testGetSecondaryUserStoreByDomainId.

@Test(dependsOnMethods = { "testGetAvailableUserStoreClasses" })
public void testGetSecondaryUserStoreByDomainId() throws Exception {
    String expectedResponse = readResource("get-user-store_by_domain_id-response.json");
    ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory());
    List<UserStoreConfigurationsRes> availableUserStoreList = Collections.singletonList(jsonWriter.readValue(expectedResponse, UserStoreConfigurationsRes.class));
    Map<String, UserStoreConfigurationsRes> userStoreMetaResMap = availableUserStoreList.stream().collect(Collectors.toMap(UserStoreConfigurationsRes::getTypeId, c -> c));
    Response response = getResponseOfGet(USER_STORE_PATH_COMPONENT + PATH_SEPARATOR + domainId);
    ValidatableResponse validatableResponse = response.then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_OK);
    for (Map.Entry<String, UserStoreConfigurationsRes> resEntry : userStoreMetaResMap.entrySet()) {
        validatableResponse.body("typeName", equalTo(resEntry.getValue().getTypeName())).body("className", equalTo(resEntry.getValue().getClassName())).body("name", equalTo(resEntry.getValue().getName())).body("description", equalTo(resEntry.getValue().getDescription()));
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) UserStoreConfigAdminServiceClient(org.wso2.identity.integration.common.clients.user.store.config.UserStoreConfigAdminServiceClient) Arrays(java.util.Arrays) ValidatableResponse(io.restassured.response.ValidatableResponse) DataProvider(org.testng.annotations.DataProvider) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) HttpStatus(org.apache.http.HttpStatus) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) UserStoreConfigurationsRes(org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.UserStoreConfigurationsRes) HttpHeaders(org.apache.http.HttpHeaders) AfterClass(org.testng.annotations.AfterClass) UserStoreConfigUtils(org.wso2.identity.integration.common.utils.UserStoreConfigUtils) Factory(org.testng.annotations.Factory) BeforeClass(org.testng.annotations.BeforeClass) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeMethod(org.testng.annotations.BeforeMethod) TestUserMode(org.wso2.carbon.automation.engine.context.TestUserMode) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) AvailableUserStoreClassesRes(org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.AvailableUserStoreClassesRes) List(java.util.List) JsonFactory(com.fasterxml.jackson.core.JsonFactory) Response(io.restassured.response.Response) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) UserStoreListResponse(org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.UserStoreListResponse) RestAssured(io.restassured.RestAssured) Collections(java.util.Collections) ValidatableResponse(io.restassured.response.ValidatableResponse) Response(io.restassured.response.Response) UserStoreListResponse(org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.UserStoreListResponse) ValidatableResponse(io.restassured.response.ValidatableResponse) JsonFactory(com.fasterxml.jackson.core.JsonFactory) UserStoreConfigurationsRes(org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.UserStoreConfigurationsRes) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 2 with UserStoreConfigurationsRes

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

use of org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreConfigurationsRes 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)2 Map (java.util.Map)2 AddUserStorePropertiesRes (org.wso2.carbon.identity.api.server.userstore.v1.model.AddUserStorePropertiesRes)2 ClaimAttributeMapping (org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping)2 UserStoreConfigurationsRes (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreConfigurationsRes)2 UserStoreException (org.wso2.carbon.user.api.UserStoreException)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RestAssured (io.restassured.RestAssured)1 Response (io.restassured.response.Response)1 ValidatableResponse (io.restassured.response.ValidatableResponse)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang.StringUtils)1 HttpHeaders (org.apache.http.HttpHeaders)1