I am using Spring MVC, Spring security for our web application. After successful login the request gets redirected to a HTML page (login.html). We have about 4 AJAX calls that are executed then after using Ext-JS.
I have a requirement to send JSON data after successful login. What this means is the JSON data has to be passed on to the client along with the login page. And on the login page we need to access this JSON data and render it. Frankly this is the same data which requested by the Ext-JS code on the login.html page. The goal is to avoid additional requests by AJAX call.
I tried out various examples on stackoverflow and other websites (just avoiding mention, to prevent cluttering) and created a custom authentication handler, and made changes appropriately. Everything works fine but not a way to send JSON/any data to client.
The below are the configurations of application-context.xml
<http auto-config="false" use-expressions="true">
<form-login login-page="/login"
login-processing-url="/static/j_spring_security_check"
authentication-failure-url="/login?login_error=t"
authentication-success-handler-ref="customAuthHandler"
authentication-failure-handler-ref="customAuthHandler"
default-target-url="/html/index.html"
always-use-default-target="true"/>
<beans:bean id="customAuthHandler"
class="com.mycompany.security.CustomAuthenticationHandler"/>
On the onAuthenticationSuccess method in CustomAuthenticationHandler I have the following code to see if I could get this value, but I could not. What I understand is since its a HTML/static content I can't pass session value to client and that needs to be a JSP. (Please correct me if wrong!) I can't change the HTML to JSP for bureaucratic reasons:
Test 1:
request.getSession(true).setAttribute("ssntest", "hello:how:are:you");
Test 2:
HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response);
Writer out = responseWrapper.getWriter();
String targetUrl = "/login";
out.write("{success:true, targetUrl : \'" + targetUrl + "\'}");
out.close();
What would be a way to pass JSON value on successful authentication along with HTML.