Search in sources :

Example 1 with SimpleApplicationSettings

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();
}
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 SimpleApplicationSettings

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);
}
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 SimpleApplicationSettings

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);
}
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) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with SimpleApplicationSettings

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;
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) Group(io.gravitee.rest.api.portal.rest.model.Group) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) GroupService(io.gravitee.rest.api.service.GroupService) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) User(io.gravitee.rest.api.portal.rest.model.User) Collectors(java.util.stream.Collectors) Application(io.gravitee.rest.api.portal.rest.model.Application) List(java.util.List) Component(org.springframework.stereotype.Component) OffsetDateTime(java.time.OffsetDateTime) UserService(io.gravitee.rest.api.service.UserService) ZoneOffset(java.time.ZoneOffset) UriInfo(javax.ws.rs.core.UriInfo) PortalApiLinkHelper.usersURL(io.gravitee.rest.api.portal.rest.utils.PortalApiLinkHelper.usersURL) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) ApplicationLinks(io.gravitee.rest.api.portal.rest.model.ApplicationLinks) Group(io.gravitee.rest.api.portal.rest.model.Group) User(io.gravitee.rest.api.portal.rest.model.User) UserEntity(io.gravitee.rest.api.model.UserEntity) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) 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)

Example 5 with SimpleApplicationSettings

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();
}
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) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) UpdateApplicationEntity(io.gravitee.rest.api.model.UpdateApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Application(io.gravitee.rest.api.portal.rest.model.Application) UpdateApplicationEntity(io.gravitee.rest.api.model.UpdateApplicationEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Aggregations

ApplicationSettings (io.gravitee.rest.api.model.application.ApplicationSettings)15 SimpleApplicationSettings (io.gravitee.rest.api.model.application.SimpleApplicationSettings)15 Test (org.junit.Test)8 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)7 OAuthClientSettings (io.gravitee.rest.api.model.application.OAuthClientSettings)4 HashMap (java.util.HashMap)4 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)3 NewApplicationEntity (io.gravitee.rest.api.model.NewApplicationEntity)3 UpdateApplicationEntity (io.gravitee.rest.api.model.UpdateApplicationEntity)3 Application (io.gravitee.rest.api.portal.rest.model.Application)3 UserService (io.gravitee.rest.api.service.UserService)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 RoleEntity (io.gravitee.rest.api.model.RoleEntity)2 UserEntity (io.gravitee.rest.api.model.UserEntity)2 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)2