use of io.gravitee.rest.api.model.application.ApplicationSettings 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.application.ApplicationSettings in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMapperTest method testConvertFromAppEntitySimpleApp.
@Test
public void testConvertFromAppEntitySimpleApp() {
ApplicationSettings settings = new ApplicationSettings();
SimpleApplicationSettings simpleAppEntitySetings = new SimpleApplicationSettings();
simpleAppEntitySetings.setClientId(APPLICATION_SIMPLE_CLIENT_ID);
simpleAppEntitySetings.setType(APPLICATION_SIMPLE_TYPE);
settings.setApp(simpleAppEntitySetings);
applicationEntity.setSettings(settings);
Application responseApplication = applicationMapper.convert(applicationEntity, uriInfo);
checkApplication(now, responseApplication, AppSettingsEnum.SIMPLE_SETTINGS);
}
use of io.gravitee.rest.api.model.application.ApplicationSettings in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMapperTest method testConvertFromAppEntityOAuthClient.
@Test
public void testConvertFromAppEntityOAuthClient() {
ApplicationSettings settings = new ApplicationSettings();
OAuthClientSettings oAuthClientEntitySettings = new OAuthClientSettings();
oAuthClientEntitySettings.setApplicationType(APPLICATION_OAUTH_APPLICATION_TYPE);
oAuthClientEntitySettings.setClientId(APPLICATION_OAUTH_CLIENT_ID);
oAuthClientEntitySettings.setClientSecret(APPLICATION_OAUTH_CLIENT_SECRET);
oAuthClientEntitySettings.setClientUri(APPLICATION_OAUTH_CLIENT_URI);
oAuthClientEntitySettings.setGrantTypes(Arrays.asList(APPLICATION_OAUTH_GRANT_TYPE));
oAuthClientEntitySettings.setLogoUri(APPLICATION_OAUTH_LOGO_URI);
oAuthClientEntitySettings.setRedirectUris(Arrays.asList(APPLICATION_OAUTH_REDIRECT_URI));
oAuthClientEntitySettings.setRenewClientSecretSupported(true);
oAuthClientEntitySettings.setResponseTypes(Arrays.asList(APPLICATION_OAUTH_RESPONSE_TYPE));
settings.setoAuthClient(oAuthClientEntitySettings);
applicationEntity.setSettings(settings);
Application responseApplication = applicationMapper.convert(applicationEntity, uriInfo);
checkApplication(now, responseApplication, AppSettingsEnum.OAUTH_SETTINGS);
}
use of io.gravitee.rest.api.model.application.ApplicationSettings in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_CreateTest method shouldNotCreateBecauseClientRegistrationDisable.
@Test(expected = IllegalStateException.class)
public void shouldNotCreateBecauseClientRegistrationDisable() throws TechnicalException {
ApplicationSettings settings = new ApplicationSettings();
OAuthClientSettings clientSettings = new OAuthClientSettings();
clientSettings.setClientId(CLIENT_ID);
settings.setoAuthClient(clientSettings);
when(newApplication.getSettings()).thenReturn(settings);
when(parameterService.findAsBoolean(Key.APPLICATION_REGISTRATION_ENABLED, "DEFAULT", ParameterReferenceType.ENVIRONMENT)).thenReturn(Boolean.FALSE);
applicationService.create(newApplication, USER_NAME);
}
use of io.gravitee.rest.api.model.application.ApplicationSettings 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);
}
Aggregations