use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.
the class ApiMgtDAO method getKeyManagerConfigurationByName.
private KeyManagerConfigurationDTO getKeyManagerConfigurationByName(Connection connection, String organization, String name) throws SQLException, IOException {
final String query = "SELECT * FROM AM_KEY_MANAGER WHERE NAME = ? AND ORGANIZATION = ?";
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setString(1, name);
preparedStatement.setString(2, organization);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (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(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);
}
return keyManagerConfigurationDTO;
}
}
}
return null;
}
use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.
the class ApiMgtDAO method populateAppRegistrationWorkflowDTO.
public void populateAppRegistrationWorkflowDTO(ApplicationRegistrationWorkflowDTO workflowDTO) throws APIManagementException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
Application application = null;
Subscriber subscriber = null;
String registrationEntry = SQLConstants.GET_APPLICATION_REGISTRATION_ENTRY_BY_SUBSCRIBER_SQL;
try {
conn = APIMgtDBUtil.getConnection();
ps = conn.prepareStatement(registrationEntry);
ps.setString(1, workflowDTO.getExternalWorkflowReference());
rs = ps.executeQuery();
while (rs.next()) {
subscriber = new Subscriber(rs.getString("USER_ID"));
subscriber.setId(rs.getInt("SUBSCRIBER_ID"));
application = new Application(rs.getString("NAME"), subscriber);
application.setId(rs.getInt("APPLICATION_ID"));
application.setUUID(rs.getString("UUID"));
application.setTokenType(rs.getString("APP_TYPE"));
application.setApplicationWorkFlowStatus(rs.getString("APPLICATION_STATUS"));
application.setCallbackUrl(rs.getString("CALLBACK_URL"));
application.setDescription(rs.getString("DESCRIPTION"));
application.setTier(rs.getString("APPLICATION_TIER"));
workflowDTO.setApplication(application);
workflowDTO.setKeyType(rs.getString("TOKEN_TYPE"));
workflowDTO.setUserName(subscriber.getName());
workflowDTO.setDomainList(rs.getString("ALLOWED_DOMAINS"));
workflowDTO.setValidityTime(rs.getLong("VALIDITY_PERIOD"));
String tenantDomain = MultitenantUtils.getTenantDomain(subscriber.getName());
String keyManagerUUID = rs.getString("KEY_MANAGER");
workflowDTO.setKeyManager(keyManagerUUID);
KeyManagerConfigurationDTO keyManagerConfigurationByUUID = getKeyManagerConfigurationByUUID(conn, keyManagerUUID);
if (keyManagerConfigurationByUUID != null) {
OAuthAppRequest request = ApplicationUtils.createOauthAppRequest(application.getName(), null, application.getCallbackUrl(), rs.getString("TOKEN_SCOPE"), rs.getString("INPUTS"), application.getTokenType(), keyManagerConfigurationByUUID.getOrganization(), keyManagerConfigurationByUUID.getName());
request.setMappingId(workflowDTO.getWorkflowReference());
request.getOAuthApplicationInfo().setApplicationUUID(application.getUUID());
workflowDTO.setAppInfoDTO(request);
} else {
throw new APIManagementException("Error occured while finding the KeyManager from uuid " + keyManagerUUID + ".", ExceptionCodes.KEY_MANAGER_NOT_REGISTERED);
}
}
} catch (SQLException | IOException e) {
handleException("Error occurred while retrieving an " + "Application Registration Entry for Workflow : " + workflowDTO.getExternalWorkflowReference(), e);
} finally {
APIMgtDBUtil.closeAllConnections(ps, conn, rs);
}
}
use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.
the class ApiMgtDAO method getKeyManagerConfigurationByUUID.
private KeyManagerConfigurationDTO getKeyManagerConfigurationByUUID(Connection connection, String uuid) throws SQLException, IOException {
final String query = "SELECT * FROM AM_KEY_MANAGER WHERE UUID = ?";
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setString(1, uuid);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
KeyManagerConfigurationDTO keyManagerConfigurationDTO = new KeyManagerConfigurationDTO();
keyManagerConfigurationDTO.setUuid(resultSet.getString("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);
}
return keyManagerConfigurationDTO;
}
}
}
return null;
}
use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO 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.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.
the class ApiMgtDAO method getKeyManagerConfigurationByID.
public KeyManagerConfigurationDTO getKeyManagerConfigurationByID(String organization, String id) throws APIManagementException {
final String query = "SELECT * FROM AM_KEY_MANAGER WHERE UUID = ? AND ORGANIZATION = ?";
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(query)) {
preparedStatement.setString(1, id);
preparedStatement.setString(2, organization);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
KeyManagerConfigurationDTO keyManagerConfigurationDTO = new KeyManagerConfigurationDTO();
String uuid = resultSet.getString("UUID");
keyManagerConfigurationDTO.setUuid(uuid);
keyManagerConfigurationDTO.setName(resultSet.getString("NAME"));
keyManagerConfigurationDTO.setDescription(resultSet.getString("DESCRIPTION"));
keyManagerConfigurationDTO.setType(resultSet.getString("TYPE"));
keyManagerConfigurationDTO.setEnabled(resultSet.getBoolean("ENABLED"));
keyManagerConfigurationDTO.setOrganization(organization);
keyManagerConfigurationDTO.setDisplayName(resultSet.getString("DISPLAY_NAME"));
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);
}
return keyManagerConfigurationDTO;
}
}
} catch (SQLException | IOException e) {
throw new APIManagementException("Error while retrieving key manager configuration for " + id + " in organization " + organization, e);
}
return null;
}
Aggregations