Search in sources :

Example 1 with IdentityGovernanceService

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;
}
Also used : PreferenceSearchAttribute(org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceSearchAttribute) ConnectorConfig(org.wso2.carbon.identity.governance.bean.ConnectorConfig) ArrayList(java.util.ArrayList) IdentityGovernanceException(org.wso2.carbon.identity.governance.IdentityGovernanceException) PreferenceResp(org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceResp) IdentityGovernanceService(org.wso2.carbon.identity.governance.IdentityGovernanceService) Property(org.wso2.carbon.identity.application.common.model.Property)

Example 2 with IdentityGovernanceService

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);
    }
}
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 3 with IdentityGovernanceService

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);
    }
}
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 4 with IdentityGovernanceService

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);
    }
}
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 5 with IdentityGovernanceService

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);
}
Also used : Property(org.wso2.carbon.identity.application.common.model.Property) CaptchaClientException(org.wso2.carbon.identity.captcha.exception.CaptchaClientException) CaptchaException(org.wso2.carbon.identity.captcha.exception.CaptchaException) IOException(java.io.IOException) CaptchaServerException(org.wso2.carbon.identity.captcha.exception.CaptchaServerException) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityGovernanceException(org.wso2.carbon.identity.governance.IdentityGovernanceException) AccountLockServiceException(org.wso2.carbon.identity.handler.event.account.lock.exception.AccountLockServiceException)

Aggregations

Property (org.wso2.carbon.identity.application.common.model.Property)13 IdentityGovernanceException (org.wso2.carbon.identity.governance.IdentityGovernanceException)13 IdentityGovernanceService (org.wso2.carbon.identity.governance.IdentityGovernanceService)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 CaptchaClientException (org.wso2.carbon.identity.captcha.exception.CaptchaClientException)4 CaptchaException (org.wso2.carbon.identity.captcha.exception.CaptchaException)4 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)3 ConnectorConfig (org.wso2.carbon.identity.governance.bean.ConnectorConfig)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Activate (org.osgi.service.component.annotations.Activate)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 List (java.util.List)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 BundleContext (org.osgi.framework.BundleContext)1 Test (org.testng.annotations.Test)1 PIIController (org.wso2.carbon.consent.mgt.core.connector.PIIController)1 ConnectorRes (org.wso2.carbon.identity.api.server.identity.governance.v1.model.ConnectorRes)1 PreferenceResp (org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceResp)1