Skip to content
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

SAML2 customizable URLs #8873

Closed
JoakimLofgren opened this issue Jul 23, 2020 · 14 comments
Closed

SAML2 customizable URLs #8873

JoakimLofgren opened this issue Jul 23, 2020 · 14 comments
Assignees
Labels
in: saml2 An issue in SAML2 modules type: enhancement A general enhancement

Comments

@JoakimLofgren
Copy link
Contributor

Expected Behavior

I want to be able to change all SAML2 URLs to be able to e.g. add a prefix.

Current Behavior

Some URLs are customizable, like Saml2LoginConfigurer.loginProcessingUrl.
While some are not, e.g. Saml2LoginConfigurer.AuthenticationRequestEndpointConfig.filterProcessingUrl (/saml2/authenticate/{registrationId}).

Context

A workaround for adding a path prefix is using the server.servlet.context-path.
But this doesn't work if you want to tweak URLs to be similar to an already existing solution created with the old SAML module.

Although assuming you want /auth as a prefix, and after login you want to redirect to the root / and not /auth/,
you cannot use the default success handler. You need to create a custom one with a redirect strategy which is not context relative.

@JoakimLofgren JoakimLofgren added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Jul 23, 2020
@jzheaux
Copy link
Contributor

jzheaux commented Jul 23, 2020

@JoakimLofgren I think it makes sense to simplify configuring the URL for creating an AuthnRequest.

If we follow the pattern established in OAuth2LoginConfigurer, I think most decisions will be fairly straightforward. For example, it would be nice to do:

http
    .saml2Login(saml2 -> saml2
        .authenticationRequestEndpoint(authn -> authn
            .baseUri(myCustomUri)
        )
    );

Then that would be quite similar to:

http
    .oauth2Login(oauth2 -> oauth2
        .authorizationEndpoint(authz -> authz
            .baseUri(myCustomUri)
        )
    );

Would you be able to submit a PR along those lines to enhance the DSL? It would also be quite nice to update the Kotlin DSL while you are at it.

@jzheaux jzheaux self-assigned this Jul 23, 2020
@jzheaux jzheaux added in: saml2 An issue in SAML2 modules 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 Jul 23, 2020
@JoakimLofgren
Copy link
Contributor Author

Sure. After #8864 is finished.

@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 Jul 29, 2020
@jzheaux
Copy link
Contributor

jzheaux commented Dec 3, 2020

After a bit more experimentation with it, I think the following is easier to read:

http
    .saml2Login(saml2 -> saml2
        .loginProcessingUrl("/saml2/response/{registrationId}")
        .authenticationRequestUri("/saml2/request/{registrationId}")
    );

I like it because it has less hierarchy.

@jzheaux
Copy link
Contributor

jzheaux commented Dec 3, 2020

@JoakimLofgren are you still able to contribute a PR to add support for configuring the Saml2WebSsoAuthenticationRequestFilter URI?

@jzheaux jzheaux added the status: ideal-for-contribution An issue that we actively are looking for someone to help us with label Dec 15, 2020
@chelseakohli
Copy link

Hey, I am kind of stuck on being not able to change default entityId & replyUrl in AuthRequest. My SP is running on http, so the urls for entityId & replyUrl are being generated for http. But by making some firewall changes, publicly website access is only by https. So basically I want the urls in AuthRequest to be https.

@jzheaux
Copy link
Contributor

jzheaux commented Apr 21, 2021

@chelseakohli, this would probably be better as a StackOverflow question, so please consider posting there if my answer here doesn't address your question and also update your comment with the StackOverflow link.

You can customize the AuthnRequest by configuring the OpenSamlAuthenticationRequestFactory:

@Bean 
Saml2AuthenticationRequestFactory authenticationRequestFactory() {
    OpenSamlAuthenticationRequestFactory factory =
            new OpenSamlAuthenticationRequestFactory();
    factory.setAuthenticationRequestContextConverter((context) -> {
        // construct the AuthnRequest
    });
}

@fr2lancer
Copy link

Hi.

Is any updates on this? Seems like the suggestions above hasn't been applied to 5.6.0-RC yet..

Any workaround on this ?(e.g. using withObjectPostProcessor ?)

Thank you.

@denis111
Copy link

denis111 commented Dec 7, 2021

@fr2lancer
I had to use reflection and ObjectPostProcessor for workaround inside configure(http) method:

Field parent = ReflectionUtils.findField(saml.getClass(), "authenticationRequestEndpoint");
      parent.setAccessible(true);
      Field child = ReflectionUtils.findField(parent.getType(), "filterProcessingUrl");
      child.setAccessible(true);
      ReflectionUtils.setField(child, ReflectionUtils.getField(parent, saml),
          SAML_PATH + "/login");
      parent.setAccessible(false);
      child.setAccessible(false);
      saml.addObjectPostProcessor(
          new ObjectPostProcessor<Saml2WebSsoAuthenticationRequestFilter>() {
            @Override
            public <O extends Saml2WebSsoAuthenticationRequestFilter> O postProcess(O object) {
              object.setRedirectMatcher(new AntPathRequestMatcher(SAML_PATH + "/login"));
              return object;
            }
          });

@denis111
Copy link

denis111 commented Dec 9, 2021

Could we also have this fields customizable?

private final RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();

Because we want to make logout requests by ajax post and JS can't control 302 redirects.

@jzheaux
Copy link
Contributor

jzheaux commented Feb 15, 2022

@denis111 please log a separate issue regarding customizing the redirect strategy.

@bramhaag
Copy link

Any progress?

@jzheaux
Copy link
Contributor

jzheaux commented Feb 18, 2022

While some are not, e.g. Saml2LoginConfigurer.AuthenticationRequestEndpointConfig.filterProcessingUrl (/saml2/authenticate/{registrationId})

@JoakimLofgren, I've created #10840 to specifically address the authentication request URI. Are there any other endpoints that you would like to see addressed? If not, I'll close this issue in favor of #10840.

@jzheaux jzheaux added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided status: ideal-for-contribution An issue that we actively are looking for someone to help us with labels Feb 18, 2022
@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Feb 25, 2022
@JoakimLofgren
Copy link
Contributor Author

Sounds good. 👍

houssemba added a commit to houssemba/spring-security that referenced this issue Jun 5, 2022
@jzheaux jzheaux removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Jun 6, 2022
@jzheaux jzheaux added this to the 6.0.0-M6 milestone Jun 6, 2022
@jzheaux jzheaux removed this from the 6.0.0-M6 milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: saml2 An issue in SAML2 modules type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

7 participants