use of io.gravitee.rest.api.model.application.ApplicationSettings in project gravitee-management-rest-api by gravitee-io.
the class ApplicationsResourceTest method shouldCreateApplicationWithSimpleSettings.
@Test
public void shouldCreateApplicationWithSimpleSettings() {
ApplicationInput input = new ApplicationInput().description(APPLICATION).groups(Arrays.asList(APPLICATION)).name(APPLICATION);
SimpleApplicationSettings sas = new SimpleApplicationSettings().clientId(APPLICATION).type(APPLICATION);
input.setSettings(new io.gravitee.rest.api.portal.rest.model.ApplicationSettings().app(sas));
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);
final io.gravitee.rest.api.model.application.SimpleApplicationSettings app = settings.getApp();
assertNotNull(app);
assertEquals(APPLICATION, app.getClientId());
assertEquals(APPLICATION, app.getType());
assertNull(settings.getoAuthClient());
Application createdApp = response.readEntity(Application.class);
assertNotNull(createdApp);
assertEquals("NEW", createdApp.getId());
}
use of io.gravitee.rest.api.model.application.ApplicationSettings in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_UpdateTest method shouldUpdate.
@Test
public void shouldUpdate() throws TechnicalException {
ApplicationSettings settings = new ApplicationSettings();
SimpleApplicationSettings clientSettings = new SimpleApplicationSettings();
clientSettings.setClientId(CLIENT_ID);
settings.setApp(clientSettings);
when(existingApplication.getSettings()).thenReturn(settings);
when(applicationRepository.findById(APPLICATION_ID)).thenReturn(Optional.of(application));
when(application.getName()).thenReturn(APPLICATION_NAME);
when(application.getStatus()).thenReturn(ApplicationStatus.ACTIVE);
when(existingApplication.getName()).thenReturn(APPLICATION_NAME);
when(existingApplication.getDescription()).thenReturn("My description");
when(application.getType()).thenReturn(ApplicationType.SIMPLE);
when(applicationRepository.update(any())).thenReturn(application);
when(roleService.findPrimaryOwnerRoleByOrganization(any(), any())).thenReturn(mock(RoleEntity.class));
MembershipEntity po = new MembershipEntity();
po.setMemberId(USER_NAME);
po.setMemberType(MembershipMemberType.USER);
po.setReferenceId(APPLICATION_ID);
po.setReferenceType(MembershipReferenceType.APPLICATION);
po.setRoleId("APPLICATION_PRIMARY_OWNER");
when(membershipService.getMembershipsByReferencesAndRole(any(), any(), any())).thenReturn(Collections.singleton(po));
final ApplicationEntity applicationEntity = applicationService.update(APPLICATION_ID, existingApplication);
verify(applicationRepository).update(argThat(application -> APPLICATION_NAME.equals(application.getName()) && application.getUpdatedAt() != null));
assertNotNull(applicationEntity);
assertEquals(APPLICATION_NAME, applicationEntity.getName());
}
use of io.gravitee.rest.api.model.application.ApplicationSettings in project gravitee-management-rest-api by gravitee-io.
the class ApplicationResource method updateApplication.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update an application", notes = "User must have APPLICATION_DEFINITION[UPDATE] permission to update an application.")
@ApiResponses({ @ApiResponse(code = 200, message = "Updated application", response = ApplicationEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_DEFINITION, acls = RolePermissionAction.UPDATE) })
public ApplicationEntity updateApplication(@Valid @NotNull(message = "An application must be provided") final UpdateApplicationEntity updatedApplication) {
// To preserve backward compatibility, ensure that we have at least default settings for simple application type
if (updatedApplication.getSettings() == null || (updatedApplication.getSettings().getoAuthClient() == null && updatedApplication.getSettings().getApp() == null)) {
ApplicationSettings settings = new ApplicationSettings();
SimpleApplicationSettings simpleAppSettings = new SimpleApplicationSettings();
simpleAppSettings.setType(updatedApplication.getType());
simpleAppSettings.setClientId(updatedApplication.getClientId());
updatedApplication.setSettings(settings);
}
return applicationService.update(application, updatedApplication);
}
use of io.gravitee.rest.api.model.application.ApplicationSettings 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;
}
use of io.gravitee.rest.api.model.application.ApplicationSettings in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_CreateTest method shouldNotCreateBecauseGrantTypesIsNotAllowed.
@Test(expected = ApplicationGrantTypesNotAllowedException.class)
public void shouldNotCreateBecauseGrantTypesIsNotAllowed() {
ApplicationSettings settings = new ApplicationSettings();
OAuthClientSettings clientSettings = new OAuthClientSettings();
clientSettings.setApplicationType("web");
clientSettings.setGrantTypes(Arrays.asList("foobar"));
settings.setoAuthClient(clientSettings);
ApplicationTypeEntity applicationType = mock(ApplicationTypeEntity.class);
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