Search in sources :

Example 11 with ApplicationSettings

use of io.gravitee.rest.api.model.application.ApplicationSettings 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 12 with ApplicationSettings

use of io.gravitee.rest.api.model.application.ApplicationSettings 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 13 with ApplicationSettings

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

the class ApplicationsResourceTest method shouldCreateApplicationWithEmptySettings.

@Test
public void shouldCreateApplicationWithEmptySettings() {
    ApplicationInput input = new ApplicationInput().description(APPLICATION).groups(Arrays.asList(APPLICATION)).name(APPLICATION).settings(new io.gravitee.rest.api.portal.rest.model.ApplicationSettings());
    final Response response = target().request().post(Entity.json(input));
    assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
    ArgumentCaptor<NewApplicationEntity> captor = ArgumentCaptor.forClass(NewApplicationEntity.class);
    Mockito.verify(applicationService).create(captor.capture(), any());
    final NewApplicationEntity value = captor.getValue();
    assertNotNull(value);
    assertEquals(APPLICATION, value.getDescription());
    assertEquals(APPLICATION, value.getName());
    final Set<String> groups = value.getGroups();
    assertNotNull(groups);
    assertFalse(groups.isEmpty());
    assertTrue(groups.contains(APPLICATION));
    assertNull(value.getType());
    assertNull(value.getClientId());
    final ApplicationSettings settings = value.getSettings();
    assertNotNull(settings);
    assertNull(settings.getApp());
    assertNull(settings.getoAuthClient());
    Application createdApp = response.readEntity(Application.class);
    assertNotNull(createdApp);
    assertEquals("NEW", createdApp.getId());
}
Also used : NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) Response(javax.ws.rs.core.Response) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) io.gravitee.rest.api.portal.rest.model(io.gravitee.rest.api.portal.rest.model) Test(org.junit.Test)

Example 14 with ApplicationSettings

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

the class ApplicationsResourceTest method shouldCreateApplicationWithoutSettings.

@Test
public void shouldCreateApplicationWithoutSettings() {
    ApplicationInput input = new ApplicationInput().description(APPLICATION).groups(Arrays.asList(APPLICATION)).name(APPLICATION);
    final Response response = target().request().post(Entity.json(input));
    assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
    assertEquals(target().path("NEW").getUri().toString(), response.getHeaders().getFirst(HttpHeaders.LOCATION));
    ArgumentCaptor<NewApplicationEntity> captor = ArgumentCaptor.forClass(NewApplicationEntity.class);
    Mockito.verify(applicationService).create(captor.capture(), any());
    final NewApplicationEntity value = captor.getValue();
    assertNotNull(value);
    assertEquals(APPLICATION, value.getDescription());
    assertEquals(APPLICATION, value.getName());
    final Set<String> groups = value.getGroups();
    assertNotNull(groups);
    assertFalse(groups.isEmpty());
    assertTrue(groups.contains(APPLICATION));
    assertNull(value.getType());
    assertNull(value.getClientId());
    final ApplicationSettings settings = value.getSettings();
    assertNotNull(settings);
    assertNull(settings.getApp());
    assertNull(settings.getoAuthClient());
    Application createdApp = response.readEntity(Application.class);
    assertNotNull(createdApp);
    assertEquals("NEW", createdApp.getId());
}
Also used : Response(javax.ws.rs.core.Response) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) Test(org.junit.Test)

Example 15 with ApplicationSettings

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

the class ApplicationsResourceTest method shouldCreateApplicationWithOauthSettings.

@Test
public void shouldCreateApplicationWithOauthSettings() {
    ApplicationInput input = new ApplicationInput().description(APPLICATION).groups(Arrays.asList(APPLICATION)).name(APPLICATION);
    OAuthClientSettings oacs = new OAuthClientSettings().applicationType(APPLICATION).clientId(APPLICATION).clientSecret(APPLICATION).clientUri(APPLICATION).logoUri(APPLICATION).grantTypes(Arrays.asList(APPLICATION)).redirectUris(Arrays.asList(APPLICATION)).responseTypes(Arrays.asList(APPLICATION)).renewClientSecretSupported(Boolean.TRUE);
    input.setSettings(new io.gravitee.rest.api.portal.rest.model.ApplicationSettings().oauth(oacs));
    final Response response = target().request().post(Entity.json(input));
    assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
    ArgumentCaptor<NewApplicationEntity> captor = ArgumentCaptor.forClass(NewApplicationEntity.class);
    Mockito.verify(applicationService).create(captor.capture(), any());
    final NewApplicationEntity value = captor.getValue();
    assertNotNull(value);
    assertEquals(APPLICATION, value.getDescription());
    assertEquals(APPLICATION, value.getName());
    final Set<String> groups = value.getGroups();
    assertNotNull(groups);
    assertFalse(groups.isEmpty());
    assertTrue(groups.contains(APPLICATION));
    assertNull(value.getType());
    assertNull(value.getClientId());
    final ApplicationSettings settings = value.getSettings();
    assertNotNull(settings);
    assertNull(settings.getApp());
    final io.gravitee.rest.api.model.application.OAuthClientSettings oauthClientSettings = settings.getoAuthClient();
    assertNotNull(oauthClientSettings);
    assertEquals(APPLICATION, oauthClientSettings.getApplicationType());
    final List<String> grantTypes = oauthClientSettings.getGrantTypes();
    assertNotNull(grantTypes);
    assertFalse(grantTypes.isEmpty());
    assertEquals(APPLICATION, grantTypes.get(0));
    final List<String> redirectUris = oauthClientSettings.getRedirectUris();
    assertNotNull(redirectUris);
    assertFalse(redirectUris.isEmpty());
    assertEquals(APPLICATION, redirectUris.get(0));
    Application createdApp = response.readEntity(Application.class);
    assertNotNull(createdApp);
    assertEquals("NEW", createdApp.getId());
}
Also used : NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) Response(javax.ws.rs.core.Response) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) Test(org.junit.Test)

Aggregations

ApplicationSettings (io.gravitee.rest.api.model.application.ApplicationSettings)27 SimpleApplicationSettings (io.gravitee.rest.api.model.application.SimpleApplicationSettings)22 Test (org.junit.Test)19 OAuthClientSettings (io.gravitee.rest.api.model.application.OAuthClientSettings)12 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)8 NewApplicationEntity (io.gravitee.rest.api.model.NewApplicationEntity)7 Application (io.gravitee.rest.api.portal.rest.model.Application)5 UserService (io.gravitee.rest.api.service.UserService)4 HashMap (java.util.HashMap)4 Response (javax.ws.rs.core.Response)4 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)3 UpdateApplicationEntity (io.gravitee.rest.api.model.UpdateApplicationEntity)3 UserEntity (io.gravitee.rest.api.model.UserEntity)3 Optional (java.util.Optional)3 ApplicationRepository (io.gravitee.repository.management.api.ApplicationRepository)2 io.gravitee.repository.management.model (io.gravitee.repository.management.model)2 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)2 MembershipEntity (io.gravitee.rest.api.model.MembershipEntity)2 MembershipMemberType (io.gravitee.rest.api.model.MembershipMemberType)2 MembershipReferenceType (io.gravitee.rest.api.model.MembershipReferenceType)2