-
Notifications
You must be signed in to change notification settings - Fork 6k
SAML: Add RequestedAuthnContext to AuthnRequest in OpenSamlAuthenticationRequestFactory #8141
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
Comments
Thanks for the suggestion, @Primedo. I think it makes sense to add support for custom attributes to Since What would you think of a |
Josh, thank you for your feedback. This is what I came up with until now and I hope it isn't the complete opposite of what you suggested: master...Primedo:gh-8141 I removed Since I didn't want to create a new What do you think, is this going in the right direction and what should I change? |
Thanks for taking some time to try this out, @Primedo. Let's see if it's possible to only focus on customizing the Regarding custom attributes, let's follow the pattern set out in As for a composite |
@jzheaux, what is your take on this change? I skipped the suggested |
I think I need to have a clearer idea on what inputs are determining what outputs. So far, I understand that you'd prefer to take something from the Can you elaborate on precisely what you are wanting to add to the |
I want the current user (anonymous or authenticated) to authenticate with an https://www.oasis-open.org/committees/download.php/35711/sstc-saml-core-errata-2.0-wd-06-diff.pdf Does this explain the requirement? |
Yes, that helps, @Primedo. When it's an authenticated user, are the details you need tied to the current |
Yes, that would work. And for anonymous users it would be helpful to have some context (cookie, URL, session or something else), so that the desired |
Do you have a concrete requirement here? Otherwise, maybe we wait on that aspect for now.
One thing you should be able to do then, which would require no enhancement at all, is for you to extend OpenSAML's |
An anonymous user is on the public site and wants to change his address. Since address change does require an authentication by id card or better this information should be transported to the IdP, otherwise the anonymous user would maybe have to authenticate twice with different methods.
Thanks, is this your preferred solution for this issue? |
Yes, @Primedo, if you can work with OpenSAML directly for your customization of the Of course, feel free to reopen this ticket if you run into trouble and want to take another look at changing |
This request was actually totally on point about limited support in the creation of AuthNRequests. |
To reiterate, I think it would be helpful to answer the following question:
|
I understand that SAML is currently on MVP state for Spring Security 5.2, but spring-security-saml is no longer supported, so 5.2 is the only valid option at the moment. Back to the issue, the goal as a developer using the framework is to be able to customize request creation without re-writing
Sample scenarios for this case would be:
|
@fpagliar good points, @Primedo as well, and I'm happy to have both of you as collaborators to help discover the right contract here. I agree that it will likely be helpful to modify the
@Primedo and I made some initial progress on these points. Building off of that progress, let me know what you both think of the following contract for the ForceAuthN use case (as it seems pretty simple). Most of this support doesn't exist yet, so it's just for illustration on what might be possible: @Bean
Saml2AuthenticationRequestContextResolver authenticationRequestContextResolver() {
Saml2AuthenticationRequestContextResolver delegate =
new DefaultSaml2AuthenticationRequestContextResolver();
return request -> {
Saml2AuthenticationRequestContext.Builder builder = delegate.resolve(request);
return builder.attribute("is-force-authn", request.getParameter("force"));
}
}
@Bean
Saml2AuthenticationRequestFactory authenticationRequestFactory() {
OpenSamlAuthenticationRequestFactory factory =
new OpenSamlAuthenticationRequestFactory();
factory.setAuthnRequestPostProcessor((context, authnRequest) -> {
if (StringUtils.hasText(context.getAttribute("is-force-authn"))) {
authnRequest.setForceAuthn(true);
}
});
return factory;
} The idea here is that the filter would call the The SAML 2.0 specification is obviously large and I'd prefer to manage I also like that this leaves all OpenSAML references inside of OpenSamlAuthenticationRequestFactory. It favors composition, which is nice. Do you believe this would address this use case as well as the others? Where do you see areas for improvement? |
Yes, and I agree upon managing
Just two cents, where I also find the other solution fine:
|
I think the overall strategy looks good. Although I think the current proposal with a string map of custom attributes is probably good enough for my current usecase. |
I think that the method name could take care of this, @Primedo. I'm thinking (Also note that I modified my sample above as I found a bug in it -- see if that also resolves your concern.)
That's a good point, we'd originally talked about it being a It depends on whether the application is constructing an The reason I proposed a
combined with the fact that if an application wants to customize the construction of an
I agree that this would be a nice thing to consider down the road, perhaps in a new component. As it is, the factory is at the service level so we don't want to have the I suppose an application could add the request as a custom attribute if they aren't concerned about leaking the request into the service layer. I don't think we'd want |
@fpagliar, I think this is a polish we could possibly do later on - I'd like to wait a bit before making That said, if you've got a concrete use case that's a great deal simpler with a custom context, then it's something worth considering. |
Regarding the other two items, I've created a ticket for adding the resolver next: #8360 The reason that this is next in priority is that it will address additional cases, like for custom implementations of I'm still analyzing the implications of exposing an |
This is definitely a step in the right direction, but I definitely feel like we need the post processor. |
It seems the ability to customize AuthnRequest which was added there, has been removed (or at least make more difficult) in 5.4.1 with af5c55c#diff-fc7cb5ee4992dc89c57d8930e6fcec7b4784e7f760ffe2480dce619f812e121e For example, before it was quite easy to customize set ForceAuthn
In latest version it is necessary to write a full AuthnRequest builder by copying code from private methods just to override few things that needed customization. |
@amergey, to clarify, this feature was added in 5.4.0 and did not change in 5.4.1. The API has remained the same since it GA'd in September.
Please see if #9209 simplifies what you are trying to do. In the meantime, several of the attributes that Spring Security sets are optional, so a copy/paste may bring in more than you need to maintain. For example, you can create a minimal OpenSamlAuthenticationRequestFactory factory = new OpenSamlAuthenticationRequestFactory();
factory.setAuthenticationRequestContextConverter((context) -> {
AuthnRequest request = authnRequestBuilder.buildObject();
request.setID("A" + UUID.randomUUID());
request.setIssueInstant(new DateTime());
request.setForceAuthn(true);
Issuer issuer = issuerBuilder.buildObject();
issuer.setValue(context.getIssuer());
request.setIssuer(issuer);
return request;
}); Or, you might find it easier to register a custom Note the reason that the API was released as a It also doesn't prevent the API in the future from adding a static method like OpenSamlAuthenticationRequestFactory factory = new OpenSamlAuthenticationRequestFactory();
factory.setAuthenticationRequestContextConverter(
createDefaultAuthenticationRequestContextConverter()
.andThen((authnRequest) -> authnRequest.setForceAuthn(true))
); You can read more about both of these points in this commit message. |
Summary
Add
RequestedAuthnContext
withComparison
andAuthnContextClassRef
to require a certain authentication from the IdP.Actual Behavior
OpenSamlAuthenticationRequestFactory
creates theAuthnRequest
with anSaml2AuthenticationRequest
, but isn't possible to modify theAuthnRequest
.Expected Behavior
Either transport the required information via
Saml2AuthenticationRequestContext
or allow the modification of the createdAuthnRequest
before it is serialized.Version
5.3.0-RELEASE
Additional Information
I am willing to work on this issue, but I am uncertain, what the expected direction could be. Personally I would prefer something like an
ObjectPostProcessor
where I would also have access to theHttpServletRequest
so I could adjust theAuthnRequest
according to the current user.The text was updated successfully, but these errors were encountered: