Search in sources :

Example 96 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-identity-framework by wso2.

the class DefaultApplicationValidator method validateInboundAuthKey.

/**
 * Validate whether the configured inbound authentication key is already being used by another application.
 *
 * @param inboundConfig Inbound authentication request configuration.
 * @param appId         Application ID.
 * @param tenantDomain  Application tenant domain.
 * @throws IdentityApplicationManagementException IdentityApplicationManagementException.
 */
private void validateInboundAuthKey(InboundAuthenticationRequestConfig inboundConfig, int appId, String tenantDomain) throws IdentityApplicationManagementException {
    if (inboundConfig == null) {
        return;
    }
    /*
         * We need to directly retrieve the application from DB since {@link ServiceProviderByInboundAuthCache} cache
         * can have inconsistent applications stored against the <inbound-auth-key, inbound-auth-type, tenant-domain>
         * cache key which is not unique.
         */
    ApplicationDAO applicationDAO = new ApplicationDAOImpl();
    String existingAppName = applicationDAO.getServiceProviderNameByClientId(inboundConfig.getInboundAuthKey(), inboundConfig.getInboundAuthType(), CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
    if (StringUtils.isBlank(existingAppName)) {
        if (log.isDebugEnabled()) {
            log.debug("Cannot find application name for the inbound auth key: " + inboundConfig.getInboundAuthKey() + " of inbound auth type: " + inboundConfig.getInboundAuthType());
        }
        return;
    }
    ServiceProvider existingApp = applicationDAO.getApplication(existingAppName, tenantDomain);
    if (existingApp != null && existingApp.getApplicationID() != appId) {
        String msg = "Inbound key: '" + inboundConfig.getInboundAuthKey() + "' of inbound auth type: '" + inboundConfig.getInboundAuthType() + "' is already configured for the application :'" + existingApp.getApplicationName() + "'";
        /*
             * Since this is a conflict scenario, we need to use a different error code. Hence throwing an
             * 'IdentityApplicationManagementClientException' here with the correct error code.
             */
        throw buildClientException(IdentityApplicationConstants.Error.INBOUND_KEY_ALREADY_EXISTS, msg);
    }
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) ApplicationDAOImpl(org.wso2.carbon.identity.application.mgt.dao.impl.ApplicationDAOImpl)

Aggregations

ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)62 Test (org.testng.annotations.Test)59 Application (org.wso2.carbon.apimgt.core.models.Application)50 BeforeTest (org.testng.annotations.BeforeTest)33 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)32 ApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO)31 PaginatableFilterableApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO)25 FileBasedApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)25 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)21 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)18 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)18 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)15 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)15 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)13 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)13 AbstractApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener)13 ApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener)13 API (org.wso2.carbon.apimgt.core.models.API)12 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)11 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)10