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

Should commence method of CasAuthenticationEntryPoint must be a final method? #4990

Closed
silenceshell opened this issue Feb 2, 2018 · 2 comments
Assignees

Comments

@silenceshell
Copy link

Summary

Should commence method of CasAuthenticationEntryPoint must be a final method?

If the request is from ajax after session expired, the current commence method will send code 302 to browser, and browser will try to redirect to the cas login page. BUT if the cas server is not at the same domain as the application, browser will deny the request because of same-origin policy.

In the issue #2999 , Rob Winch shows an example to solve this problem:

public class CustomLoginUrlAuthenticationEntryPoint implements LoginUrlAuthenticationEntryPoint {

   public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
            throws IOException, ServletException {

    if(ajaxRedirect) {
      // do ajax handling
    } else {
      loginUrlAuthenticationEntryPoint.commence(request,response,authException);
    }
}

This is nice, but the commence method of CasAuthenticationEntryPoint is final and I can not override it .

	public final void commence(final HttpServletRequest servletRequest,
			final HttpServletResponse response,
			final AuthenticationException authenticationException) throws IOException,
			ServletException {

		final String urlEncodedService = createServiceUrl(servletRequest, response);
		final String redirectUrl = createRedirectUrl(urlEncodedService);

		preCommence(servletRequest, response);

		response.sendRedirect(redirectUrl);
	}

So, maybe commence method of CasAuthenticationEntryPoint could remove the final ?

@rwinch
Copy link
Member

rwinch commented Feb 5, 2018

In general, you should favor composition over inheritance. Why do you need to override the method? Does it provide any additional value?

@rwinch rwinch self-assigned this Feb 5, 2018
@rwinch rwinch added the status: waiting-for-feedback We need additional information before we can continue label Feb 5, 2018
@silenceshell
Copy link
Author

ok, I will use composition to wrap CasAuthenticationEntryPoint.
Thank you ~!

@rwinch rwinch removed the status: waiting-for-feedback We need additional information before we can continue label Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants