SEC-588: Completed JdbcTokenRepositoryImpl and added extra update method to PersistentTokenRepository interface (additional files from failed commit).
This commit is contained in:
parent
7caa1587b3
commit
1a5ef2dece
|
@ -2,33 +2,45 @@ package org.springframework.security.ui.rememberme;
|
|||
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Simple <tt>PersistentTokenRepository</tt> implementation backed by a Map. Intended for testing only.
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
*/
|
||||
public class InMemoryTokenRepositoryImpl implements PersistentTokenRepository {
|
||||
private Map seriesTokens = new HashMap();
|
||||
|
||||
public synchronized void saveToken(PersistentRememberMeToken token) {
|
||||
public synchronized void createNewToken(PersistentRememberMeToken token) {
|
||||
PersistentRememberMeToken current = (PersistentRememberMeToken) seriesTokens.get(token.getSeries());
|
||||
|
||||
if (current != null && !token.getUsername().equals(current.getUsername())) {
|
||||
throw new DataIntegrityViolationException("Series Id already exists with different username");
|
||||
if (current != null) {
|
||||
throw new DataIntegrityViolationException("Series Id '"+ token.getSeries() +"' already exists!");
|
||||
}
|
||||
|
||||
// Store it, overwriting the existing one.
|
||||
seriesTokens.put(token.getSeries(), token);
|
||||
}
|
||||
|
||||
public synchronized void updateToken(String series, String tokenValue, Date lastUsed) {
|
||||
PersistentRememberMeToken token = getTokenForSeries(series);
|
||||
|
||||
PersistentRememberMeToken newToken = new PersistentRememberMeToken(token.getUsername(), series, tokenValue,
|
||||
new Date());
|
||||
|
||||
// Store it, overwriting the existing one.
|
||||
seriesTokens.put(series, newToken);
|
||||
}
|
||||
|
||||
public synchronized PersistentRememberMeToken getTokenForSeries(String seriesId) {
|
||||
return (PersistentRememberMeToken) seriesTokens.get(seriesId);
|
||||
}
|
||||
|
||||
public synchronized void removeAllTokens(String username) {
|
||||
public synchronized void removeUserTokens(String username) {
|
||||
Iterator series = seriesTokens.keySet().iterator();
|
||||
|
||||
while (series.hasNext()) {
|
||||
|
|
Loading…
Reference in New Issue