use of org.mamute.model.UserSession 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.model.UserSession in project mamute by caelum.
the class UserDAOTest method should_find_by_session_key.
@Test
public void should_find_by_session_key() {
User gui = user("Guilherme Sonar", "gui@email.com.br");
users.save(gui);
UserSession userSession = gui.newSession();
users.save(userSession);
assertEquals(gui, users.findBySessionKey(userSession.getSessionKey()).getUser());
assertNull(users.findBySessionKey("12345"));
assertNull(users.findBySessionKey(null));
}
use of org.mamute.model.UserSession 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