don't create a session if it does not exists

This commit is contained in:
Athou
2014-08-19 07:34:07 +02:00
parent f56cba59ae
commit 0140402ad4
4 changed files with 9 additions and 7 deletions

View File

@@ -75,10 +75,12 @@ public class UserService {
* try to log in by checking if the user has an active session
*/
public Optional<User> login(HttpSession session) {
User user = (User) session.getAttribute(SESSION_KEY_USER);
if (user != null) {
afterLogin(user);
return Optional.of(user);
if (session != null) {
User user = (User) session.getAttribute(SESSION_KEY_USER);
if (user != null) {
afterLogin(user);
return Optional.of(user);
}
}
return Optional.absent();
}

View File

@@ -67,7 +67,7 @@ public class SecurityCheckProvider implements InjectableProvider<SecurityCheck,
}
private Optional<User> cookieSessionLogin() {
return userService.login(request.getSession());
return userService.login(request.getSession(false));
}
private Optional<User> basicAuthenticationLogin(HttpContext c) {

View File

@@ -36,7 +36,7 @@ public class CustomCssServlet extends HttpServlet {
final Optional<User> user = new UnitOfWork<Optional<User>>(sessionFactory) {
@Override
protected Optional<User> runInSession() throws Exception {
return userService.login(req.getSession());
return userService.login(req.getSession(false));
}
}.run();
if (!user.isPresent()) {

View File

@@ -53,7 +53,7 @@ public class NextUnreadServlet extends HttpServlet {
final Optional<User> user = new UnitOfWork<Optional<User>>(sessionFactory) {
@Override
protected Optional<User> runInSession() throws Exception {
return userService.login(req.getSession());
return userService.login(req.getSession(false));
}
}.run();
if (!user.isPresent()) {