Search in sources :

Example 1 with ApplicationDAOImpl

use of org.wso2.carbon.identity.application.mgt.dao.impl.ApplicationDAOImpl in project carbon-apimgt by wso2.

the class DAOFactory method getApplicationDAO.

public static ApplicationDAO getApplicationDAO() throws APIMgtDAOException {
    ApplicationDAO appDAO = null;
    try (Connection connection = DAOUtil.getConnection()) {
        String driverName = connection.getMetaData().getDriverName();
        if (driverName.contains(MYSQL) || driverName.contains(H2)) {
            appDAO = new ApplicationDAOImpl();
        } else if (driverName.contains(DB2)) {
        } else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
            appDAO = new ApplicationDAOImpl();
        } else if (driverName.contains(POSTGRE)) {
            appDAO = new ApplicationDAOImpl();
        } else if (driverName.contains(ORACLE)) {
            appDAO = new ApplicationDAOImpl();
        } else {
            throw new APIMgtDAOException("Unhandled DB driver: " + driverName + " detected", ExceptionCodes.APIM_DAO_EXCEPTION);
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting ApplicationDAO", e);
    }
    setup();
    return appDAO;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO)

Example 2 with ApplicationDAOImpl

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

the class ApplicationMgtSystemConfig method getApplicationDAO.

/**
 * Return an instance of the ApplicationDAO
 *
 * @return
 */
public ApplicationDAO getApplicationDAO() {
    ApplicationDAO applicationDAO = null;
    if (appDAOClassName != null) {
        try {
            // Bundle class loader will cache the loaded class and returned
            // the already loaded instance, hence calling this method
            // multiple times doesn't cost.
            Class clazz = Class.forName(appDAOClassName);
            applicationDAO = (ApplicationDAO) clazz.newInstance();
        } catch (ClassNotFoundException e) {
            log.error("Error while instantiating the ApplicationDAO ", e);
        } catch (InstantiationException e) {
            log.error("Error while instantiating the ApplicationDAO ", e);
        } catch (IllegalAccessException e) {
            log.error("Error while instantiating the ApplicationDAO ", e);
        }
    } else {
        applicationDAO = new ApplicationDAOImpl();
    }
    return new CacheBackedApplicationDAO(applicationDAO);
}
Also used : CacheBackedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.CacheBackedApplicationDAO) CacheBackedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.CacheBackedApplicationDAO) SAMLApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.SAMLApplicationDAO) OAuthApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.OAuthApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) SAMLApplicationDAOImpl(org.wso2.carbon.identity.application.mgt.dao.impl.SAMLApplicationDAOImpl) ApplicationDAOImpl(org.wso2.carbon.identity.application.mgt.dao.impl.ApplicationDAOImpl) OAuthApplicationDAOImpl(org.wso2.carbon.identity.application.mgt.dao.impl.OAuthApplicationDAOImpl)

Example 3 with ApplicationDAOImpl

use of org.wso2.carbon.identity.application.mgt.dao.impl.ApplicationDAOImpl 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.identity.application.mgt.dao.ApplicationDAO)2 ApplicationDAOImpl (org.wso2.carbon.identity.application.mgt.dao.impl.ApplicationDAOImpl)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)1 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)1 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)1 OAuthApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.OAuthApplicationDAO)1 SAMLApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.SAMLApplicationDAO)1 CacheBackedApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.impl.CacheBackedApplicationDAO)1 OAuthApplicationDAOImpl (org.wso2.carbon.identity.application.mgt.dao.impl.OAuthApplicationDAOImpl)1 SAMLApplicationDAOImpl (org.wso2.carbon.identity.application.mgt.dao.impl.SAMLApplicationDAOImpl)1