use of org.wso2.carbon.identity.cors.mgt.core.model.CORSApplication in project carbon-identity-framework by wso2.
the class CORSOriginDAOImpl method getCORSOriginApplications.
/**
* {@inheritDoc}
*/
@Override
public List<CORSApplication> getCORSOriginApplications(String corsOriginId) throws CORSManagementServiceServerException {
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false);
NamedPreparedStatement namedPreparedStatement = new NamedPreparedStatement(connection, GET_CORS_APPLICATIONS_BY_CORS_ORIGIN_ID)) {
namedPreparedStatement.setString(1, corsOriginId);
try (ResultSet resultSet = namedPreparedStatement.executeQuery()) {
List<CORSApplication> corsApplications = new ArrayList<>();
while (resultSet.next()) {
CORSApplication corsApplication = new CORSApplication(resultSet.getString(UNIQUE_ID), resultSet.getString("APP_NAME"));
corsApplications.add(corsApplication);
}
return corsApplications;
}
} catch (SQLException e) {
throw handleServerException(ERROR_CODE_CORS_APPLICATIONS_RETRIEVE, e, String.valueOf(corsOriginId));
}
}
use of org.wso2.carbon.identity.cors.mgt.core.model.CORSApplication in project carbon-identity-framework by wso2.
the class CORSManagementServiceTests method testGetCORSApplicationsByCORSOriginId.
@Test
public void testGetCORSApplicationsByCORSOriginId() throws CORSManagementServiceException {
String originUUID = UUID.randomUUID().toString();
try (Connection connection = IdentityDatabaseUtil.getDBConnection(true)) {
try {
// Add the application.
try (PreparedStatement preparedStatement1 = connection.prepareStatement(INSERT_APPLICATION)) {
// Add application 1.
preparedStatement1.setInt(1, SampleApp1.ID);
preparedStatement1.setInt(2, SampleTenant.ID);
preparedStatement1.setString(3, SampleApp1.NAME);
preparedStatement1.setString(4, SampleApp1.UUID);
preparedStatement1.executeUpdate();
}
// Add the application.
try (PreparedStatement preparedStatement2 = connection.prepareStatement(INSERT_APPLICATION)) {
// Add application 2.
preparedStatement2.setInt(1, SampleApp2.ID);
preparedStatement2.setInt(2, SampleApp2.ID);
preparedStatement2.setString(3, SampleApp2.NAME);
preparedStatement2.setString(4, SampleApp2.UUID);
preparedStatement2.executeUpdate();
}
String origin = SAMPLE_ORIGIN_LIST_1.get(0);
try (NamedPreparedStatement namedPreparedStatement = new NamedPreparedStatement(connection, INSERT_CORS_ORIGIN)) {
// Origin is not present. Therefore add an origin.
namedPreparedStatement.setInt(1, SampleTenant.ID);
namedPreparedStatement.setString(2, origin);
namedPreparedStatement.setString(3, originUUID);
namedPreparedStatement.executeUpdate();
// Get origin id.
int corsOriginId;
try (ResultSet resultSet = namedPreparedStatement.getGeneratedKeys()) {
if (resultSet.next()) {
corsOriginId = resultSet.getInt(1);
} else {
IdentityDatabaseUtil.rollbackTransaction(connection);
throw handleServerException(ERROR_CODE_CORS_ADD, SampleTenant.DOMAIN_NAME);
}
}
try (PreparedStatement preparedStatement4 = connection.prepareStatement(INSERT_CORS_ASSOCIATION)) {
// Add application associations.
preparedStatement4.setInt(1, corsOriginId);
preparedStatement4.setInt(2, SampleApp1.ID);
preparedStatement4.executeUpdate();
}
try (PreparedStatement preparedStatement5 = connection.prepareStatement(INSERT_CORS_ASSOCIATION)) {
// Add application associations.
preparedStatement5.setInt(1, corsOriginId);
preparedStatement5.setInt(2, SampleApp2.ID);
preparedStatement5.executeUpdate();
}
}
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
throw handleServerException(ERROR_CODE_CORS_ADD, e, IdentityTenantUtil.getTenantDomain(SampleTenant.ID));
}
IdentityDatabaseUtil.commitTransaction(connection);
} catch (SQLException e) {
throw handleServerException(ERROR_CODE_CORS_ADD, e, SampleTenant.DOMAIN_NAME);
}
List<String> retrievedCORSOriginApplicationIds = corsManagementService.getCORSApplicationsByCORSOriginId(originUUID, SampleTenant.DOMAIN_NAME).stream().map(CORSApplication::getId).collect(Collectors.toList());
List<String> expectedApplicationIds = new ArrayList<>();
expectedApplicationIds.add(SampleApp1.UUID);
expectedApplicationIds.add(SampleApp2.UUID);
assertEquals(retrievedCORSOriginApplicationIds, expectedApplicationIds);
}
use of org.wso2.carbon.identity.cors.mgt.core.model.CORSApplication in project identity-api-server by wso2.
the class CORSApplicationToCORSApplicationObject method apply.
@Override
public CORSApplicationObject apply(CORSApplication corsApplication) {
CORSApplicationObject corsApplicationObject = new CORSApplicationObject();
corsApplicationObject.setId(corsApplication.getId());
corsApplicationObject.setName(corsApplication.getName());
return corsApplicationObject;
}
Aggregations