Websphere 7 Java 1.7 Jersey 1.19
I have a page which is sending an ajax call to a REST endpoint within the same web application. I have a Filter which sets up the session when the user accesses the page. However, in Firefox, the session is null when I try to access it in the REST endpoint. I am not having this problem with IE10 or Chrome. It seems as though Firefox is not sending the tracking cookie when it makes the AJAX call. That is what I see in Firebug. My Firefox is set to accept cookies.
var firsttest = function() {
return $.ajax({
url: "rest/test/testmethod1",
method: "GET"
});
};
@GET
@Path("/testmethod1")
@Produces(MediaType.APPLICATION_JSON)
public Response testMethod1(@Context HttpServletRequest request) throws JsonGenerationException,
JsonMappingException, IOException {
System.out.println("request = " + request);
if (!isUserReadOnly(request) && !isUserReadWrite(request)) {
return Response.status(Status.FORBIDDEN).build();
}
ObjectMapper mapper = new ObjectMapper();
TestResponse testResponse = new TestResponse(1, "A");
return Response.ok(mapper.writeValueAsString(testResponse)).build();
}
private boolean isUserReadOnly(HttpServletRequest request) {
HttpSession session = request.getSession(false);
Authentication authentication = (Authentication) session.getAttribute("authentication");
if (authentication == null) {
System.out.println("authentication null");
return false;
}
System.out.println(authentication.toString());
return authentication.isReadOnlyRole();
}
private boolean isUserReadWrite(HttpServletRequest request) {
HttpSession session = request.getSession(false);
Authentication authentication = (Authentication) session.getAttribute("authentication");
if (authentication == null) {
System.out.println("authentication null");
return false;
}
System.out.println(authentication.toString());
return authentication.isReadWriteRole();
}