Search in sources :

Example 6 with OAuthClientSettings

use of io.gravitee.rest.api.model.application.OAuthClientSettings in project gravitee-management-rest-api by gravitee-io.

the class ApplicationService_CreateTest method shouldNotCreateBecauseRedirectURIsNotFound.

@Test(expected = ApplicationRedirectUrisNotFound.class)
public void shouldNotCreateBecauseRedirectURIsNotFound() {
    ApplicationSettings settings = new ApplicationSettings();
    OAuthClientSettings clientSettings = new OAuthClientSettings();
    clientSettings.setApplicationType("web");
    clientSettings.setGrantTypes(Arrays.asList("foobar"));
    settings.setoAuthClient(clientSettings);
    ApplicationTypeEntity applicationType = mock(ApplicationTypeEntity.class);
    ApplicationGrantTypeEntity foobar = new ApplicationGrantTypeEntity();
    foobar.setType("foobar");
    when(applicationType.getRequires_redirect_uris()).thenReturn(true);
    when(applicationType.getAllowed_grant_types()).thenReturn(Arrays.asList(foobar));
    when(applicationTypeService.getApplicationType(any())).thenReturn(applicationType);
    when(newApplication.getSettings()).thenReturn(settings);
    when(parameterService.findAsBoolean(Key.APPLICATION_REGISTRATION_ENABLED, "DEFAULT", ParameterReferenceType.ENVIRONMENT)).thenReturn(Boolean.TRUE);
    when(parameterService.findAsBoolean(Key.APPLICATION_TYPE_WEB_ENABLED, "DEFAULT", ParameterReferenceType.ENVIRONMENT)).thenReturn(Boolean.TRUE);
    applicationService.create(newApplication, USER_NAME);
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) ApplicationGrantTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationGrantTypeEntity) Test(org.junit.Test)

Example 7 with OAuthClientSettings

use of io.gravitee.rest.api.model.application.OAuthClientSettings in project gravitee-management-rest-api by gravitee-io.

the class ApplicationService_CreateTest method shouldNotCreateBecauseGrantTypesIsEmpty.

@Test(expected = ApplicationGrantTypesNotFoundException.class)
public void shouldNotCreateBecauseGrantTypesIsEmpty() {
    ApplicationSettings settings = new ApplicationSettings();
    OAuthClientSettings clientSettings = new OAuthClientSettings();
    clientSettings.setApplicationType("web");
    settings.setoAuthClient(clientSettings);
    when(newApplication.getSettings()).thenReturn(settings);
    when(parameterService.findAsBoolean(Key.APPLICATION_REGISTRATION_ENABLED, "DEFAULT", ParameterReferenceType.ENVIRONMENT)).thenReturn(Boolean.TRUE);
    when(parameterService.findAsBoolean(Key.APPLICATION_TYPE_WEB_ENABLED, "DEFAULT", ParameterReferenceType.ENVIRONMENT)).thenReturn(Boolean.TRUE);
    applicationService.create(newApplication, USER_NAME);
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) Test(org.junit.Test)

Example 8 with OAuthClientSettings

use of io.gravitee.rest.api.model.application.OAuthClientSettings in project gravitee-management-rest-api by gravitee-io.

the class ApplicationResource method updateApplicationByApplicationId.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_DEFINITION, acls = RolePermissionAction.UPDATE) })
public Response updateApplicationByApplicationId(@PathParam("applicationId") String applicationId, @Valid @NotNull(message = "Input must not be null.") Application application) {
    if (!applicationId.equalsIgnoreCase(application.getId())) {
        throw new BadRequestException("'applicationId' is not the same that the application in payload");
    }
    ApplicationEntity appEntity = applicationService.findById(applicationId);
    UpdateApplicationEntity updateApplicationEntity = new UpdateApplicationEntity();
    updateApplicationEntity.setDescription(application.getDescription());
    updateApplicationEntity.setName(application.getName());
    updateApplicationEntity.setPicture(checkAndScaleImage(application.getPicture()));
    checkImageFormat(application.getBackground());
    updateApplicationEntity.setBackground(application.getBackground());
    updateApplicationEntity.setGroups(appEntity.getGroups());
    if (application.getSettings() != null) {
        ApplicationSettings settings = new ApplicationSettings();
        if (application.getSettings().getApp() != null) {
            SimpleApplicationSettings sas = appEntity.getSettings().getApp();
            sas.setClientId(application.getSettings().getApp().getClientId());
            sas.setType(application.getSettings().getApp().getType());
            settings.setApp(sas);
        } else if (application.getSettings().getOauth() != null) {
            OAuthClientSettings oacs = appEntity.getSettings().getoAuthClient();
            oacs.setGrantTypes(application.getSettings().getOauth().getGrantTypes());
            oacs.setRedirectUris(application.getSettings().getOauth().getRedirectUris());
            settings.setoAuthClient(oacs);
        }
        updateApplicationEntity.setSettings(settings);
    }
    Application updatedApp = applicationMapper.convert(applicationService.update(applicationId, updateApplicationEntity), uriInfo);
    return Response.ok(addApplicationLinks(updatedApp)).tag(Long.toString(updatedApp.getUpdatedAt().toInstant().toEpochMilli())).lastModified(Date.from(updatedApp.getUpdatedAt().toInstant())).build();
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) UpdateApplicationEntity(io.gravitee.rest.api.model.UpdateApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Application(io.gravitee.rest.api.portal.rest.model.Application) UpdateApplicationEntity(io.gravitee.rest.api.model.UpdateApplicationEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 9 with OAuthClientSettings

use of io.gravitee.rest.api.model.application.OAuthClientSettings in project gravitee-management-rest-api by gravitee-io.

the class ApplicationsResource method createApplication.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_APPLICATION, acls = RolePermissionAction.CREATE) })
public Response createApplication(@Valid @NotNull(message = "Input must not be null.") ApplicationInput applicationInput) {
    NewApplicationEntity newApplicationEntity = new NewApplicationEntity();
    newApplicationEntity.setDescription(applicationInput.getDescription());
    newApplicationEntity.setGroups(applicationInput.getGroups() != null ? new HashSet<>(applicationInput.getGroups()) : new HashSet<>());
    newApplicationEntity.setName(applicationInput.getName());
    newApplicationEntity.setPicture(applicationInput.getPicture());
    final io.gravitee.rest.api.portal.rest.model.ApplicationSettings settings = applicationInput.getSettings();
    ApplicationSettings newApplicationEntitySettings = new ApplicationSettings();
    if (settings == null || (settings.getApp() == null && settings.getOauth() == null)) {
        newApplicationEntity.setSettings(newApplicationEntitySettings);
    } else {
        final io.gravitee.rest.api.portal.rest.model.SimpleApplicationSettings simpleAppInput = settings.getApp();
        if (simpleAppInput != null) {
            SimpleApplicationSettings sas = new SimpleApplicationSettings();
            sas.setClientId(simpleAppInput.getClientId());
            sas.setType(simpleAppInput.getType());
            newApplicationEntitySettings.setApp(sas);
        }
        final io.gravitee.rest.api.portal.rest.model.OAuthClientSettings oauthAppInput = settings.getOauth();
        if (oauthAppInput != null) {
            OAuthClientSettings ocs = new OAuthClientSettings();
            ocs.setApplicationType(oauthAppInput.getApplicationType());
            ocs.setGrantTypes(oauthAppInput.getGrantTypes());
            ocs.setRedirectUris(oauthAppInput.getRedirectUris());
            newApplicationEntitySettings.setoAuthClient(ocs);
        }
    }
    newApplicationEntity.setSettings(newApplicationEntitySettings);
    ApplicationEntity createdApplicationEntity = applicationService.create(newApplicationEntity, getAuthenticatedUser());
    return Response.created(this.getLocationHeader(createdApplicationEntity.getId())).entity(applicationMapper.convert(createdApplicationEntity, uriInfo)).build();
}
Also used : NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 10 with OAuthClientSettings

