Search in sources :

Example 1 with UserStoreListResponse

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

the class UserStoreSuccessTest method testGetUserStore.

@Test(dependsOnMethods = { "testGetSecondaryUserStoreByDomainId" })
public void testGetUserStore() throws IOException {
    String expectedResponse = readResource("get-user-store-response.json");
    ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory());
    List<UserStoreListResponse> userStoreListResponseList = Arrays.asList(jsonWriter.readValue(expectedResponse, UserStoreListResponse[].class));
    Map<String, UserStoreListResponse> userStoreListResMap = userStoreListResponseList.stream().collect(Collectors.toMap(UserStoreListResponse::getId, c -> c));
    Response response = getResponseOfGet(USER_STORE_PATH_COMPONENT);
    ValidatableResponse validatableResponse = response.then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_OK);
    for (Map.Entry<String, UserStoreListResponse> resEntry : userStoreListResMap.entrySet()) {
        validatableResponse.body("find{ it.id == '" + resEntry.getKey() + "' }.name", equalTo(resEntry.getValue().getName()));
        validatableResponse.body("find{ it.id == '" + resEntry.getKey() + "' }.description", equalTo(resEntry.getValue().getDescription()));
        validatableResponse.body("find{ it.id == '" + resEntry.getKey() + "' }.self", equalTo("/t/" + tenant + "/api/server/v1" + USER_STORE_PATH_COMPONENT + PATH_SEPARATOR + resEntry.getValue().getId()));
    }
}
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) UserStoreListResponse(org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.UserStoreListResponse) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 2 with UserStoreListResponse

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

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

Example 4 with UserStoreListResponse

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

the class ServerUserStoreService method buildUserStoreListResponse.

/**
 * Construct response list with configured user stores details.
 *
 * @param userStoreDTOS array of UserStoreDTO object.
 * @return List<UserStoreListResponse>.
 */
private List<UserStoreListResponse> buildUserStoreListResponse(UserStoreDTO[] userStoreDTOS, String requiredAttributes) {
    List<UserStoreListResponse> userStoreListResponseToAdd = new ArrayList<>();
    Map<String, Boolean> userStoreManagersType = UserStoreManagerRegistry.getUserStoreManagersType();
    if (ArrayUtils.isNotEmpty(userStoreDTOS)) {
        for (UserStoreDTO jsonObject : userStoreDTOS) {
            UserStoreListResponse userStoreList = new UserStoreListResponse();
            userStoreList.setDescription(jsonObject.getDescription());
            userStoreList.setName(jsonObject.getDomainId());
            userStoreList.setId(base64URLEncodeId(jsonObject.getDomainId()));
            userStoreList.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + UserStoreConstants.USER_STORE_PATH_COMPONENT + "/%s", base64URLEncodeId(jsonObject.getDomainId()))).toString());
            userStoreList.setEnabled(jsonObject.getDisabled() != null && !jsonObject.getDisabled());
            userStoreList.setTypeName(getUserStoreTypeName(jsonObject.getClassName()));
            if (StringUtils.isNotBlank(requiredAttributes)) {
                String[] requiredAttributesArray = requiredAttributes.split(REGEX_COMMA);
                addUserstoreProperties(jsonObject, userStoreList, Arrays.asList(requiredAttributesArray));
            }
            if (userStoreManagersType.containsKey(jsonObject.getClassName())) {
                userStoreList.setIsLocal(userStoreManagersType.get(jsonObject.getClassName()));
            }
            userStoreListResponseToAdd.add(userStoreList);
        }
    }
    return userStoreListResponseToAdd;
}
Also used : UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) ArrayList(java.util.ArrayList) UserStoreListResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreListResponse)

Aggregations

UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)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 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang.StringUtils)1 HttpHeaders (org.apache.http.HttpHeaders)1 HttpStatus (org.apache.http.HttpStatus)1 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)1 IsNull.notNullValue (org.hamcrest.core.IsNull.notNullValue)1 AfterClass (org.testng.annotations.AfterClass)1