My JAX-RS resource for authentication looks like this (by the way I want to improve it for security matters because it's not safe to call the username and password by a GET Method):
@Path("/UserService")
public class UserServiceRS {
UserService user ;
AuthenticationManager authManager;
public UserServiceRS(){
user=(UserService)SpringApplicationContext.getBean("userDetailsService");
authManager(AuthenticationManager)SpringApplicationContext
.getBean("authenticationManager");
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/authentification/{username}/{password}")
public String login(@PathParam( value="username" ) String username,
@PathParam( value="password" ) String password )
{
Logger LOG = LoggerFactory.getLogger(LoginBean.class);
LOG.info("Starting to login");
try{
UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(username,password);
Authentication authenticate = authManager.authenticate(usernamePasswordAuthenticationToken);
SecurityContextHolder.getContext().setAuthentication(authenticate);
return "1";
}catch (final Exception e){
LOG.error("Error log in" + e);
}
return "0";
}
And in my jQuery Mobile client the method I call in the "connect" button looks like this:
function login(){
var uri="myuri";
var login=$("#login").val();
var password=$("#pass").val();
uri=uri+"/"+login+"/"+password;
$.getJSON(uri,function(data){
if(JSON.stringify(data)==1){
$.mobile.changePage("#page-signup-succeeded",{transition:"slide" });
}
else {
$.mobile.changePage("#page-signup-failed");
}
});
};
I would like to manage the session in my jQuery Mobile client and I don't know how to get the session from the authenticated user. How can I achieve this?