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);
}
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);
}
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));
}
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]);
}
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;
}
Aggregations