public LoggedInProfilesResponse getLoggedUsers(int max) {
   LoggedInProfilesResponse response = new LoggedInProfilesResponse();
   List<UserProfile> users = context.getLogManager().getRecentUsers(SESSION_TIMEOUT);
   response.setUsers(users.subList(0, Math.min(max, users.size())));
   response.setCount(users.size());
   return response;
 }
  private boolean initSession(
      UserProfile user,
      String password,
      boolean requirePassword,
      HttpServletRequest request,
      HttpServletResponse response) {

    Authentication auth;

    try {
      if (requirePassword) {
        UsernamePasswordAuthenticationToken token =
            new UsernamePasswordAuthenticationToken(user.getUsername(), password);
        auth = authenticationManager.authenticate(token);
      } else {
        auth = new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());
      }

      context.getLogManager().loggedIn(user);
      SecurityContextHolder.getContext().setAuthentication(auth);
      securityContextRepository.saveContext(SecurityContextHolder.getContext(), request, response);
      rememberMeServices.loginSuccess(request, response, auth);
      request
          .getSession()
          .setAttribute("nquire-it-token", new BigInteger(260, random).toString(32));
    } catch (Exception ex) {
      auth = null;
    }

    return auth != null
        && auth.getPrincipal() != null
        && auth.getPrincipal() instanceof UserProfile;
  }
 public boolean mergeAccount(UserProfile user, UserProfile mergedUser, String provider) {
   if (context.getUserProfileDao().deleteConnection(mergedUser, provider)) {
     context.getLogManager().usersMerged(user, mergedUser);
     context.getVotableDao().transferContent(mergedUser, user);
     context.getVoteDao().transferVotes(mergedUser, user);
     context.getRoleDao().transferRoles(mergedUser, user);
     context.getUserProfileDao().deleteUser(mergedUser);
     return true;
   } else {
     return false;
   }
 }
 public StatusResponse logout(
     UserProfile user,
     HashMap<String, Connection<?>> connections,
     HttpServletRequest request,
     HttpServletResponse response) {
   context.getLogManager().loggedOut(user);
   CookieClearingLogoutHandler cookieClearingLogoutHandler =
       new CookieClearingLogoutHandler(
           AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
   SecurityContextLogoutHandler securityContextLogoutHandler = new SecurityContextLogoutHandler();
   cookieClearingLogoutHandler.logout(request, response, null);
   securityContextLogoutHandler.logout(request, response, null);
   return status(connections, request.getSession());
 }
 public List<UserProfile> getLoggedUsers() {
   return context.getLogManager().getRecentUsers(SESSION_TIMEOUT);
 }
 public boolean isLoggedIn(UserProfile user) {
   return context.getLogManager().userRecentAction(user, SESSION_TIMEOUT);
 }