protected void onLoginSuccess(HttpServletRequest request, HttpServletResponse response, Authentication successfulAuthentication) { LoginUser user = (LoginUser) successfulAuthentication.getPrincipal(); logger.debug("Creating new persistent login for user " + user.getUsername()); PersistentRememberMeToken persistentToken = new PersistentRememberMeToken(user.getUserId(), generateSeriesData(), generateTokenData(), new Date()); try { tokenRepository.createNewToken(persistentToken); addCookie(persistentToken, request, response); } catch (Exception e) { logger.error("Failed to save persistent token ", e); } }
@Override public PersistentRememberMeToken getTokenForSeries(String seriesId) { try { return getJdbcTemplate().queryForObject(sqlSelect, new RowMapper<PersistentRememberMeToken>() { public PersistentRememberMeToken mapRow(ResultSet rs, int rowNum) throws SQLException { //String username, String series, String tokenValue, Date date return new PersistentRememberMeToken(rs.getString(3), rs.getString(1), rs.getString(2), rs.getTimestamp(4)); } }, seriesId); } catch (EmptyResultDataAccessException zeroResults) { if (logger.isInfoEnabled()) { logger.info("Querying token for series '" + seriesId + "' returned no results.", zeroResults); } } catch (IncorrectResultSizeDataAccessException moreThanOne) { logger.error("Querying token for series '" + seriesId + "' returned more than one value. Series" + " should be unique"); } catch (DataAccessException e) { logger.error("Failed to load token for series " + seriesId, e); } return null; }
@Override public void createNewToken(PersistentRememberMeToken token) { logger.info("Creating Token for user : {}", token.getUsername()); UserSessions userSession = new UserSessions(); userSession.setUserEmail(token.getUsername()); userSession.setSeries(token.getSeries()); userSession.setSessionToken(token.getTokenValue()); userSession.setLastLogin(token.getDate()); persist(userSession); }
@Override public PersistentRememberMeToken getTokenForSeries(String seriesId) { logger.info("Fetch Token if any for seriesId : {}", seriesId); try { Criteria crit = createEntityCriteria(); crit.add(Restrictions.eq("series", seriesId)); UserSessions userSession = (UserSessions) crit.uniqueResult(); return new PersistentRememberMeToken(userSession.getUserEmail(), userSession.getSeries(), userSession.getSessionToken(), userSession.getLastLogin()); } catch (Exception e) { logger.info("Token not found..."); return null; } }
@Override public PersistentRememberMeToken getTokenForSeries(String seriesId) { Long sessionId = Long.valueOf(seriesId); return sessionService .findSession(sessionId) .map(this::toPersistentRememberMeToken) .orElse(null); }
private PersistentRememberMeToken toPersistentRememberMeToken(Session session) { String username = String.valueOf(session.getUserId()); String series = String.valueOf(session.getId()); LocalDateTime lastUsedAt = Optional.ofNullable(session.getLastUsedAt()).orElseGet(session::getIssuedAt); return new PersistentRememberMeToken( username, series, session.getToken(), toDate(lastUsedAt)); }
@Override public void createNewToken(PersistentRememberMeToken token) { logger.info("Creating Token for user : {}", token.getUsername()); PersistentLogin persistentLogin = new PersistentLogin(); persistentLogin.setUsername(token.getUsername()); persistentLogin.setSeries(token.getSeries()); persistentLogin.setToken(token.getTokenValue()); persistentLogin.setLast_used(token.getDate()); persist(persistentLogin); }
@Override public PersistentRememberMeToken getTokenForSeries(String seriesId) { logger.info("Fetch Token if any for seriesId : {}", seriesId); try { Criteria crit = createEntityCriteria(); crit.add(Restrictions.eq("series", seriesId)); PersistentLogin persistentLogin = (PersistentLogin) crit.uniqueResult(); return new PersistentRememberMeToken(persistentLogin.getUsername(), persistentLogin.getSeries(), persistentLogin.getToken(), persistentLogin.getLast_used()); } catch (Exception e) { logger.info("Token not found..."); return null; } }
/** {@inheritDoc} */ @Override public PersistentRememberMeToken getTokenForSeries(String seriesId) { RememberMeToken token = this.rememberMeTokenRepository.findBySeries(seriesId); if (null == token) { return null; } return new PersistentRememberMeToken(token.getUsername(), token.getSeries(), token.getTokenValue(), token.getDate()); }
/** * <p>Constructor for RememberMeToken.</p> * * @param token a {@link org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken} object. */ public RememberMeToken(PersistentRememberMeToken token) { this.series = token.getSeries(); this.username = token.getUsername(); this.tokenValue = token.getTokenValue(); this.date = token.getDate(); }
/** * The method provides the functionality to store a new token in the token repository * @param token The token that will be stored in the token repository */ @Override public synchronized void createNewToken(PersistentRememberMeToken token) { PersistentRememberMeToken current = this.seriesTokens.get(token.getSeries()); if(current != null) { throw new DataIntegrityViolationException("Series Id \'" + token.getSeries() + "\' already exists!"); } else { this.seriesTokens.put(token.getSeries(), token); saveTokens(); } }
/** * Updates a specific token with a new values to a specific token * @param series The token that will be updated * @param tokenValue The new token value * @param lastUsed Date for when it was last used */ @Override public synchronized void updateToken(String series, String tokenValue, Date lastUsed) { PersistentRememberMeToken token = this.getTokenForSeries(series); PersistentRememberMeToken newToken = new PersistentRememberMeToken(token.getUsername(), series, tokenValue, new Date()); this.seriesTokens.put(series, newToken); saveTokens(); }
/** * Remove a user token from the repository * @param username The token that matches this user name will be removed */ @Override public synchronized void removeUserTokens(String username) { Iterator series = this.seriesTokens.keySet().iterator(); while(series.hasNext()) { String seriesId = (String)series.next(); PersistentRememberMeToken token = this.seriesTokens.get(seriesId); if(username.equals(token.getUsername())) { series.remove(); } } saveTokens(); }
/** * Get all tokens in a token list * @return A list of tokens */ private SessionTokenList getTokens(){ final SessionTokenList tokens = new SessionTokenList(); for(PersistentRememberMeToken persistentRememberMeToken : seriesTokens.values()){ final SessionToken token = new SessionToken(persistentRememberMeToken); tokens.add(token); } return tokens; }
@Override public void createNewToken(PersistentRememberMeToken token) { PersistentLoginEntity userPersistentToken = new PersistentLoginEntity(); userPersistentToken.setSeries(token.getSeries()); userPersistentToken.setUsername(token.getUsername()); userPersistentToken.setToken(token.getTokenValue()); userPersistentToken.setLastUsed(token.getDate()); persistentLoginRepository.save(userPersistentToken); }
@Override public PersistentRememberMeToken getTokenForSeries(String seriesId) { PersistentLoginEntity userPersistentToken = persistentLoginRepository.findBySeries(seriesId); if (userPersistentToken == null) { return null; } return new PersistentRememberMeToken( userPersistentToken.getUsername(), userPersistentToken.getSeries(), userPersistentToken.getToken(), userPersistentToken.getLastUsed()); }
@Override public void createNewToken(PersistentRememberMeToken token) { PersistentLogin persistentLogin = new PersistentLogin(); UserBO user = this.userService.findByName(token.getUsername()); persistentLogin.setSeries(token.getSeries()); persistentLogin.setToken(token.getTokenValue()); persistentLogin.setUser(UserConverter.convert(user)); persistentLogin.setLastUsed(token.getDate()); this.sessionFactory.getCurrentSession().save(persistentLogin); }
@Override public void createNewToken(PersistentRememberMeToken token) { AutoLogin vo = new AutoLogin(); vo.setToken(token.getTokenValue()); vo.setSeriesId(token.getSeries()); vo.setLastUsed(token.getDate()); vo.setUserId(token.getUsername()); userService.createLoginToken(vo); }
@Override public void createNewToken(PersistentRememberMeToken prmt) { TokenEntity tokenEntity = new TokenEntity(); tokenEntity.setDate(prmt.getDate()); tokenEntity.setSeries(prmt.getSeries()); tokenEntity.setTokenValue(prmt.getTokenValue()); tokenEntity.setUsername(prmt.getUsername()); tokenRepository.save(tokenEntity); }
@Override public PersistentRememberMeToken getTokenForSeries(String series) { TokenEntity tokenEntity = tokenRepository.findBySeries(series); if (tokenEntity != null) { return new PersistentRememberMeToken(tokenEntity.getUsername(), tokenEntity.getSeries(), tokenEntity.getTokenValue(), tokenEntity.getDate()); } return null; }
@Override public void createNewToken(PersistentRememberMeToken token) { try { authTokenService.createAuthToken(token.getUsername(), CurrentRequestUtils.get().getRemoteAddr(), token.getSeries(), token.getTokenValue()); } catch (Throwable e) { throw new RuntimeException("Failed to create auth token", e); } }
@Override public PersistentRememberMeToken getTokenForSeries(String seriesId) { try { AuthToken authToken = authTokenService.getAuthTokenByUuid(seriesId); User user = userService.getUserByUuid(authToken.getUserUuid()); return new PersistentRememberMeToken(user.getEmail(), authToken.getUuid(), authToken.getTokenValue(), new Date(authToken.getLastVerifiedAt())); } catch (Throwable e) { log.info("Persistent auth token wasn't found for seriesId " + seriesId); return null; } }
@Override public PersistentRememberMeToken getTokenForSeries(String seriesId) { PersistentLogins persistentLogins = new PersistentLogins(); persistentLogins.setSeries(seriesId); PersistentLogins persistentLoginsInDB = commonBaseService.getUnique(PersistentLogins.class, persistentLogins); if (persistentLoginsInDB == null) return null; return new PersistentRememberMeToken(persistentLoginsInDB.getUsername(), persistentLoginsInDB.getSeries(), persistentLoginsInDB.getTokenValue(), persistentLoginsInDB.getLastUsedDate()); }
public PersistentLogins(PersistentRememberMeToken token) { super(); this.series = token.getSeries(); this.username = token.getUsername(); this.tokenValue = token.getTokenValue(); this.lastUsedDate = token.getDate(); }
@Modifying @Transactional default void createNewToken(PersistentRememberMeToken token) { PersistentLogins logins = new PersistentLogins(); logins.setLastUsed(token.getDate()); logins.setSeries(token.getSeries()); logins.setToken(token.getTokenValue()); logins.setUsername(token.getUsername()); this.save(logins); }
default PersistentRememberMeToken getTokenForSeries(String seriesId) { List<PersistentLogins> logins = this.findBySeries(seriesId); if (logins.isEmpty()) { return null; } PersistentLogins login = logins.get(0); return new PersistentRememberMeToken(login.getUsername(), login.getSeries(), login.getToken(), login.getLastUsed()); }
/** * Stores the new {@link PersistentRememberMeToken} but first changes the series to be series + currentIpAddress and * then delegates to the injected {@link PersistentTokenRepository} to do all the work. */ @Override public void createNewToken(PersistentRememberMeToken token) { String ipSeries = ipSeries(token.getSeries()); PersistentRememberMeToken ipToken = tokenWithSeries(token, ipSeries); this.delegateRepository.createNewToken(ipToken); }
/** * Gets the {@link PersistentRememberMeToken} for the given seriesId + currentIpAddress. By always adding the IP * address to the identifier we guarantee that the token can only be retrieved if the IP of the original token * matches the current user's token. It then delegates to the injected {@link PersistentTokenRepository} to do all * the work. */ @Override public PersistentRememberMeToken getTokenForSeries(String seriesId) { String ipSeries = ipSeries(seriesId); PersistentRememberMeToken ipToken = delegateRepository.getTokenForSeries(ipSeries); return tokenWithSeries(ipToken, seriesId); }
@Override public PersistentRememberMeToken getTokenForSeries(String seriesId) { RememberMeToken token = this.rememberMeTokenRepository.findBySeries(seriesId); if (token == null){ return null; } return new PersistentRememberMeToken(token.getUsername(), token.getSeries(), token.getTokenValue(), token.getDate()); }
@Override @Transactional public void createNewToken(PersistentRememberMeToken token) { repo.save(RememberMeToken.of(token.getSeries(), token.getUsername(), token.getTokenValue(), token.getDate())); }
@Override public PersistentRememberMeToken getTokenForSeries(String seriesId) { return repo.findBySeries(seriesId).map(RememberMeToken::toPersistentRememberMeToken).orElse(null); }
public PersistentRememberMeToken toPersistentRememberMeToken() { return new PersistentRememberMeToken(username, series, tokenValue, date); }
@Override public void createNewToken(PersistentRememberMeToken token) { Long sessionId = Long.valueOf(token.getSeries()); Long userId = Long.valueOf(token.getUsername()); sessionService.createSession(sessionId, userId, token.getTokenValue()); }
public PersistentLogin(PersistentRememberMeToken token){ this.series = token.getSeries(); this.username = token.getUsername(); this.token = token.getTokenValue(); this.lastUsed = token.getDate(); }