|
7 | 7 | import org.inffy.domain.member.entity.Member; |
8 | 8 | import org.inffy.domain.member.repository.MemberRepository; |
9 | 9 | import org.inffy.global.exception.entity.RestApiException; |
| 10 | +import org.inffy.global.exception.entity.StompJwtException; |
10 | 11 | import org.inffy.global.exception.error.CustomErrorCode; |
11 | 12 | import org.springframework.beans.factory.InitializingBean; |
12 | 13 | import org.springframework.beans.factory.annotation.Value; |
| 14 | +import org.springframework.messaging.simp.stomp.StompHeaderAccessor; |
13 | 15 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
14 | 16 | import org.springframework.security.core.Authentication; |
15 | 17 | import org.springframework.security.core.GrantedAuthority; |
@@ -124,4 +126,31 @@ public boolean validateToken(String token) { |
124 | 126 | throw new RestApiException(CustomErrorCode.JWT_NOT_VALID); // 유효하지 않은 토큰 |
125 | 127 | } |
126 | 128 | } |
| 129 | + |
| 130 | + public boolean validateStompJwt(String token) { |
| 131 | + if(token == null) { |
| 132 | + throw new JwtException("Jwt AccessToken not found"); |
| 133 | + } |
| 134 | + |
| 135 | + try { |
| 136 | + Jwts.parserBuilder() |
| 137 | + .setSigningKey(key) |
| 138 | + .build() |
| 139 | + .parseClaimsJws(token) |
| 140 | + .getBody(); |
| 141 | + return true; |
| 142 | + } catch (ExpiredJwtException e) { |
| 143 | + throw new StompJwtException(CustomErrorCode.JWT_ACCESS_TOKEN_EXPIRED); |
| 144 | + } catch (MalformedJwtException e) { |
| 145 | + throw new StompJwtException(CustomErrorCode.JWT_MALFORMED); |
| 146 | + } catch (SignatureException | SecurityException e) { |
| 147 | + throw new StompJwtException(CustomErrorCode.JWT_SIGNATURE); |
| 148 | + } catch (UnsupportedJwtException e) { |
| 149 | + throw new StompJwtException(CustomErrorCode.JWT_UNSUPPORTED); |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + public String getJwtFromStompRequest(final StompHeaderAccessor accessor){ |
| 154 | + return accessor.getFirstNativeHeader("Authorization").substring(7); |
| 155 | + } |
127 | 156 | } |
0 commit comments