Search in sources :

Example 1 with ApplicationBasicInfo

use of org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo in project carbon-identity-framework by wso2.

the class CORSManagementServiceImpl method setCORSOrigins.

/**
 * {@inheritDoc}
 */
@Override
public void setCORSOrigins(String applicationId, List<String> origins, String tenantDomain) throws CORSManagementServiceException {
    int tenantId = getTenantId(tenantDomain);
    ApplicationBasicInfo applicationBasicInfo = getApplicationBasicInfo(applicationId, tenantDomain);
    // Check for duplicate entries.
    if (CORSConfigurationUtils.hasDuplicates(origins)) {
        throw handleClientException(ERROR_CODE_DUPLICATE_ORIGINS);
    }
    List<Origin> originList = CORSConfigurationUtils.createOriginList(origins);
    // Set the CORS origins.
    getCORSOriginDAO().setCORSOrigins(applicationBasicInfo.getApplicationId(), originList.stream().map(origin -> {
        // Create the CORS origin.
        CORSOrigin corsOrigin = new CORSOrigin();
        corsOrigin.setOrigin(origin.getValue());
        return corsOrigin;
    }).collect(Collectors.toList()), tenantId);
}
Also used : Origin(org.wso2.carbon.identity.cors.mgt.core.model.Origin) CORSOrigin(org.wso2.carbon.identity.cors.mgt.core.model.CORSOrigin) CORSOrigin(org.wso2.carbon.identity.cors.mgt.core.model.CORSOrigin) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)

Example 2 with ApplicationBasicInfo

use of org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo in project carbon-identity-framework by wso2.

the class CORSManagementServiceImpl method addCORSOrigins.

/**
 * {@inheritDoc}
 */
@Override
public void addCORSOrigins(String applicationId, List<String> origins, String tenantDomain) throws CORSManagementServiceException {
    int tenantId = getTenantId(tenantDomain);
    ApplicationBasicInfo applicationBasicInfo = getApplicationBasicInfo(applicationId, tenantDomain);
    List<Origin> originList = CORSConfigurationUtils.createOriginList(origins);
    // Check if the CORS origins are already present.
    List<CORSOrigin> existingCORSOrigins = getCORSOriginDAO().getCORSOriginsByApplicationId(applicationBasicInfo.getApplicationId(), tenantId);
    List<String> corsOriginIdList = existingCORSOrigins.stream().map(CORSOrigin::getId).collect(Collectors.toList());
    for (Origin origin : originList) {
        if (corsOriginIdList.contains(origin.getValue())) {
            // CORS origin is already registered for the application.
            if (log.isDebugEnabled()) {
                log.debug(String.format("Duplicate addition of existing CORS Origin (%s) for the " + "application id: %s, tenant domain: %s", origin, applicationId, tenantDomain));
            }
            throw handleClientException(ERROR_CODE_ORIGIN_PRESENT, tenantDomain, origin.getValue());
        }
    }
    // Add the CORS origins.
    getCORSOriginDAO().addCORSOrigins(applicationBasicInfo.getApplicationId(), originList.stream().map(origin -> {
        // Create the CORS origin.
        CORSOrigin corsOrigin = new CORSOrigin();
        corsOrigin.setOrigin(origin.getValue());
        return corsOrigin;
    }).collect(Collectors.toList()), tenantId);
}
Also used : Origin(org.wso2.carbon.identity.cors.mgt.core.model.Origin) CORSOrigin(org.wso2.carbon.identity.cors.mgt.core.model.CORSOrigin) CORSOrigin(org.wso2.carbon.identity.cors.mgt.core.model.CORSOrigin) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)

Example 3 with ApplicationBasicInfo

use of org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo in project carbon-identity-framework by wso2.

the class CORSManagementServiceImpl method getApplicationCORSOrigins.

/**
 * {@inheritDoc}
 */
@Override
public List<CORSOrigin> getApplicationCORSOrigins(String applicationId, String tenantDomain) throws CORSManagementServiceException {
    int tenantId = getTenantId(tenantDomain);
    ApplicationBasicInfo applicationBasicInfo = getApplicationBasicInfo(applicationId, tenantDomain);
    return Collections.unmodifiableList(getCORSOriginDAO().getCORSOriginsByApplicationId(applicationBasicInfo.getApplicationId(), tenantId));
}
Also used : ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)

Example 4 with ApplicationBasicInfo

use of org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method getApplicationBasicInfo.

