Skip to content

Create composite ReactiveAuthenticationManager #14521

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
franticticktick opened this issue Feb 1, 2024 · 8 comments · Fixed by #14591
Closed

Create composite ReactiveAuthenticationManager #14521

franticticktick opened this issue Feb 1, 2024 · 8 comments · Fixed by #14591
Assignees
Labels
in: core An issue in spring-security-core status: feedback-provided Feedback has been provided type: enhancement A general enhancement

Comments

@franticticktick
Copy link
Contributor

Need to make a composite ReactiveAuthenticationManager, for example CompositeReactiveAuthenticationManager, which contains a list of managers. The behavior should be approximately the same as that of ProviderManager - you need to iterate all the managers and use the first of the successful authentications as a result.

@franticticktick franticticktick added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Feb 1, 2024
franticticktick pushed a commit to franticticktick/spring-security that referenced this issue Feb 2, 2024
@jzheaux
Copy link
Contributor

jzheaux commented Feb 5, 2024

Have you already tried DelegatingReactiveAuthenticationManager?

@jzheaux jzheaux self-assigned this Feb 5, 2024
@jzheaux jzheaux added in: core An issue in spring-security-core status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 5, 2024
@franticticktick
Copy link
Contributor Author

Yes. DelegatingReactiveAuthenticationManager does not have the behavior that I need, since at the first failed authentication, flux exits. In my case, there are two authentication schemes and I need to iterate over both as in ProviderManager. There is currently no analogue of ProviderManager.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 6, 2024
@jzheaux
Copy link
Contributor

jzheaux commented Feb 9, 2024

I see. I wonder if it would be better to add a property to DelegatingReactiveAuthenticationManager like setContinueOnError. Would that work for you?

@franticticktick
Copy link
Contributor Author

Yes, I think this solution will work.

@franticticktick
Copy link
Contributor Author

In general, this idea is good, but it seems to me that it is impossible to implement it in DelegatingReactiveAuthenticationManager. Method authenticate will return the first successful authentication, but the stream will not move further. That is, there can be many delegates in the list and all will be discarded except the first one, which returns a non empty result.

@franticticktick
Copy link
Contributor Author

franticticktick commented Feb 12, 2024

If only something like this?

	public Mono<Authentication> authenticate(Authentication authentication) {
		if(continueOnError)
			return Flux.fromIterable(delegates)
					.concatMapDelayError(m -> m.authenticate(authentication)
							.doOnError(logger::debug)
					)
					.next();
		// @formatter:off
		return Flux.fromIterable(this.delegates)
				.concatMap((m) -> m.authenticate(authentication))
				.next();
		// @formatter:on
	}

@jzheaux
Copy link
Contributor

jzheaux commented Feb 12, 2024

Or, another way:

Flux<ReactiveAuthenticationManager> result = Flux.fromIterable(this.delegates);
Function<ReactiveAuthenticationManager, Mono<Authentication>> logging = 
        (m) -> m.authenticate(authentication).doOnError(logger::debug);
return ((this.continueOnError) ? result.concatMapDelayError(logging) : result.concatMap(logging)).next();

@jzheaux jzheaux added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Feb 12, 2024
franticticktick pushed a commit to franticticktick/spring-security that referenced this issue Feb 13, 2024
@franticticktick
Copy link
Contributor Author

Ok, I have opened a new PR.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 13, 2024
franticticktick pushed a commit to franticticktick/spring-security that referenced this issue Feb 13, 2024
…as been marked as non-static, setter method has been added for continueOnError flag, test have been refactored.

Closes spring-projectsgh-14521
franticticktick pushed a commit to franticticktick/spring-security that referenced this issue Feb 13, 2024
franticticktick pushed a commit to franticticktick/spring-security that referenced this issue Feb 13, 2024
franticticktick pushed a commit to franticticktick/spring-security that referenced this issue Feb 22, 2024
franticticktick pushed a commit to franticticktick/spring-security that referenced this issue Feb 24, 2024
jzheaux added a commit to franticticktick/spring-security that referenced this issue Feb 26, 2024
jzheaux added a commit that referenced this issue Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core An issue in spring-security-core status: feedback-provided Feedback has been provided type: enhancement A general enhancement
Projects
None yet
3 participants