use of io.gravitee.rest.api.model.NewApplicationEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationsResource method createApplication.
/**
* Create a new application for the authenticated user.
*
* @param application
* @return
*/
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create an application", notes = "User must have MANAGEMENT_APPLICATION[CREATE] permission to create an application.")
@ApiResponses({ @ApiResponse(code = 201, message = "Application successfully created", response = ApplicationEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_APPLICATION, acls = RolePermissionAction.CREATE) })
public Response createApplication(@ApiParam(name = "application", required = true) @Valid @NotNull(message = "An application must be provided") final NewApplicationEntity application) {
// To preserve backward compatibility, ensure that we have at least default settings for simple application type
if (application.getSettings() == null || (application.getSettings().getoAuthClient() == null && application.getSettings().getApp() == null)) {
ApplicationSettings settings = new ApplicationSettings();
SimpleApplicationSettings simpleAppSettings = new SimpleApplicationSettings();
simpleAppSettings.setType(application.getType());
simpleAppSettings.setClientId(application.getClientId());
settings.setApp(simpleAppSettings);
application.setSettings(settings);
}
ApplicationEntity newApplication = applicationService.create(application, getAuthenticatedUser());
if (newApplication != null) {
return Response.created(this.getLocationHeader(newApplication.getId())).entity(newApplication).build();
}
return Response.serverError().build();
}
use of io.gravitee.rest.api.model.NewApplicationEntity 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();
}
use of io.gravitee.rest.api.model.NewApplicationEntity 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());
}
use of io.gravitee.rest.api.model.NewApplicationEntity 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());
}
use of io.gravitee.rest.api.model.NewApplicationEntity 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());
}
Aggregations