Skip to content

Support per method security requirement in RepositoryRestResource #1059

Closed
@bschoenmaeckers

Description

@bschoenmaeckers

Is your feature request related to a problem? Please describe.
I'm using spring-data-rest to export rest endpoints for a repository. This works great but the @securityrequirement annotation does only work on the class level. I would like to give each method a different security requirement.

Example:

@RepositoryRestResource(excerptProjection = UserBasicProjection.class)
public interface UserRepository extends JpaRepository<User, Long> {

    @Override
    @IsAuthenticated
    Optional<User> findById(Long id);

    @IsAuthenticated
    Optional<User> findOneByEmailAndDeletedIsFalse(String email);

    @Override
    @IsAdmin
    Page<User> findAll(Pageable pageable);

    @IsAdmin
    List<User> findByDebtIsGreaterThan(double debt);
 
    ....
}

@IsAdmin infers @SecurityRequirement(name = OAUTH2_SECURITY_SCHEME, scopes = "api_admin")
@IsAuthenticated infers @SecurityRequirement(name = OAUTH2_SECURITY_SCHEME, scopes = "api_full")

Describe the solution you'd like

The DataRestTagsService should check the actual repository method in addition to the repository type.

Set<io.swagger.v3.oas.annotations.security.SecurityRequirement> allSecurityTags = securityParser.getSecurityRequirementsForClass(repositoryType);

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions