spring-projects / spring-projects/spring-security

Consider requireFactor for AuthorizationManagerFactories

Open
#18,061 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Related to https://github.com/spring-projects/spring-security/issues/18004

Currently, to specify a time-sensitive factor, it is needed to create an AuthorizationManagerFactory by way of a static factory that returns a builder:

var passwordIn30m = AuthorizationManagerFactories.multiFactor()
		.requireFactor( (factor) -> factor
			.passwordAuthority()
			.validDuration(Duration.ofMinutes(30))
		)
		.build();

This can then be used to create rules that include this factor as a basis:

http
		.authorizeHttpRequests((authorize) -> authorize
			.requestMatchers("/admin/**").access(passwordIn30m.hasRole("ADMIN"))
			.anyRequest().authenticated()
		)
		// ...

When just one factor is under consideration, this boilerplate could be reduced in a few ways. One way is to make it simpler to provide just one authority like so:

var passwordIn30m = AuthorizationManagerFactories.hasFactor(PASSWORD_AUTHORITY, Duration.ofMinutes(30));
http
		.authorizeHttpRequests((authorize) -> authorize
			.requestMatchers("/admin/**").access(passwordIn30m.hasRole("ADMIN"))
			.anyRequest().authenticated()
		)
		// ...

Or, AuthorizationManagerFactories could expose the individual authorities:

var passwordIn30m = AuthorizationManagerFactories.hasPasswordFactor((f) -> f.validDuration(Duration.ofMinutes(30)));
http
		.authorizeHttpRequests((authorize) -> authorize
			.requestMatchers("/admin/**").access(passwordIn30m.hasRole("ADMIN"))
			.anyRequest().authenticated()
		)
		// ...

I like the idea of having a simpler representation for a single factor since there are use cases other than multi-factor authentication when applications will want to require a time-sensitive factor in order to proceed.

NOTE: This ticket is marked as team-attention since we don't have a clear idea whether to go down any of these routes just yet.

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.

Research direction

Start with AuthorizationManagerFactories and read the related issue #18004 to understand the existing multi-factor factory and the unresolved alternatives. The work is not ready for implementation until the team chooses a single-factor API direction; done would mean implementing and validating that agreed design.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.