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);
}
}
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);
}
}
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);
}
}
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()));
}
}
}
}
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()));
}
}
}
}
Aggregations