Search in sources :

Example 16 with Permissions

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

the class GroupResource method updateGroup.

@PUT
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update an existing group")
@ApiResponses({ @ApiResponse(code = 200, message = "Group successfully updated", response = GroupEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_GROUP, acls = RolePermissionAction.UPDATE), @Permission(value = RolePermission.GROUP_MEMBER, acls = RolePermissionAction.UPDATE) })
public GroupEntity updateGroup(@ApiParam(name = "group", required = true) @Valid @NotNull final UpdateGroupEntity updateGroupEntity) {
    final GroupEntity groupEntity = checkRights();
    // check if user is a 'simple group admin' or a platform admin
    if (!permissionService.hasPermission(RolePermission.ENVIRONMENT_GROUP, GraviteeContext.getCurrentEnvironment(), CREATE, UPDATE, DELETE)) {
        updateGroupEntity.setMaxInvitation(groupEntity.getMaxInvitation());
        updateGroupEntity.setLockApiRole(groupEntity.isLockApiRole());
        updateGroupEntity.setLockApplicationRole(groupEntity.isLockApplicationRole());
        updateGroupEntity.setSystemInvitation(groupEntity.isSystemInvitation());
        updateGroupEntity.setEmailInvitation(groupEntity.isEmailInvitation());
        if (groupEntity.isLockApiRole()) {
            updateGroupEntity.getRoles().put(RoleScope.API, groupEntity.getRoles().get(RoleScope.API));
        }
        if (groupEntity.isLockApplicationRole()) {
            updateGroupEntity.getRoles().put(RoleScope.APPLICATION, groupEntity.getRoles().get(RoleScope.APPLICATION));
        }
    }
    return groupService.update(group, updateGroupEntity);
}
Also used : GroupEntity(io.gravitee.rest.api.model.GroupEntity) UpdateGroupEntity(io.gravitee.rest.api.model.UpdateGroupEntity) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 17 with Permissions

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

the class GroupResource method addGroupMember.

@POST
@Path("/memberships")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Associate a group to existing APIs or Applications")
@ApiResponses({ @ApiResponse(code = 200, message = "Group successfully updated", response = GroupEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_GROUP, acls = RolePermissionAction.UPDATE) })
public GroupEntity addGroupMember(@QueryParam("type") String type) {
    final GroupEntity groupEntity = checkRights();
    groupService.associate(group, type);
    return groupEntity;
}
Also used : GroupEntity(io.gravitee.rest.api.model.GroupEntity) UpdateGroupEntity(io.gravitee.rest.api.model.UpdateGroupEntity) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 18 with Permissions

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

the class GroupInvitationsResource method createGroupInvitation.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create an invitation to join a group", notes = "User must have the GROUP_INVITATION[CREATE] permission to use this service")
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_GROUP, acls = { UPDATE, CREATE }), @Permission(value = RolePermission.GROUP_INVITATION, acls = RolePermissionAction.CREATE) })
public InvitationEntity createGroupInvitation(@Valid @NotNull final NewInvitationEntity invitationEntity) {
    // Check that group exists
    final GroupEntity groupEntity = groupService.findById(group);
    // check if user is a 'simple group admin' or a platform admin
    final boolean hasPermission = permissionService.hasPermission(RolePermission.ENVIRONMENT_GROUP, GraviteeContext.getCurrentEnvironment(), CREATE, UPDATE, DELETE);
    if (!hasPermission) {
        if (groupEntity.getMaxInvitation() != null && groupService.getNumberOfMembers(group) >= groupEntity.getMaxInvitation()) {
            throw new GroupMembersLimitationExceededException(groupEntity.getMaxInvitation());
        }
        if (!groupEntity.isEmailInvitation()) {
            throw new GroupInvitationForbiddenException(EMAIL, group);
        }
    }
    invitationEntity.setReferenceType(GROUP);
    invitationEntity.setReferenceId(group);
    return invitationService.create(invitationEntity);
}
Also used : GroupMembersLimitationExceededException(io.gravitee.rest.api.service.exceptions.GroupMembersLimitationExceededException) GroupEntity(io.gravitee.rest.api.model.GroupEntity) GroupInvitationForbiddenException(io.gravitee.rest.api.service.exceptions.GroupInvitationForbiddenException) ApiOperation(io.swagger.annotations.ApiOperation) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 19 with Permissions

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

