Skip to content

Support per method security requirement in RepositoryRestResource #1059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bschoenmaeckers opened this issue Feb 12, 2021 · 2 comments
Closed
Labels
enhancement New feature or request

Comments

@bschoenmaeckers
Copy link

bschoenmaeckers commented Feb 12, 2021

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

@bnasslahsen
Copy link
Collaborator

@bschoenmaeckers,

The support is now added.
You can test it using the latest snapshot.

@bschoenmaeckers
Copy link
Author

Works as expected. Thanks!

This was referenced Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants