use of io.gravitee.rest.api.model.application.SimpleApplicationSettings 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.SimpleApplicationSettings 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.SimpleApplicationSettings in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_CreateTest method shouldNotCreateBecauseClientIdExists.
@Test(expected = ClientIdAlreadyExistsException.class)
public void shouldNotCreateBecauseClientIdExists() throws TechnicalException {
Map<String, String> metadata = new HashMap<>();
metadata.put("client_id", CLIENT_ID);
when(application.getMetadata()).thenReturn(metadata);
ApplicationSettings settings = new ApplicationSettings();
SimpleApplicationSettings clientSettings = new SimpleApplicationSettings();
clientSettings.setClientId(CLIENT_ID);
settings.setApp(clientSettings);
when(newApplication.getSettings()).thenReturn(settings);
when(applicationRepository.findAllByEnvironment("DEFAULT", ApplicationStatus.ACTIVE)).thenReturn(Collections.singleton(application));
applicationService.create(newApplication, USER_NAME);
}
use of io.gravitee.rest.api.model.application.SimpleApplicationSettings in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMapper method convert.
public Application convert(ApplicationEntity applicationEntity, UriInfo uriInfo) {
final Application application = new Application();
application.setApplicationType(applicationEntity.getType());
application.setCreatedAt(applicationEntity.getCreatedAt().toInstant().atOffset(ZoneOffset.UTC));
application.setDescription(applicationEntity.getDescription());
Set<String> groupEntities = applicationEntity.getGroups();
if (groupEntities != null && !groupEntities.isEmpty()) {
List<Group> groups = groupEntities.stream().map(groupService::findById).map(groupEntity -> new Group().id(groupEntity.getId()).name(groupEntity.getName())).collect(Collectors.toList());
application.setGroups(groups);
}
application.setId(applicationEntity.getId());
application.setName(applicationEntity.getName());
UserEntity primaryOwnerUserEntity = userService.findById(applicationEntity.getPrimaryOwner().getId());
User owner = userMapper.convert(primaryOwnerUserEntity);
owner.setLinks(userMapper.computeUserLinks(usersURL(uriInfo.getBaseUriBuilder(), primaryOwnerUserEntity.getId()), primaryOwnerUserEntity.getUpdatedAt()));
application.setOwner(owner);
application.setUpdatedAt(applicationEntity.getUpdatedAt().toInstant().atOffset(ZoneOffset.UTC));
application.setPicture(applicationEntity.getPicture());
application.setBackground(applicationEntity.getBackground());
final ApplicationSettings applicationEntitySettings = applicationEntity.getSettings();
if (applicationEntitySettings != null) {
io.gravitee.rest.api.portal.rest.model.ApplicationSettings appSettings = new io.gravitee.rest.api.portal.rest.model.ApplicationSettings();
final SimpleApplicationSettings simpleAppEntitySettings = applicationEntitySettings.getApp();
if (simpleAppEntitySettings != null) {
appSettings.app(new io.gravitee.rest.api.portal.rest.model.SimpleApplicationSettings().clientId(simpleAppEntitySettings.getClientId()).type(simpleAppEntitySettings.getType()));
application.setHasClientId(simpleAppEntitySettings.getClientId() != null);
} else {
final OAuthClientSettings oAuthClientEntitySettings = applicationEntitySettings.getoAuthClient();
appSettings.oauth(new io.gravitee.rest.api.portal.rest.model.OAuthClientSettings().applicationType(oAuthClientEntitySettings.getApplicationType()).clientId(oAuthClientEntitySettings.getClientId()).clientSecret(oAuthClientEntitySettings.getClientSecret()).clientUri(oAuthClientEntitySettings.getClientUri()).logoUri(oAuthClientEntitySettings.getLogoUri()).grantTypes(oAuthClientEntitySettings.getGrantTypes()).redirectUris(oAuthClientEntitySettings.getRedirectUris()).responseTypes(oAuthClientEntitySettings.getResponseTypes()).renewClientSecretSupported(oAuthClientEntitySettings.isRenewClientSecretSupported()));
application.setHasClientId(oAuthClientEntitySettings.getClientId() != null);
}
application.setSettings(appSettings);
}
return application;
}
use of io.gravitee.rest.api.model.application.SimpleApplicationSettings 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();
}
Aggregations