use of org.wso2.micro.gateway.tests.common.model.ApplicationDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class RegisterApiServiceImpl method updateApplication.
@Override
public Response updateApplication(UpdateRequestDTO updateRequest, String clientId) {
ApplicationDTO applicationDTO = null;
try {
Application application = DCRMUtils.getOAuth2DCRMService().updateApplication(DCRMUtils.getApplicationUpdateRequest(updateRequest), clientId);
applicationDTO = DCRMUtils.getApplicationDTOFromApplication(application);
} catch (DCRMClientException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Client error while updating application \n" + updateRequest.toString(), e);
}
DCRMUtils.handleErrorResponse(e, LOG);
} catch (DCRMServerException e) {
DCRMUtils.handleErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, e, true, LOG);
} catch (Throwable throwable) {
DCRMUtils.handleErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, throwable, true, LOG);
}
return Response.status(Response.Status.OK).entity(applicationDTO).build();
}
use of org.wso2.micro.gateway.tests.common.model.ApplicationDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMUtils method getApplicationDTOFromApplication.
/**
* Convert the Application object to the ApplicationDTO object.
* @param application Instance of an @see Application class.
* @return Instance of @see ApplicationDTO
*/
public static ApplicationDTO getApplicationDTOFromApplication(Application application) {
if (application == null) {
return null;
}
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setClientId(application.getClientId());
applicationDTO.setClientName(application.getClientName());
applicationDTO.setClientSecret(application.getClientSecret());
applicationDTO.setRedirectUris(application.getRedirectUris());
applicationDTO.setGrantTypes(application.getGrantTypes());
// currently, we are not setting an expiration time for
applicationDTO.setClientSecretExpiresAt(0L);
return applicationDTO;
}
use of org.wso2.micro.gateway.tests.common.model.ApplicationDTO in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method fromDTOtoApplication.
public static Application fromDTOtoApplication(ApplicationDTO applicationDTO, String username) {
// subscriber field of the body is not honored
Subscriber subscriber = new Subscriber(username);
Application application = new Application(applicationDTO.getName(), subscriber);
application.setTier(applicationDTO.getThrottlingPolicy());
application.setDescription(applicationDTO.getDescription());
application.setUUID(applicationDTO.getApplicationId());
// Check if the token type is not set in the request.
if (StringUtils.isEmpty(applicationDTO.getTokenType().toString())) {
// Set the default to JWT.
application.setTokenType(APIConstants.TOKEN_TYPE_JWT);
} else {
// Otherwise set it to the type in the request.
application.setTokenType(applicationDTO.getTokenType().toString());
}
Map<String, String> appAttributes = applicationDTO.getAttributes();
application.setApplicationAttributes(appAttributes);
if (applicationDTO.getGroups() != null && applicationDTO.getGroups().size() > 0) {
application.setGroupId(String.join(",", applicationDTO.getGroups()));
}
return application;
}
use of org.wso2.micro.gateway.tests.common.model.ApplicationDTO in project carbon-apimgt by wso2.
the class ExportUtils method createApplicationDTOToExport.
/**
* Create an aggregated Application DTO to be exported.
*
* @param application Application{@link Application} to be exported
* @param apiConsumer API Consumer
* @param withKeys Export the Application with keys or not
* @return Exported application
* @throws APIManagementException If an error occurs while retrieving subscribed APIs
*/
private static ExportedApplication createApplicationDTOToExport(Application application, APIConsumer apiConsumer, Boolean withKeys) throws APIManagementException {
ApplicationDTO applicationDto = ApplicationMappingUtil.fromApplicationtoDTO(application);
// Set keys if withKeys is true
if (withKeys == null || !withKeys) {
application.clearOAuthApps();
} else {
List<ApplicationKeyDTO> applicationKeyDTOs = new ArrayList<>();
for (APIKey apiKey : application.getKeys()) {
// Encode the consumer secret and set it
apiKey.setConsumerSecret(new String(Base64.encodeBase64(apiKey.getConsumerSecret().getBytes(Charset.defaultCharset()))));
ApplicationKeyDTO applicationKeyDTO = ApplicationKeyMappingUtil.fromApplicationKeyToDTO(apiKey);
applicationKeyDTOs.add(applicationKeyDTO);
}
applicationDto.setKeys(applicationKeyDTOs);
}
// Get the subscribed API details and add it to a set
Set<SubscribedAPI> subscribedAPIs = apiConsumer.getSubscribedAPIs(application.getSubscriber(), application.getName(), application.getGroupId());
Set<ExportedSubscribedAPI> exportedSubscribedAPIs = new HashSet<>();
for (SubscribedAPI subscribedAPI : subscribedAPIs) {
ExportedSubscribedAPI exportedSubscribedAPI = new ExportedSubscribedAPI(subscribedAPI.getApiId(), subscribedAPI.getSubscriber(), subscribedAPI.getTier().getName());
exportedSubscribedAPIs.add(exportedSubscribedAPI);
}
// Set the subscription count by counting the number of subscribed APIs
applicationDto.setSubscriptionCount(exportedSubscribedAPIs.size());
// Set the application
ExportedApplication exportedApplication = new ExportedApplication(applicationDto);
// Set the subscribed APIs
exportedApplication.setSubscribedAPIs(exportedSubscribedAPIs);
return exportedApplication;
}
use of org.wso2.micro.gateway.tests.common.model.ApplicationDTO in project carbon-apimgt by wso2.
the class SubscriptionValidationDataUtil method fromApplicationToApplicationListDTO.
public static ApplicationListDTO fromApplicationToApplicationListDTO(List<Application> model) {
ApplicationListDTO applicationListDTO = new ApplicationListDTO();
if (model != null) {
for (Application appModel : model) {
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setUuid(appModel.getUuid());
applicationDTO.setId(appModel.getId());
applicationDTO.setName(appModel.getName());
applicationDTO.setPolicy(appModel.getPolicy());
applicationDTO.setSubName(appModel.getSubName());
applicationDTO.setTokenType(appModel.getTokenType());
applicationDTO.setOrganization(appModel.getOrganization());
Set<String> groupIds = appModel.getGroupIds();
for (String grp : groupIds) {
GroupIdDTO groupIdDTO = new GroupIdDTO();
groupIdDTO.setApplicationId(appModel.getId());
groupIdDTO.setGroupId(grp);
applicationDTO.getGroupIds().add(groupIdDTO);
}
Map<String, String> attributes = appModel.getAttributes();
applicationDTO.setAttributes(attributes);
applicationListDTO.getList().add(applicationDTO);
}
applicationListDTO.setCount(model.size());
} else {
applicationListDTO.setCount(0);
}
return applicationListDTO;
}
Aggregations