use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationKeyDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method getApplicationKeyByAppIDAndKeyMapping.
/**
* Returns Keys of an application by key type
*
* @param applicationId Application Id
* @param keyMappingId Key Mapping ID
* @return Application Key Information
*/
private ApplicationKeyDTO getApplicationKeyByAppIDAndKeyMapping(String applicationId, String keyMappingId) {
String username = RestApiCommonUtil.getLoggedInUsername();
try {
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(username);
Application application = apiConsumer.getLightweightApplicationByUUID(applicationId);
if (application != null) {
APIKey apiKey = apiConsumer.getApplicationKeyByAppIDAndKeyMapping(application.getId(), keyMappingId);
if (apiKey != null) {
return ApplicationKeyMappingUtil.fromApplicationKeyToDTO(apiKey);
}
} else {
log.error("Application not found with ID: " + applicationId);
}
} catch (APIManagementException e) {
log.error(e.getMessage(), e);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationKeyDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsApplicationIdOauthKeysKeyMappingIdPut.
@Override
public Response applicationsApplicationIdOauthKeysKeyMappingIdPut(String applicationId, String keyMappingId, ApplicationKeyDTO body, MessageContext messageContext) throws APIManagementException {
String username = RestApiCommonUtil.getLoggedInUsername();
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(username);
Application application = apiConsumer.getApplicationByUUID(applicationId);
if (application != null) {
ApplicationKeyDTO appKey = getApplicationKeyByAppIDAndKeyMapping(applicationId, keyMappingId);
if (RestAPIStoreUtils.isUserOwnerOfApplication(application) && appKey != null) {
String grantTypes = StringUtils.join(body.getSupportedGrantTypes(), ',');
JsonObject jsonParams = new JsonObject();
jsonParams.addProperty(APIConstants.JSON_GRANT_TYPES, grantTypes);
jsonParams.addProperty(APIConstants.JSON_USERNAME, username);
if (body.getAdditionalProperties() != null) {
if (body.getAdditionalProperties() instanceof String && StringUtils.isNotEmpty((String) body.getAdditionalProperties())) {
jsonParams.addProperty(APIConstants.JSON_ADDITIONAL_PROPERTIES, (String) body.getAdditionalProperties());
} else if (body.getAdditionalProperties() instanceof Map) {
String jsonContent = new Gson().toJson(body.getAdditionalProperties());
jsonParams.addProperty(APIConstants.JSON_ADDITIONAL_PROPERTIES, jsonContent);
}
}
OAuthApplicationInfo updatedData = apiConsumer.updateAuthClient(username, application, appKey.getKeyType().value(), body.getCallbackUrl(), null, null, null, body.getGroupId(), new Gson().toJson(jsonParams), appKey.getKeyManager());
ApplicationKeyDTO applicationKeyDTO = new ApplicationKeyDTO();
applicationKeyDTO.setCallbackUrl(updatedData.getCallBackURL());
JsonObject json = new Gson().fromJson(updatedData.getJsonString(), JsonObject.class);
if (json.get(APIConstants.JSON_GRANT_TYPES) != null) {
String[] updatedGrantTypes = json.get(APIConstants.JSON_GRANT_TYPES).getAsString().split(" ");
applicationKeyDTO.setSupportedGrantTypes(Arrays.asList(updatedGrantTypes));
}
applicationKeyDTO.setConsumerKey(updatedData.getClientId());
applicationKeyDTO.setConsumerSecret(updatedData.getClientSecret());
applicationKeyDTO.setKeyType(appKey.getKeyType());
Object additionalProperties = updatedData.getParameter(APIConstants.JSON_ADDITIONAL_PROPERTIES);
if (additionalProperties != null) {
applicationKeyDTO.setAdditionalProperties(additionalProperties);
}
applicationKeyDTO.setKeyMappingId(body.getKeyMappingId());
applicationKeyDTO.setKeyManager(body.getKeyManager());
return Response.ok().entity(applicationKeyDTO).build();
} else {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_APPLICATION, applicationId, log);
}
} else {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_APPLICATION, applicationId, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationKeyDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsApplicationIdKeysGet.
/**
* Retrieve all keys of an application
*
* @param applicationId Application Id
* @return Application Key Information list
*/
@Override
public Response applicationsApplicationIdKeysGet(String applicationId, MessageContext messageContext) {
Set<APIKey> applicationKeys = getApplicationKeys(applicationId);
List<ApplicationKeyDTO> keyDTOList = new ArrayList<>();
ApplicationKeyListDTO applicationKeyListDTO = new ApplicationKeyListDTO();
applicationKeyListDTO.setCount(0);
if (applicationKeys != null) {
for (APIKey apiKey : applicationKeys) {
ApplicationKeyDTO appKeyDTO = ApplicationKeyMappingUtil.fromApplicationKeyToDTO(apiKey);
keyDTOList.add(appKeyDTO);
}
applicationKeyListDTO.setList(keyDTOList);
applicationKeyListDTO.setCount(keyDTOList.size());
}
return Response.ok().entity(applicationKeyListDTO).build();
}
Aggregations