use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method getKeyManagerConfigurations.
public List<KeyManagerConfigurationDTO> getKeyManagerConfigurations() throws APIManagementException {
List<KeyManagerConfigurationDTO> keyManagerConfigurationDTOS = new ArrayList<>();
final String query = "SELECT * FROM AM_KEY_MANAGER";
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(query)) {
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
KeyManagerConfigurationDTO keyManagerConfigurationDTO = new KeyManagerConfigurationDTO();
String uuid = resultSet.getString("UUID");
keyManagerConfigurationDTO.setUuid(uuid);
keyManagerConfigurationDTO.setName(resultSet.getString("NAME"));
keyManagerConfigurationDTO.setDisplayName(resultSet.getString("DISPLAY_NAME"));
keyManagerConfigurationDTO.setDescription(resultSet.getString("DESCRIPTION"));
keyManagerConfigurationDTO.setType(resultSet.getString("TYPE"));
keyManagerConfigurationDTO.setEnabled(resultSet.getBoolean("ENABLED"));
keyManagerConfigurationDTO.setOrganization(resultSet.getString("ORGANIZATION"));
keyManagerConfigurationDTO.setTokenType(resultSet.getString("TOKEN_TYPE"));
keyManagerConfigurationDTO.setExternalReferenceId(resultSet.getString("EXTERNAL_REFERENCE_ID"));
try (InputStream configuration = resultSet.getBinaryStream("CONFIGURATION")) {
String configurationContent = IOUtils.toString(configuration);
Map map = new Gson().fromJson(configurationContent, Map.class);
keyManagerConfigurationDTO.setAdditionalProperties(map);
} catch (IOException e) {
log.error("Error while converting configurations in " + uuid, e);
}
keyManagerConfigurationDTOS.add(keyManagerConfigurationDTO);
}
}
} catch (SQLException e) {
throw new APIManagementException("Error while retrieving all key manager configurations", e);
}
return keyManagerConfigurationDTOS;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method isIDPExistInOrg.
public boolean isIDPExistInOrg(String organization, String resourceId) throws APIManagementException {
final String query = "SELECT 1 FROM AM_KEY_MANAGER WHERE EXTERNAL_REFERENCE_ID = ? AND ORGANIZATION = ?";
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(query)) {
preparedStatement.setString(1, resourceId);
preparedStatement.setString(2, organization);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
return true;
}
}
} catch (SQLException e) {
throw new APIManagementException("Error while checking key manager for " + resourceId + " in organization " + organization, e);
}
return false;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method getCommonOperationPolicyByPolicyID.
private OperationPolicyData getCommonOperationPolicyByPolicyID(Connection connection, String policyId, String organization, boolean isWithPolicyDefinition) throws SQLException {
String dbQuery = SQLConstants.OperationPolicyConstants.GET_COMMON_OPERATION_POLICY_WITH_OUT_DEFINITION_FROM_POLICY_ID;
PreparedStatement statement = connection.prepareStatement(dbQuery);
statement.setString(1, policyId);
statement.setString(2, organization);
ResultSet rs = statement.executeQuery();
OperationPolicyData policyData = null;
if (rs.next()) {
policyData = new OperationPolicyData();
policyData.setPolicyId(policyId);
policyData.setOrganization(organization);
policyData.setMd5Hash(rs.getString("POLICY_MD5"));
policyData.setSpecification(populatePolicySpecificationFromRS(rs));
}
rs.close();
statement.close();
if (isWithPolicyDefinition && policyData != null) {
populatePolicyDefinitions(connection, policyId, policyData);
}
return policyData;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method getLightweightApplicationByConsumerKey.
public ApplicationInfo getLightweightApplicationByConsumerKey(String consumerKey) throws APIManagementException {
Connection connection = null;
PreparedStatement prepStmt = null;
ResultSet rs = null;
try {
connection = APIMgtDBUtil.getConnection();
String query = SQLConstants.GET_APPLICATION_INFO_BY_CK;
prepStmt = connection.prepareStatement(query);
prepStmt.setString(1, consumerKey);
rs = prepStmt.executeQuery();
if (rs.next()) {
ApplicationInfo applicationInfo = new ApplicationInfo();
applicationInfo.setName(rs.getString("NAME"));
applicationInfo.setUuid(rs.getString("UUID"));
applicationInfo.setOrganizationId(rs.getString("ORGANIZATION"));
applicationInfo.setOwner(rs.getString("OWNER"));
return applicationInfo;
}
} catch (SQLException e) {
handleException("Error while obtaining organisation of the application for client id " + consumerKey, e);
} finally {
APIMgtDBUtil.closeAllConnections(prepStmt, connection, rs);
}
return null;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method getConsumerKeysForApplication.
/**
* Retrieves the consumer keys and keymanager in a given application
*
* @param appId application id
* @return Map<ConsumerKey, Pair<keyManagerName, keyManagerTenantDomain>
* @throws APIManagementException
*/
public Map<String, Pair<String, String>> getConsumerKeysForApplication(int appId) throws APIManagementException {
Map<String, Pair<String, String>> consumerKeysOfApplication = new HashMap<>();
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(SQLConstants.GET_CONSUMER_KEY_OF_APPLICATION_SQL)) {
preparedStatement.setInt(1, appId);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
String consumerKey = resultSet.getString("CONSUMER_KEY");
String keyManagerName = resultSet.getString("NAME");
String keyManagerOrganization = resultSet.getString("ORGANIZATION");
consumerKeysOfApplication.put(consumerKey, Pair.of(keyManagerName, keyManagerOrganization));
}
}
} catch (SQLException e) {
String msg = "Error occurred while getting consumer keys for application " + appId;
log.error(msg, e);
throw new APIManagementException(msg, e);
}
return consumerKeysOfApplication;
}
Aggregations