@Override
public ApplicationBasicInfo[] getApplicationBasicInfo(int offset, int limit) throws IdentityApplicationManagementException {
    validateAttributesForPagination(offset, limit);
    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement getAppNamesStmt = null;
    ResultSet appNameResultSet = null;
    String sqlQuery;
    ArrayList<ApplicationBasicInfo> appInfo = new ArrayList<ApplicationBasicInfo>();
    try {
        String databaseProductName = connection.getMetaData().getDatabaseProductName();
        if (databaseProductName.contains("MySQL") || databaseProductName.contains("MariaDB") || databaseProductName.contains("H2")) {
            sqlQuery = LOAD_APP_NAMES_BY_TENANT_MYSQL;
            getAppNamesStmt = connection.prepareStatement(sqlQuery);
            populateListAppNamesQueryValues(tenantID, offset, limit, getAppNamesStmt);
        } else if (databaseProductName.contains("Oracle")) {
            sqlQuery = LOAD_APP_NAMES_BY_TENANT_ORACLE;
            getAppNamesStmt = connection.prepareStatement(sqlQuery);
            populateListAppNamesQueryValues(tenantID, offset + limit, offset, getAppNamesStmt);
        } else if (databaseProductName.contains("Microsoft")) {
            sqlQuery = LOAD_APP_NAMES_BY_TENANT_MSSQL;
            getAppNamesStmt = connection.prepareStatement(sqlQuery);
            populateListAppNamesQueryValues(tenantID, offset, limit, getAppNamesStmt);
        } else if (databaseProductName.contains("PostgreSQL")) {
            sqlQuery = LOAD_APP_NAMES_BY_TENANT_POSTGRESQL;
            getAppNamesStmt = connection.prepareStatement(sqlQuery);
            populateListAppNamesQueryValues(tenantID, limit, offset, getAppNamesStmt);
        } else if (databaseProductName.contains("DB2")) {
            sqlQuery = LOAD_APP_NAMES_BY_TENANT_DB2SQL;
            getAppNamesStmt = connection.prepareStatement(sqlQuery);
            populateListAppNamesQueryValues(tenantID, offset + 1, offset + limit, getAppNamesStmt);
        } else if (databaseProductName.contains("INFORMIX")) {
            sqlQuery = LOAD_APP_NAMES_BY_TENANT_INFORMIX;
            getAppNamesStmt = connection.prepareStatement(sqlQuery);
            getAppNamesStmt.setInt(1, offset);
            getAppNamesStmt.setInt(2, limit);
            getAppNamesStmt.setInt(3, tenantID);
            getAppNamesStmt.setString(4, LOCAL_SP);
        } else {
            log.error("Error while loading applications from DB: Database driver could not be identified or " + "not supported.");
            throw new IdentityApplicationManagementException("Error while loading applications from DB: " + "Database driver could not be identified or not supported.");
        }
        appNameResultSet = getAppNamesStmt.executeQuery();
        while (appNameResultSet.next()) {
            appInfo.add(buildApplicationBasicInfo(appNameResultSet));
        }
    } catch (SQLException e) {
        throw new IdentityApplicationManagementException("Error while loading applications from DB: " + e.getMessage(), e);
    } finally {
        IdentityApplicationManagementUtil.closeStatement(getAppNamesStmt);
        IdentityApplicationManagementUtil.closeResultSet(appNameResultSet);
        IdentityApplicationManagementUtil.closeConnection(connection);
    }
    return appInfo.toArray(new ApplicationBasicInfo[0]);
}
Also used : SQLException(java.sql.SQLException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)

Example 5 with ApplicationBasicInfo

use of org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method getDiscoverableApplicationBasicInfoByResourceId.

@Override
public ApplicationBasicInfo getDiscoverableApplicationBasicInfoByResourceId(String resourceId, String tenantDomain) throws IdentityApplicationManagementException {
    if (log.isDebugEnabled()) {
        log.debug("Getting application basic information for resourceId: " + resourceId + " in tenantDomain: " + tenantDomain + " if discoverable.");
    }
    ApplicationBasicInfo applicationBasicInfo = null;
    boolean isDiscoverable = false;
    try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
        try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, LOAD_APP_BY_TENANT_AND_UUID)) {
            statement.setInt(ApplicationTableColumns.TENANT_ID, IdentityTenantUtil.getTenantId(tenantDomain));
            statement.setString(ApplicationTableColumns.UUID, resourceId);
            try (ResultSet resultSet = statement.executeQuery()) {
                while (resultSet.next()) {
                    applicationBasicInfo = buildApplicationBasicInfo(resultSet);
                    isDiscoverable = getBooleanValue(resultSet.getString(ApplicationTableColumns.IS_DISCOVERABLE));
                }
            }
        }
    } catch (SQLException e) {
        throw new IdentityApplicationManagementServerException("Error while getting discoverable application " + "basic information for resourceId: " + resourceId + " in tenantDomain: " + tenantDomain, e);
    }
    if (applicationBasicInfo != null && !isDiscoverable) {
        throw new IdentityApplicationManagementClientException(APPLICATION_NOT_DISCOVERABLE.getCode(), "Requested application resource " + resourceId + " is not discoverable.");
    }
    return applicationBasicInfo;
}
Also used : NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IdentityApplicationManagementServerException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)

Aggregations

ApplicationBasicInfo (org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)31 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)9 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 SQLException (java.sql.SQLException)8 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)8 ArrayList (java.util.ArrayList)7 ApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO)7 PaginatableFilterableApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO)7 FileBasedApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)7 Test (org.testng.annotations.Test)5 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)5 PreparedStatement (java.sql.PreparedStatement)4 AbstractApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener)4 ApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener)4 ApplicationBasicInfoCacheEntry (org.wso2.carbon.identity.application.mgt.internal.cache.ApplicationBasicInfoCacheEntry)3 ApplicationResourceManagementListener (org.wso2.carbon.identity.application.mgt.listener.ApplicationResourceManagementListener)3 CORSOrigin (org.wso2.carbon.identity.cors.mgt.core.model.CORSOrigin)3 Entry (java.util.Map.Entry)2 IdentityApplicationManagementServerException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException)2