Search in sources :

Example 31 with ApplicationDTO

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();
}
Also used : ApplicationDTO(org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.ApplicationDTO) DCRMClientException(org.wso2.carbon.identity.oauth.dcr.exception.DCRMClientException) DCRMServerException(org.wso2.carbon.identity.oauth.dcr.exception.DCRMServerException) Application(org.wso2.carbon.identity.oauth.dcr.bean.Application)

Example 32 with ApplicationDTO

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;
}
Also used : ApplicationDTO(org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.ApplicationDTO)

Example 33 with 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;
}
Also used : Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 34 with ApplicationDTO

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;
}
Also used : ExportedSubscribedAPI(org.wso2.carbon.apimgt.rest.api.store.v1.models.ExportedSubscribedAPI) ApplicationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO) APIKey(org.wso2.carbon.apimgt.api.model.APIKey) ApplicationKeyDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationKeyDTO) ArrayList(java.util.ArrayList) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) ExportedSubscribedAPI(org.wso2.carbon.apimgt.rest.api.store.v1.models.ExportedSubscribedAPI) ExportedApplication(org.wso2.carbon.apimgt.rest.api.store.v1.models.ExportedApplication) HashSet(java.util.HashSet)

Example 35 with ApplicationDTO

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;
}
Also used : GroupIdDTO(org.wso2.carbon.apimgt.internal.service.dto.GroupIdDTO) ApplicationDTO(org.wso2.carbon.apimgt.internal.service.dto.ApplicationDTO) Application(org.wso2.carbon.apimgt.api.model.subscription.Application) ApplicationListDTO(org.wso2.carbon.apimgt.internal.service.dto.ApplicationListDTO)

Aggregations

BeforeClass (org.testng.annotations.BeforeClass)17 ApplicationDTO (org.wso2.micro.gateway.tests.common.model.ApplicationDTO)17 Application (org.wso2.carbon.apimgt.core.models.Application)11 ApplicationDTO (org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationDTO)11 ArrayList (java.util.ArrayList)10 JSONObject (org.json.JSONObject)10 HashMap (java.util.HashMap)9 Application (org.wso2.carbon.apimgt.api.model.Application)8 API (org.wso2.micro.gateway.tests.common.model.API)8 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)7 ExportedApplication (org.wso2.carbon.apimgt.rest.api.store.v1.models.ExportedApplication)7 KeyValidationInfo (org.wso2.micro.gateway.tests.common.KeyValidationInfo)7 MockAPIPublisher (org.wso2.micro.gateway.tests.common.MockAPIPublisher)7 Test (org.junit.Test)6 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)6 ApplicationKeysDTO (org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationKeysDTO)6 ApplicationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO)6 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)5 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)5 ApplicationCreationResponse (org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse)5