use of org.mamute.dto.UserAndSession in project mamute by caelum.
the class Access method login.
public User login(User user) {
if (user.isBanned())
throw new BannedUserException();
UserSession newSession = user.newSession();
Cookie cookie = new Cookie(BRUTAL_SESSION, newSession.getSessionKey());
cookie.setPath("/");
cookie.setHttpOnly(true);
cookie.setMaxAge(Integer.MAX_VALUE);
response.addCookie(cookie);
users.save(newSession);
this.userAndSession = new UserAndSession(user, newSession);
return user;
}
use of org.mamute.dto.UserAndSession in project mamute by caelum.
the class AccessTest method should_auto_login_with_valid_cookie.
@Test
public void should_auto_login_with_valid_cookie() {
String sessionKey = "session-key";
Cookie brutalCookie = new Cookie(Access.BRUTAL_SESSION, sessionKey);
Cookie[] cookies = new Cookie[] { anyCookie(), anyCookie(), brutalCookie, anyCookie(), anyCookie() };
when(request.getCookies()).thenReturn(cookies);
when(users.findBySessionKey(sessionKey)).thenReturn(new UserAndSession(user, new UserSession(user, sessionKey)));
Access access = new Access(response, request, users);
assertTrue(access.tryToAutoLogin());
}
Aggregations