Skip to content

Commit

Permalink
some refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
bennetelli committed Jan 12, 2021
1 parent ed66e3f commit a1c78e4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ public class TogglzCSRFTokenCache {

private static final PassiveExpiringMap<String, CSRFToken> expiringMap;
private static final Object lock = new Object();

static {
PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<String, CSRFToken>
expirationPolicy = new PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<>(
10, TimeUnit.MINUTES);
expiringMap = new PassiveExpiringMap<>(expirationPolicy, new HashMap<>());
}

public static void cacheToken(CSRFToken token) {
static void cacheToken(CSRFToken token) {
synchronized (lock) {
expiringMap.put(token.getValue(), token);
}
}

public static boolean isTokenInCache(CSRFToken token) {
static boolean isTokenInCache(CSRFToken token) {
synchronized (lock) {
return expiringMap.containsKey(token.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

public class TogglzCSRFTokenValidator implements CSRFTokenValidator {


public static final String CSRF_TOKEN_NAME = "togglz_csrf";
static final String CSRF_TOKEN_NAME = "togglz_csrf";

@Override
public boolean isTokenValid(HttpServletRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

public interface CSRFTokenValidator {


boolean isTokenValid(HttpServletRequest request);
}

0 comments on commit a1c78e4

Please sign in to comment.