Hi im having problem retrieving the userid from the session, my code looks a bit like this.. Can anyone tell why it is always writing "anon" to the database no matter whos signed in.. The getuserprincipal() doesnt seem to work.
Any suggestions?
public IUserMessage getUser(HttpServletRequest request) {
IUserMessage message = new UserMessage();
String username = "";
if(this.user==null){
Principal principal = request.getUserPrincipal();
if(principal==null){
username = request.getParameter("user");
if(username==null || username.equals("")){
message.setMessage(ERROR_USER_NOT_LOGGED_IN);
user = new User();
user.setUserId("anon");
message.setUser(user);
return message;
}
} else {
username = principal.getName();
}
DatabaseManager databaseManager = new DatabaseManager();
if(message.getStatus()==Constants.STATUS_OK){
this.user = message.getUser();
}
} else {
message.setUser(this.user);
message.setStatus(Constants.STATUS_OK);
}
return message;
Any suggestions?
public IUserMessage getUser(HttpServletRequest request) {
IUserMessage message = new UserMessage();
String username = "";
if(this.user==null){
Principal principal = request.getUserPrincipal();
if(principal==null){
username = request.getParameter("user");
if(username==null || username.equals("")){
message.setMessage(ERROR_USER_NOT_LOGGED_IN);
user = new User();
user.setUserId("anon");
message.setUser(user);
return message;
}
} else {
username = principal.getName();
}
DatabaseManager databaseManager = new DatabaseManager();
if(message.getStatus()==Constants.STATUS_OK){
this.user = message.getUser();
}
} else {
message.setUser(this.user);
message.setStatus(Constants.STATUS_OK);
}
return message;