Search in sources :

Example 1 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.

/**
 * 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();
}
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) NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 2 with ApplicationSettings

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);
}
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) Application(io.gravitee.rest.api.portal.rest.model.Application) Test(org.junit.Test)

Example 3 with ApplicationSettings

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);
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) Application(io.gravitee.rest.api.portal.rest.model.Application) Test(org.junit.Test)

Example 4 with ApplicationSettings

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);
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) Test(org.junit.Test)

Example 5 with ApplicationSettings

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);
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) ApplicationGrantTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationGrantTypeEntity) 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