I'm developing an application using Extjs-6 with Spring 4. My Application is Restful.
I enable CORS Origin as follow:
public class CorsFilter extends OncePerRequestFilter {
private static final String ORIGIN = "Origin";
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
response.addHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Credentials", "true");
response.addHeader("Access-Control-Max-Age", "10");
String reqHead = request.getHeader("Access-Control-Request-Headers");
if (!StringUtils.isEmpty(reqHead)) {
response.addHeader("Access-Control-Allow-Headers", reqHead);
}
if (request.getMethod().equals("OPTIONS")) {
try {
response.getWriter().print("OK");
response.getWriter().flush();
} catch (IOException e) {
e.printStackTrace();
}
} else{
filterChain.doFilter(request, response);
}
}
}
Filter config:
<security:http use-expressions="true">
...
<sec:custom-filter ref="CorsFilter" before="HEADERS_FILTER"/>
</security:http>
And the Bean:
<bean id="CorsFilter" class="..." />
I want to users loging with an AJAX request. I test ajax request using Advanced REST client and http requester. Results of extensions are as follow:
Ext Ajax request code is as follow:
Ext.Ajax.request({
url: "http://localhost/Calk/j_spring_security_check",
// params: {
// "j_username": "ali",
// "j_password": "123456"
// },
params: "j_username=ali&j_password=123456",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST",
success: function(){...},
failure: function(){...}
});
When I send the request, it get 200 OK, and I init the application in client side, And send some requests to get some data. But server for all this requests get 401 Unauthorized.
Whats the problem?
Important Update:
Logining request is as follow:
Server set cookie in response, and getting authorized data request is as follow:
Why?



