use of org.wso2.carbon.apimgt.api.model.KeyManager in project carbon-apimgt by wso2.
the class KeyManagersApiServiceImpl method keyManagersKeyManagerIdPut.
public Response keyManagersKeyManagerIdPut(String keyManagerId, KeyManagerDTO body, MessageContext messageContext) throws APIManagementException {
String organization = RestApiUtil.getOrganization(messageContext);
APIAdmin apiAdmin = new APIAdminImpl();
try {
KeyManagerConfigurationDTO keyManagerConfigurationDTO = KeyManagerMappingUtil.toKeyManagerConfigurationDTO(organization, body);
keyManagerConfigurationDTO.setUuid(keyManagerId);
KeyManagerConfigurationDTO oldKeyManagerConfigurationDTO = apiAdmin.getKeyManagerConfigurationById(organization, keyManagerId);
if (oldKeyManagerConfigurationDTO == null) {
throw new APIManagementException("Requested KeyManager not found", ExceptionCodes.KEY_MANAGER_NOT_FOUND);
} else {
if (!oldKeyManagerConfigurationDTO.getName().equals(keyManagerConfigurationDTO.getName())) {
RestApiUtil.handleBadRequest("Key Manager name couldn't able to change", log);
}
KeyManagerConfigurationDTO retrievedKeyManagerConfigurationDTO = apiAdmin.updateKeyManagerConfiguration(keyManagerConfigurationDTO);
APIUtil.logAuditMessage(APIConstants.AuditLogConstants.KEY_MANAGER, new Gson().toJson(keyManagerConfigurationDTO), APIConstants.AuditLogConstants.UPDATED, RestApiCommonUtil.getLoggedInUsername());
return Response.ok(KeyManagerMappingUtil.toKeyManagerDTO(retrievedKeyManagerConfigurationDTO)).build();
}
} catch (APIManagementException e) {
String error = "Error while Retrieving Key Manager configuration for " + keyManagerId + " in organization " + organization;
throw new APIManagementException(error, e, ExceptionCodes.INTERNAL_ERROR);
}
}
use of org.wso2.carbon.apimgt.api.model.KeyManager in project carbon-apimgt by wso2.
the class KeyManagersApiServiceImpl method keyManagersKeyManagerIdGet.
public Response keyManagersKeyManagerIdGet(String keyManagerId, MessageContext messageContext) throws APIManagementException {
String organization = RestApiUtil.getOrganization(messageContext);
APIAdmin apiAdmin = new APIAdminImpl();
KeyManagerConfigurationDTO keyManagerConfigurationDTO = apiAdmin.getKeyManagerConfigurationById(organization, keyManagerId);
if (keyManagerConfigurationDTO != null) {
KeyManagerDTO keyManagerDTO = KeyManagerMappingUtil.toKeyManagerDTO(keyManagerConfigurationDTO);
return Response.ok(keyManagerDTO).build();
}
throw new APIManagementException("Requested KeyManager not found", ExceptionCodes.KEY_MANAGER_NOT_FOUND);
}
use of org.wso2.carbon.apimgt.api.model.KeyManager in project carbon-apimgt by wso2.
the class ApiMgtDAO method getConsumerKeyByApplicationIdKeyTypeKeyManager.
public String getConsumerKeyByApplicationIdKeyTypeKeyManager(int applicationId, String keyType, String keyManager) throws APIManagementException {
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(SQLConstants.GET_CONSUMER_KEY_FOR_APPLICATION_KEY_TYPE_APP_ID_KEY_MANAGER_SQL)) {
preparedStatement.setInt(1, applicationId);
preparedStatement.setString(2, keyType);
preparedStatement.setString(3, keyManager);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
return resultSet.getString("CONSUMER_KEY");
}
}
} catch (SQLException e) {
String msg = "Error occurred while retreving consumer key for application" + applicationId + " keyType " + keyType + " Key Manager " + keyManager;
log.error(msg, e);
throw new APIManagementException(msg, e);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.KeyManager 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.model.KeyManager 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