인증/권한 업무 규칙과 전환 불변식 추출 #2
1 changed files with 29 additions and 0 deletions
|
|
@ -0,0 +1,29 @@
|
|||
package com.example.auth.security;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Token Blacklist Service - preserves AUTH-012 invariant.
|
||||
* Logout immediately invalidates token.
|
||||
*/
|
||||
@Service
|
||||
public class TokenBlacklistService {
|
||||
|
||||
private final ConcurrentHashMap<String, Instant> blacklist = new ConcurrentHashMap<>();
|
||||
|
||||
public void blacklist(String token) {
|
||||
blacklist.put(token, Instant.now());
|
||||
}
|
||||
|
||||
public boolean isBlacklisted(String token) {
|
||||
return blacklist.containsKey(token);
|
||||
}
|
||||
|
||||
public void cleanupExpired() {
|
||||
Instant cutoff = Instant.now().minusSeconds(7 * 24 * 60 * 60);
|
||||
blacklist.entrySet().removeIf(entry -> entry.getValue().isBefore(cutoff));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue