반응형
@Getter
public class JwtFactory {
private String subject = "test1@email.com";
private Date issuedAt = new Date();
private Date expiration = new Date(new Date().getTime() + Duration.ofDays(14).toMillis());
private Map<String, Object> claims = emptyMap();
// 빌더 패턴 써서 설정이 필요한 데이터만 선택 설정
@Builder
public JwtFactory(String subject, Date issuedAt, Date expiration, Map<String, Object> claims) {
this.subject = subject != null ? subject : this.subject;
this.issuedAt = issuedAt != null ? issuedAt : this.issuedAt;
this.expiration = expiration != null ? expiration : this.expiration;
this.claims = claims != null ? claims : emptyMap();
}
public static JwtFactory withDefaultValues() {
return JwtFactory.builder().build();
}
public String createToken(JwtProperties jwtProperties) {
return Jwts.builder()
.setSubject(subject)
.setHeaderParam(Header.TYPE, Header.JWT_TYPE)
.setIssuer(jwtProperties.getIssuer())
.setIssuedAt(issuedAt)
.setExpiration(expiration)
.addClaims(claims)
.signWith(SignatureAlgorithm.HS256, jwtProperties.getSecretKey())
.compact();
}
}
테스트 코드 짜는 중인데 롬복 인식이 안됨
build.gradle에 추가해보라고 하는거 다 해봤는데 안됨
걍 맨 위쪽 import하는 곳에
import lombok.Builder;
import lombok.Getter;
추가했더니 됨
ㅋㅋ
반응형
'Spring Security' 카테고리의 다른 글
| [Spring Security] Token Filter 구현하기 (0) | 2025.05.05 |
|---|---|
| [Spring Security] SecurityContextHolder란? (0) | 2025.05.05 |
| [Spring Security] JWT와 Authentication객체 (쓰임의 차이, 내가 헷갈렸던 부분 정리) (0) | 2025.05.04 |
| [Spring Security] 토큰 생성, 유효성 검사, 정보 빼오는 클래스 코드 - TokenProvider (0) | 2025.05.04 |
| [Spring Security] JWT 구현 준비단계(의존성 추가, 이슈 발급자, 비밀키 설정) (0) | 2025.05.04 |