Search in sources :

Example 1 with ConnectorRes

use of org.wso2.carbon.identity.api.server.identity.governance.v1.model.ConnectorRes in project identity-api-server by wso2.

the class ServerIdentityGovernanceService method getGovernanceConnector.

/**
 * Get governance connector.
 *
 * @param categoryId  Governance connector category id.
 * @param connectorId Governance connector id.
 * @return Governance connectors for the give id.
 */
public ConnectorRes getGovernanceConnector(String categoryId, String connectorId) {
    try {
        IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService();
        String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        String connectorName = new String(Base64.getUrlDecoder().decode(connectorId), StandardCharsets.UTF_8);
        ConnectorConfig connectorConfig = identityGovernanceService.getConnectorWithConfigs(tenantDomain, connectorName);
        if (connectorConfig == null) {
            throw handleNotFoundError(connectorId, GovernanceConstants.ErrorMessage.ERROR_CODE_CONNECTOR_NOT_FOUND);
        }
        String categoryIdFound = Base64.getUrlEncoder().withoutPadding().encodeToString(connectorConfig.getCategory().getBytes(StandardCharsets.UTF_8));
        if (!categoryId.equals(categoryIdFound)) {
            throw handleNotFoundError(connectorId, GovernanceConstants.ErrorMessage.ERROR_CODE_CONNECTOR_NOT_FOUND);
        }
        return buildConnectorResDTO(connectorConfig);
    } catch (IdentityGovernanceException e) {
        GovernanceConstants.ErrorMessage errorEnum = GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_CONNECTOR;
        Response.Status status = Response.Status.INTERNAL_SERVER_ERROR;
        throw handleException(e, errorEnum, status);
    }
}
Also used : ConnectorConfig(org.wso2.carbon.identity.governance.bean.ConnectorConfig) IdentityGovernanceService(org.wso2.carbon.identity.governance.IdentityGovernanceService) IdentityGovernanceException(org.wso2.carbon.identity.governance.IdentityGovernanceException)

Example 2 with ConnectorRes

use of org.wso2.carbon.identity.api.server.identity.governance.v1.model.ConnectorRes in project identity-api-server by wso2.

the class ServerIdentityGovernanceService method updateGovernanceConnectorProperty.

/**
 * Update governance connector property.
 *
 * @param categoryId          Governance connector category id.
 * @param connectorId         Governance connector id.
 * @param governanceConnector Connector property to update.
 */
public void updateGovernanceConnectorProperty(String categoryId, String connectorId, ConnectorsPatchReq governanceConnector) {
    try {
        IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService();
        String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        ConnectorRes connector = getGovernanceConnector(categoryId, connectorId);
        if (connector == null) {
            throw handleNotFoundError(connectorId, GovernanceConstants.ErrorMessage.ERROR_CODE_CONNECTOR_NOT_FOUND);
        }
        Map<String, String> configurationDetails = new HashMap<>();
        for (PropertyReq propertyReqDTO : governanceConnector.getProperties()) {
            configurationDetails.put(propertyReqDTO.getName(), propertyReqDTO.getValue());
        }
        identityGovernanceService.updateConfiguration(tenantDomain, configurationDetails);
    } catch (IdentityGovernanceException e) {
        GovernanceConstants.ErrorMessage errorEnum = GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_CONNECTOR_PROPERTY;
        Response.Status status = Response.Status.INTERNAL_SERVER_ERROR;
        throw handleException(e, errorEnum, status);
    }
}
Also used : ConnectorRes(org.wso2.carbon.identity.api.server.identity.governance.v1.model.ConnectorRes) HashMap(java.util.HashMap) IdentityGovernanceService(org.wso2.carbon.identity.governance.IdentityGovernanceService) PropertyReq(org.wso2.carbon.identity.api.server.identity.governance.v1.model.PropertyReq) IdentityGovernanceException(org.wso2.carbon.identity.governance.IdentityGovernanceException)

Example 3 with ConnectorRes

use of org.wso2.carbon.identity.api.server.identity.governance.v1.model.ConnectorRes in project identity-api-server by wso2.

the class ServerIdentityGovernanceService method getGovernanceConnectorsByCategory.

/**
 * Get governance connector category.
 *
 * @param categoryId Governance connector category id.
 * @return List of governance connectors for the give id.
 */