the class InstancesResource method getInstances.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List gateway instances")
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_INSTANCE, acls = RolePermissionAction.READ) })
public Page<InstanceListItem> getInstances(@BeanParam InstanceSearchParam param) {
    InstanceQuery query = new InstanceQuery();
    query.setIncludeStopped(param.isIncludeStopped());
    query.setFrom(param.getFrom());
    query.setTo(param.getTo());
    query.setPage(param.getPage());
    query.setSize(param.getSize());
    return instanceService.search(query);
}
Also used : InstanceQuery(io.gravitee.rest.api.model.InstanceQuery) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 20 with Permissions

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

the class PlatformEventsResource method getPlatformEvents.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List platform events", notes = "User must have the MANAGEMENT_PLATFORM[READ] permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Platform events", response = EventEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_PLATFORM, acls = RolePermissionAction.READ) })
public Page<EventEntity> getPlatformEvents(@BeanParam EventSearchParam eventSearchParam) {
    eventSearchParam.validate();
    Map<String, Object> properties = new HashMap<>();
    if (eventSearchParam.getApiIdsParam() != null && eventSearchParam.getApiIdsParam().getIds() != null && !eventSearchParam.getApiIdsParam().getIds().isEmpty()) {
        properties.put(Event.EventProperties.API_ID.getValue(), eventSearchParam.getApiIdsParam().getIds());
    } else if (!isAdmin()) {
        properties.put(Event.EventProperties.API_ID.getValue(), apiService.findByUser(getAuthenticatedUser(), null, false).stream().filter(api -> permissionService.hasPermission(API_ANALYTICS, api.getId(), READ)).map(ApiEntity::getId).collect(Collectors.joining(",")));
    }
    Page<EventEntity> events = eventService.search(eventSearchParam.getEventTypeListParam().getEventTypes(), properties, eventSearchParam.getFrom(), eventSearchParam.getTo(), eventSearchParam.getPage(), eventSearchParam.getSize());
    events.getContent().forEach(event -> {
        Map<String, String> properties1 = event.getProperties();
        // Event relative to API
        if (properties1 != null && properties1.containsKey(Event.EventProperties.API_ID.getValue())) {
            // Remove payload content from response since it's not required anymore
            event.setPayload(null);
            // Retrieve additional data
            String apiId = properties1.get(Event.EventProperties.API_ID.getValue());
            try {
                ApiEntity api = apiService.findById(apiId);
                properties1.put("api_name", api.getName());
                properties1.put("api_version", api.getVersion());
            } catch (ApiNotFoundException anfe) {
                properties1.put("deleted", Boolean.TRUE.toString());
                properties1.put("api_name", "Deleted API");
            }
        }
    });
    return events;
}
Also used : HashMap(java.util.HashMap) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) EventEntity(io.gravitee.rest.api.model.EventEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) Permissions(io.gravitee.rest.api.management.rest.security.Permissions) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Permissions (io.gravitee.rest.api.management.rest.security.Permissions)48 ApiOperation (io.swagger.annotations.ApiOperation)11 GET (javax.ws.rs.GET)7 Produces (javax.ws.rs.Produces)7 MediaEntity (io.gravitee.rest.api.model.MediaEntity)6 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)6 ApiResponses (io.swagger.annotations.ApiResponses)6 MediaType (io.gravitee.common.http.MediaType)5 Permission (io.gravitee.rest.api.management.rest.security.Permission)5 PageEntity (io.gravitee.rest.api.model.PageEntity)5 RolePermission (io.gravitee.rest.api.model.permissions.RolePermission)5 UpdatePageEntity (io.gravitee.rest.api.model.UpdatePageEntity)4 LogQuery (io.gravitee.rest.api.model.analytics.query.LogQuery)4 RolePermissionAction (io.gravitee.rest.api.model.permissions.RolePermissionAction)4 UploadUnauthorized (io.gravitee.rest.api.service.exceptions.UploadUnauthorized)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 InvalidImageException (io.gravitee.rest.api.exception.InvalidImageException)3 PagedResult (io.gravitee.rest.api.management.rest.model.PagedResult)3 GroupEntity (io.gravitee.rest.api.model.GroupEntity)3