Search in sources :

Example 1 with ApplicationListResponse

use of org.wso2.carbon.identity.api.server.application.management.v1.ApplicationListResponse in project product-is by wso2.

the class ApplicationManagementSuccessTest method testGetAllApplications.

@Test
public void testGetAllApplications() throws IOException {
    Response response = getResponseOfGet(APPLICATION_MANAGEMENT_API_BASE_PATH);
    response.then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_OK);
    ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory());
    ApplicationListResponse listResponse = jsonWriter.readValue(response.asString(), ApplicationListResponse.class);
    assertNotNull(listResponse);
    Assert.assertFalse(listResponse.getApplications().stream().anyMatch(appBasicInfo -> appBasicInfo.getName().equals(ApplicationConstants.LOCAL_SP)), "Default resident service provider '" + ApplicationConstants.LOCAL_SP + "' is listed by the API");
    if (StringUtils.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, tenant)) {
        // Check whether the default "My Account" app exists.
        Assert.assertTrue(listResponse.getApplications().stream().anyMatch(appBasicInfo -> appBasicInfo.getName().equals(MY_ACCOUNT)), "Default application 'My Account' is not listed by the API.");
    }
}
Also used : Response(io.restassured.response.Response) ApplicationListResponse(org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationListResponse) ApplicationListResponse(org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationListResponse) StringUtils(org.apache.commons.lang.StringUtils) MultitenantConstants(org.wso2.carbon.utils.multitenancy.MultitenantConstants) Factory(org.testng.annotations.Factory) URLUtils(com.nimbusds.oauth2.sdk.util.URLUtils) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TestUserMode(org.wso2.carbon.automation.engine.context.TestUserMode) HttpStatus(org.apache.http.HttpStatus) Test(org.testng.annotations.Test) IOException(java.io.IOException) HashMap(java.util.HashMap) Assert.assertNotNull(org.testng.Assert.assertNotNull) ApplicationConstants(org.wso2.carbon.identity.application.mgt.ApplicationConstants) URLEncoder(java.net.URLEncoder) JsonFactory(com.fasterxml.jackson.core.JsonFactory) Assert(org.testng.Assert) Response(io.restassured.response.Response) Map(java.util.Map) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) Is.is(org.hamcrest.core.Is.is) ApplicationListResponse(org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationListResponse) Utils.assertNotBlank(org.wso2.identity.integration.test.rest.api.server.application.management.v1.Utils.assertNotBlank) HttpHeaders(org.apache.http.HttpHeaders) Utils.extractApplicationIdFromLocationHeader(org.wso2.identity.integration.test.rest.api.server.application.management.v1.Utils.extractApplicationIdFromLocationHeader) JsonFactory(com.fasterxml.jackson.core.JsonFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 2 with ApplicationListResponse

use of org.wso2.carbon.identity.api.server.application.management.v1.ApplicationListResponse in project identity-api-server by wso2.

the class ServerApplicationManagementService method getAllApplications.

public ApplicationListResponse getAllApplications(Integer limit, Integer offset, String filter, String sortOrder, String sortBy, String requiredAttributes) {
    handleNotImplementedCapabilities(sortOrder, sortBy, requiredAttributes);
    String tenantDomain = ContextLoader.getTenantDomainFromContext();
    boolean isEqualFilterUsed = false;
    limit = validateAndGetLimit(limit);
    offset = validateAndGetOffset(offset);
    // Format the filter to a value that can be interpreted by the backend.
    ExpressionNode expressionNode = buildFilterNode(filter);
    String formattedFilter = null;
    if (expressionNode != null) {
        // Handle eq operation as special case, there will be only one application with a given name in tenant.
        if (isEqualOperation(expressionNode)) {
            isEqualFilterUsed = true;
        }
        formattedFilter = generateFilterStringForBackend(expressionNode.getAttributeValue(), expressionNode.getOperation(), expressionNode.getValue());
    }
    String username = ContextLoader.getUsernameFromContext();
    try {
        int totalResults = getApplicationManagementService().getCountOfApplications(tenantDomain, username, formattedFilter);
        ApplicationBasicInfo[] filteredAppList;
        if (isEqualFilterUsed) {
            ApplicationBasicInfo applicationBasicInfo = getApplicationManagementService().getApplicationBasicInfoByName(expressionNode.getValue(), tenantDomain);
            if (applicationBasicInfo == null) {
                filteredAppList = new ApplicationBasicInfo[0];
            } else {
                filteredAppList = new ApplicationBasicInfo[] { applicationBasicInfo };
            }
        } else {
            filteredAppList = getApplicationManagementService().getApplicationBasicInfo(tenantDomain, username, formattedFilter, offset, limit);
        }
        int resultsInCurrentPage = filteredAppList.length;
        return new ApplicationListResponse().totalResults(totalResults).startIndex(offset + 1).count(resultsInCurrentPage).applications(getApplicationListItems(filteredAppList)).links(Util.buildPaginationLinks(limit, offset, totalResults, APPLICATION_MANAGEMENT_PATH_COMPONENT).entrySet().stream().map(link -> new Link().rel(link.getKey()).href(link.getValue())).collect(Collectors.toList()));
    } catch (IdentityApplicationManagementException e) {
        String msg = "Error listing applications of tenantDomain: " + tenantDomain;
        throw handleIdentityApplicationManagementException(e, msg);
    }
}
Also used : ApplicationListResponse(org.wso2.carbon.identity.api.server.application.management.v1.ApplicationListResponse) ExpressionNode(org.wso2.carbon.identity.core.model.ExpressionNode) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo) Link(org.wso2.carbon.identity.api.server.application.management.v1.Link)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 URLUtils (com.nimbusds.oauth2.sdk.util.URLUtils)1 Response (io.restassured.response.Response)1 IOException (java.io.IOException)1 URLEncoder (java.net.URLEncoder)1 HashMap (java.util.HashMap)1 Map (java.util.Map)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 Is.is (org.hamcrest.core.Is.is)1 IsNull.notNullValue (org.hamcrest.core.IsNull.notNullValue)1 Assert (org.testng.Assert)1 Assert.assertNotNull (org.testng.Assert.assertNotNull)1 Factory (org.testng.annotations.Factory)1 Test (org.testng.annotations.Test)1 TestUserMode (org.wso2.carbon.automation.engine.context.TestUserMode)1 ApplicationListResponse (org.wso2.carbon.identity.api.server.application.management.v1.ApplicationListResponse)1