0

I have an application, where user is pre-authorized by SSO and lands to my page, now I need to make a call to another rest api to get some data, which is running on another server, but it will be use the same authentication. So I just wanted to know, how I can provide the authentication process? Do I need to set the cookie what I am getting from the incoming request.

Diwakar
  • 1
  • 3

1 Answers1

0

When the request lands on your page it should have a token or key, in the http AUTHORIZATION header, this should be used with a filter

public class AuthFilter extends OncePerRequestFilter {

private String failureUrl;

private SimpleUrlAuthenticationFailureHandler failureHandler = new SimpleUrlAuthenticationFailureHandler();

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws ServletException, IOException {

    try {
        // check your SSO token here
        chain.doFilter(request, response);
    } catch (OnlineDriverEnquiryException ode) {
        failureHandler.setDefaultFailureUrl(failureUrl);
        failureHandler.onAuthenticationFailure(request, response, new BadCredentialsException("Captcha invalid!"));
    }
}

public String getFailureUrl() {

    return failureUrl;
}

public void setFailureUrl(String failureUrl) {

    this.failureUrl = failureUrl;
}

}

Also read this post on how to set up the auto config. Spring security without form login

Community
  • 1
  • 1
Essex Boy
  • 7,565
  • 2
  • 21
  • 24