public List<ConnectorRes> getGovernanceConnectorsByCategory(String categoryId) {
    try {
        IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService();
        String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        String category = new String(Base64.getUrlDecoder().decode(categoryId), StandardCharsets.UTF_8);
        List<ConnectorConfig> connectorConfigs = identityGovernanceService.getConnectorListWithConfigsByCategory(tenantDomain, category);
        if (connectorConfigs.size() == 0) {
            throw handleNotFoundError(categoryId, GovernanceConstants.ErrorMessage.ERROR_CODE_CATEGORY_NOT_FOUND);
        }
        return buildConnectorsResDTOS(connectorConfigs);
    } catch (IdentityGovernanceException e) {
        GovernanceConstants.ErrorMessage errorEnum = GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_CATEGORY;
        Response.Status status = Response.Status.INTERNAL_SERVER_ERROR;
        throw handleException(e, errorEnum, status);
    }
}
Also used : ConnectorConfig(org.wso2.carbon.identity.governance.bean.ConnectorConfig) IdentityGovernanceService(org.wso2.carbon.identity.governance.IdentityGovernanceService) IdentityGovernanceException(org.wso2.carbon.identity.governance.IdentityGovernanceException)

Example 4 with ConnectorRes

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

the class IdentityGovernanceSuccessTest method testGetGovernanceConnector.

@Test
public void testGetGovernanceConnector() throws IOException {
    for (Map.Entry<String, CategoriesRes> category : categories.entrySet()) {
        String expectedResponse = readResource("get-category-" + category.getKey() + "-response.json");
        ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory());
        List<ConnectorRes> connectorsList = jsonWriter.readValue(expectedResponse, CategoryRes.class).getConnectors();
        Map<String, ConnectorRes> connectors = connectorsList.stream().collect(Collectors.toMap(ConnectorRes::getId, c -> c));
        for (Map.Entry<String, ConnectorRes> connector : connectors.entrySet()) {
            Response response = getResponseOfGet(IDENTITY_GOVERNANCE_ENDPOINT_URI + "/" + category.getKey() + "/connectors/" + connector.getKey());
            ValidatableResponse validatableResponse = response.then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_OK);
            validatableResponse.body("id", equalTo(connector.getKey())).body("name", equalTo(connector.getValue().getName())).body("category", equalTo(connector.getValue().getCategory())).body("friendlyName", equalTo(connector.getValue().getFriendlyName())).body("order", equalTo(connector.getValue().getOrder())).body("subCategory", equalTo(connector.getValue().getSubCategory()));
            Map<String, PropertyRes> properties = connector.getValue().getProperties().stream().collect(Collectors.toMap(PropertyRes::getName, c -> c));
            for (Map.Entry<String, PropertyRes> property : properties.entrySet()) {
                validatableResponse.body("properties.find{it.name == '" + property.getValue().getName() + "' }.displayName", equalTo(property.getValue().getDisplayName())).body("properties.find{it.name == '" + property.getValue().getName() + "' }.description", equalTo(property.getValue().getDescription()));
            }
        }
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) 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) PreferenceResp(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.PreferenceResp) ConnectorRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.ConnectorRes) AfterClass(org.testng.annotations.AfterClass) Factory(org.testng.annotations.Factory) PropertyRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.PropertyRes) BeforeClass(org.testng.annotations.BeforeClass) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeMethod(org.testng.annotations.BeforeMethod) TestUserMode(org.wso2.carbon.automation.engine.context.TestUserMode) CategoryRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.CategoryRes) PropertyReq(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.PropertyReq) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) List(java.util.List) JsonFactory(com.fasterxml.jackson.core.JsonFactory) Response(io.restassured.response.Response) CategoriesRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.CategoriesRes) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) RestAssured(io.restassured.RestAssured) ValidatableResponse(io.restassured.response.ValidatableResponse) JsonFactory(com.fasterxml.jackson.core.JsonFactory) CategoryRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.CategoryRes) ValidatableResponse(io.restassured.response.ValidatableResponse) Response(io.restassured.response.Response) ConnectorRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.ConnectorRes) CategoriesRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.CategoriesRes) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PropertyRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.PropertyRes) Test(org.testng.annotations.Test)

Example 5 with ConnectorRes

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

