use of org.wso2.carbon.identity.governance.IdentityGovernanceService in project identity-api-server by wso2.
the class ServerIdentityGovernanceService method getConfigPreference.
/**
* Get governance connector properties according to the search attribute.
*
* @param preferenceSearchAttribute Governance connector details.
* @return Governance connector properties for the given connector or properties.
*/
public List<PreferenceResp> getConfigPreference(List<PreferenceSearchAttribute> preferenceSearchAttribute) {
IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService();
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
List<PreferenceResp> preferenceRespList = new ArrayList<>();
for (PreferenceSearchAttribute prefSearchAttr : preferenceSearchAttribute) {
String connectorName = prefSearchAttr.getConnectorName();
List<String> expectedProperties = prefSearchAttr.getProperties();
Property[] properties;
try {
ConnectorConfig connectorConfig = identityGovernanceService.getConnectorWithConfigs(tenantDomain, connectorName);
if (connectorConfig == null) {
throw handleBadRequestError(GovernanceConstants.ErrorMessage.ERROR_CODE_INCORRECT_CONNECTOR_NAME, connectorName);
}
properties = connectorConfig.getProperties();
PreferenceResp preferenceResp = buildPreferenceRespDTO(connectorName, properties, expectedProperties);
preferenceRespList.add(preferenceResp);
} catch (IdentityGovernanceException e) {
GovernanceConstants.ErrorMessage errorEnum = GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_CONNECTOR_PREFERENCES;
Response.Status status = Response.Status.INTERNAL_SERVER_ERROR;
throw handleException(e, errorEnum, status);
}
}
return preferenceRespList;
}
use of org.wso2.carbon.identity.governance.IdentityGovernanceService 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.governance.IdentityGovernanceService 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.governance.IdentityGovernanceService 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.governance.IdentityGovernanceService in project identity-governance by wso2-extensions.
the class PasswordRecoveryReCaptchaConnector method checkReCaptchaEnabledForForgotPassoword.
/**
* Check ReCaptcha configuration in management console for password recovery.
*
* @param servletRequest
* @param propertyName
* @return
*/
private boolean checkReCaptchaEnabledForForgotPassoword(ServletRequest servletRequest, String propertyName) {
Property[] connectorConfigs;
try {
connectorConfigs = CaptchaUtil.getConnectorConfigs(servletRequest, identityGovernanceService, propertyName);
} catch (Exception e) {
// Can happen due to invalid tenant/ invalid configuration
if (log.isDebugEnabled()) {
log.debug("Unable to load connector configuration.", e);
}
return false;
}
String enable = null;
for (Property connectorConfig : connectorConfigs) {
if ((propertyName).equals(connectorConfig.getName())) {
enable = connectorConfig.getValue();
}
}
return Boolean.parseBoolean(enable);
}
Aggregations