Search in sources :

Example 11 with Permissions

use of io.gravitee.rest.api.portal.rest.security.Permissions 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)

Example 12 with Permissions

use of io.gravitee.rest.api.portal.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.

the class ApplicationResource method getApplicationType.

@GET
@Path("configuration")
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_DEFINITION, acls = RolePermissionAction.READ) })
public Response getApplicationType(@PathParam("applicationId") String applicationId) {
    ApplicationEntity applicationEntity = applicationService.findById(applicationId);
    ApplicationTypeEntity applicationType = applicationTypeService.getApplicationType(applicationEntity.getType());
    return Response.ok(applicationType).build();
}
Also used : ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) UpdateApplicationEntity(io.gravitee.rest.api.model.UpdateApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 13 with Permissions

use of io.gravitee.rest.api.portal.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.

the class ApplicationsResource method createApplication.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_APPLICATION, acls = RolePermissionAction.CREATE) })
public Response createApplication(@Valid @NotNull(message = "Input must not be null.") ApplicationInput applicationInput) {
    NewApplicationEntity newApplicationEntity = new NewApplicationEntity();
    newApplicationEntity.setDescription(applicationInput.getDescription());
    newApplicationEntity.setGroups(applicationInput.getGroups() != null ? new HashSet<>(applicationInput.getGroups()) : new HashSet<>());
    newApplicationEntity.setName(applicationInput.getName());
    newApplicationEntity.setPicture(applicationInput.getPicture());
    final io.gravitee.rest.api.portal.rest.model.ApplicationSettings settings = applicationInput.getSettings();
    ApplicationSettings newApplicationEntitySettings = new ApplicationSettings();
    if (settings == null || (settings.getApp() == null && settings.getOauth() == null)) {
        newApplicationEntity.setSettings(newApplicationEntitySettings);
    } else {
        final io.gravitee.rest.api.portal.rest.model.SimpleApplicationSettings simpleAppInput = settings.getApp();
        if (simpleAppInput != null) {
            SimpleApplicationSettings sas = new SimpleApplicationSettings();
            sas.setClientId(simpleAppInput.getClientId());
            sas.setType(simpleAppInput.getType());
            newApplicationEntitySettings.setApp(sas);
        }
        final io.gravitee.rest.api.portal.rest.model.OAuthClientSettings oauthAppInput = settings.getOauth();
        if (oauthAppInput != null) {
            OAuthClientSettings ocs = new OAuthClientSettings();
            ocs.setApplicationType(oauthAppInput.getApplicationType());
            ocs.setGrantTypes(oauthAppInput.getGrantTypes());
            ocs.setRedirectUris(oauthAppInput.getRedirectUris());
            newApplicationEntitySettings.setoAuthClient(ocs);
        }
    }
    newApplicationEntity.setSettings(newApplicationEntitySettings);
    ApplicationEntity createdApplicationEntity = applicationService.create(newApplicationEntity, getAuthenticatedUser());
    return Response.created(this.getLocationHeader(createdApplicationEntity.getId())).entity(applicationMapper.convert(createdApplicationEntity, uriInfo)).build();
}
Also used : NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) 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) NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 14 with Permissions

use of io.gravitee.rest.api.portal.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.

the class ApplicationAlertsResource method createApplicationAlert.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_ALERT, acls = RolePermissionAction.CREATE) })
public Response createApplicationAlert(@PathParam("applicationId") String applicationId, @Valid @NotNull(message = "Input must not be null.") AlertInput alertInput) {
    checkPlugins();
    if (applicationAlertService.findByApplication(applicationId).size() == 10) {
        throw new ApplicationAlertMaximumException(applicationId, 10);
    }
    final NewAlertTriggerEntity newAlertTriggerEntity = alertMapper.convert(alertInput);
    final AlertTriggerEntity alert = applicationAlertService.create(applicationId, newAlertTriggerEntity);
    return Response.created(this.getLocationHeader(alert.getId())).entity(alertMapper.convert(alert)).build();
}
Also used : ApplicationAlertMaximumException(io.gravitee.rest.api.service.exceptions.ApplicationAlertMaximumException) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) AlertTriggerEntity(io.gravitee.rest.api.model.alert.AlertTriggerEntity) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 15 with Permissions

use of io.gravitee.rest.api.portal.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.

the class ApplicationMetadataResource method createApplicationMetadata.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_METADATA, acls = RolePermissionAction.CREATE) })
public Response createApplicationMetadata(@PathParam("applicationId") String applicationId, @Valid @NotNull final ReferenceMetadataInput metadata) {
    // prevent creation of a metadata on an another APPLICATION
    NewApplicationMetadataEntity newApplicationMetadataEntity = this.referenceMetadataMapper.convert(metadata, applicationId);
    final ApplicationMetadataEntity applicationMetadataEntity = metadataService.create(newApplicationMetadataEntity);
    return Response.created(this.getLocationHeader(applicationMetadataEntity.getKey())).entity(this.referenceMetadataMapper.convert(applicationMetadataEntity)).build();
}
Also used : NewApplicationMetadataEntity(io.gravitee.rest.api.model.NewApplicationMetadataEntity) UpdateApplicationMetadataEntity(io.gravitee.rest.api.model.UpdateApplicationMetadataEntity) ApplicationMetadataEntity(io.gravitee.rest.api.model.ApplicationMetadataEntity) NewApplicationMetadataEntity(io.gravitee.rest.api.model.NewApplicationMetadataEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Aggregations

Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)20 RatingEntity (io.gravitee.rest.api.model.RatingEntity)5 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)5 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)5 ApiNotFoundException (io.gravitee.rest.api.service.exceptions.ApiNotFoundException)5 RatingNotFoundException (io.gravitee.rest.api.service.exceptions.RatingNotFoundException)4 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)3 MemberEntity (io.gravitee.rest.api.model.MemberEntity)3 Produces (javax.ws.rs.Produces)3 InlinePictureEntity (io.gravitee.rest.api.model.InlinePictureEntity)2 UpdateApplicationEntity (io.gravitee.rest.api.model.UpdateApplicationEntity)2 UpdateRatingEntity (io.gravitee.rest.api.model.UpdateRatingEntity)2 AlertTriggerEntity (io.gravitee.rest.api.model.alert.AlertTriggerEntity)2 ApplicationSettings (io.gravitee.rest.api.model.application.ApplicationSettings)2 OAuthClientSettings (io.gravitee.rest.api.model.application.OAuthClientSettings)2 SimpleApplicationSettings (io.gravitee.rest.api.model.application.SimpleApplicationSettings)2 PortalNotificationConfigEntity (io.gravitee.rest.api.model.notification.PortalNotificationConfigEntity)2 MembershipService (io.gravitee.rest.api.service.MembershipService)2 SinglePrimaryOwnerException (io.gravitee.rest.api.service.exceptions.SinglePrimaryOwnerException)2 Consumes (javax.ws.rs.Consumes)2