the class IdentityGovernanceSuccessTest method testGetGovernanceConnectorCategory.

@Test
public void testGetGovernanceConnectorCategory() throws IOException {
    for (Map.Entry<String, CategoriesRes> category : categories.entrySet()) {
        String expectedResponse = readResource("get-category-" + category.getKey() + "-response.json");
        ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory());
        List<ConnectorRes> connectorsList = jsonWriter.readValue(expectedResponse, CategoryRes.class).getConnectors();
        Map<String, ConnectorRes> connectors = connectorsList.stream().collect(Collectors.toMap(ConnectorRes::getId, c -> c));
        Response response = getResponseOfGet(IDENTITY_GOVERNANCE_ENDPOINT_URI + "/" + category.getKey());
        ValidatableResponse validatableResponse = response.then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_OK);
        for (Map.Entry<String, ConnectorRes> connector : connectors.entrySet()) {
            validatableResponse.body("connectors.find{ it.id == '" + connector.getKey() + "' }.name", equalTo(connector.getValue().getName())).body("connectors.find{ it.id == '" + connector.getKey() + "' }.category", equalTo(connector.getValue().getCategory())).body("connectors.find{ it.id == '" + connector.getKey() + "' }.friendlyName", equalTo(connector.getValue().getFriendlyName())).body("connectors.find{ it.id == '" + connector.getKey() + "' }.order", equalTo(connector.getValue().getOrder())).body("connectors.find{ it.id == '" + connector.getKey() + "' }.subCategory", equalTo(connector.getValue().getSubCategory()));
            Map<String, PropertyRes> properties = connector.getValue().getProperties().stream().collect(Collectors.toMap(PropertyRes::getName, c -> c));
            for (Map.Entry<String, PropertyRes> property : properties.entrySet()) {
                validatableResponse.body("connectors.find{ it.id == '" + connector.getKey() + "' }.properties.find{it.name " + "== '" + property.getValue().getName() + "' }.displayName", equalTo(property.getValue().getDisplayName())).body("connectors.find{ it.id == '" + connector.getKey() + "' }.properties.find{it.name " + "== '" + property.getValue().getName() + "' }.description", equalTo(property.getValue().getDescription()));
            }
        }
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) 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) PreferenceResp(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.PreferenceResp) ConnectorRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.ConnectorRes) AfterClass(org.testng.annotations.AfterClass) Factory(org.testng.annotations.Factory) PropertyRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.PropertyRes) BeforeClass(org.testng.annotations.BeforeClass) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeMethod(org.testng.annotations.BeforeMethod) TestUserMode(org.wso2.carbon.automation.engine.context.TestUserMode) CategoryRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.CategoryRes) PropertyReq(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.PropertyReq) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) List(java.util.List) JsonFactory(com.fasterxml.jackson.core.JsonFactory) Response(io.restassured.response.Response) CategoriesRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.CategoriesRes) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) RestAssured(io.restassured.RestAssured) ValidatableResponse(io.restassured.response.ValidatableResponse) JsonFactory(com.fasterxml.jackson.core.JsonFactory) CategoryRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.CategoryRes) ValidatableResponse(io.restassured.response.ValidatableResponse) Response(io.restassured.response.Response) ConnectorRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.ConnectorRes) CategoriesRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.CategoriesRes) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PropertyRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.PropertyRes) Test(org.testng.annotations.Test)

Aggregations

ConnectorRes (org.wso2.carbon.identity.api.server.identity.governance.v1.model.ConnectorRes)4 IdentityGovernanceException (org.wso2.carbon.identity.governance.IdentityGovernanceException)3 IdentityGovernanceService (org.wso2.carbon.identity.governance.IdentityGovernanceService)3 ConnectorConfig (org.wso2.carbon.identity.governance.bean.ConnectorConfig)3 JsonFactory (com.fasterxml.jackson.core.JsonFactory)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 RestAssured (io.restassured.RestAssured)2 Response (io.restassured.response.Response)2 ValidatableResponse (io.restassured.response.ValidatableResponse)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang.StringUtils)2 HttpStatus (org.apache.http.HttpStatus)2 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)2 IsNull.notNullValue (org.hamcrest.core.IsNull.notNullValue)2 AfterClass (org.testng.annotations.AfterClass)2