use of io.gravitee.rest.api.model.application.OAuthClientSettings in project gravitee-management-rest-api by gravitee-io.

the class ApplicationServiceImpl method getSettings.

private ApplicationSettings getSettings(Application application) {
    final ApplicationSettings settings = new ApplicationSettings();
    if (application.getType() == ApplicationType.SIMPLE) {
        SimpleApplicationSettings simpleSettings = new SimpleApplicationSettings();
        if (application.getMetadata() != null) {
            if (application.getMetadata().get("client_id") != null) {
                simpleSettings.setClientId(application.getMetadata().get("client_id"));
            }
            if (application.getMetadata().get("type") != null) {
                simpleSettings.setType(application.getMetadata().get("type"));
            }
        }
        settings.setApp(simpleSettings);
    } else {
        OAuthClientSettings clientSettings = new OAuthClientSettings();
        if (application.getMetadata() != null) {
            try {
                final String registrationPayload = application.getMetadata().get("registration_payload");
                if (registrationPayload != null) {
                    final ClientRegistrationResponse registrationResponse = mapper.readValue(registrationPayload, ClientRegistrationResponse.class);
                    clientSettings.setClientId(registrationResponse.getClientId());
                    clientSettings.setClientSecret(registrationResponse.getClientSecret());
                    clientSettings.setClientUri(registrationResponse.getClientUri());
                    clientSettings.setApplicationType(registrationResponse.getApplicationType());
                    clientSettings.setLogoUri(registrationResponse.getLogoUri());
                    clientSettings.setResponseTypes(registrationResponse.getResponseTypes());
                    clientSettings.setRedirectUris(registrationResponse.getRedirectUris());
                    clientSettings.setGrantTypes(registrationResponse.getGrantTypes());
                }
                Iterator<ClientRegistrationProviderEntity> clientRegistrationProviderIte = clientRegistrationService.findAll().iterator();
                if (clientRegistrationProviderIte.hasNext()) {
                    clientSettings.setRenewClientSecretSupported(clientRegistrationProviderIte.next().isRenewClientSecretSupport());
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        settings.setoAuthClient(clientSettings);
    }
    return settings;
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) ClientRegistrationResponse(io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationResponse) ClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity) UuidString(io.gravitee.rest.api.service.common.UuidString) IOException(java.io.IOException)

Aggregations

ApplicationSettings (io.gravitee.rest.api.model.application.ApplicationSettings)12 OAuthClientSettings (io.gravitee.rest.api.model.application.OAuthClientSettings)12 SimpleApplicationSettings (io.gravitee.rest.api.model.application.SimpleApplicationSettings)11 Test (org.junit.Test)7 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)3 ApplicationTypeEntity (io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity)3 Application (io.gravitee.rest.api.portal.rest.model.Application)3 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)2 ClientRegistrationProviderEntity (io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity)2 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Component (org.springframework.stereotype.Component)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Page (io.gravitee.common.data.domain.Page)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 ApplicationRepository (io.gravitee.repository.management.api.ApplicationRepository)1 MembershipRepository (io.gravitee.repository.management.api.MembershipRepository)1 ApplicationCriteria (io.gravitee.repository.management.api.search.ApplicationCriteria)1 io.gravitee.repository.management.model (io.gravitee.repository.management.model)1