spring-projects / spring-projects/spring-security

Create SqlAllAuthoritiesAuthorizationManager

Open
#17,963 3 comments 0 reactions 1 assignee View on GitHub

@therepanic is already working on this.

Since Sep 26, 2025.

in: core status: ideal-for-contribution type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

We should create an AuthorizationManager that can lookup authorities using a configured SQL statement given the username of the currently authenticated user. If any values are returned, then it returns those authorities otherwise it grants access to the user.

Pseudo code looks like:


List<String> additionalAuthorities = findAdditionalAuthorities(authentication.get().getName()); // lookup from SQL statement
if (additionalAuthorities.isEmpty() {
    return new AccessDecision(true);
}
else {
    return AllAuthoritiesAuthorizationManager.hasAllAuthorities(additionalAuthorities).authorize(authentication, object);
}

NOTE: findAdditionalAuthorities should use a mapper object of sorts that can swap out. It can return some constants if the SQL returns true or it can lookup the additional authorities in SQL.

This can then be used for situations where it is a user preference to enable multi-factor authentication. We should also update the documentation to show how to use it. Something like this:

AuthorizationManager<Object> additionalAuthorization =  SqlAllAuthoritiesAuthorizationManager
    .whenTrue("select true from users where mfa_enabled = true and username = :username")
    .additionalAuthorities("FACTOR_PASSWORD", "FACTOR_OTT")
    .dataSource(dataSource)
    .build()

return new DefaultAuthorizationManagerFactory.build()
    .additionalAuthorization(additionalAuthorization)
    .build();

an additional option for users that gets the authorities from SQL:

AuthorizationManager<Object> additionalAuthorization =  SqlAllAuthoritiesAuthorizationManager
    .selectAuthorities("select authorities from additional_authorities where username = :username")
    .dataSource(dataSource)
    .build()

return new DefaultAuthorizationManagerFactory.build()
    .additionalAuthorization(additionalAuthorization)
    .build();

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.