Skip to content

Commit dc86abe

Browse files
authored
Merge pull request #17 from MeTLaBPJ/dongkyun
[Fix] Merge 충돌 해결
2 parents 8e5f2c3 + cb65baf commit dc86abe

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/main/java/org/inffy/domain/chat/handler/StompHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Message<?> preSend(Message<?> message, MessageChannel messageChannel){
3131
String authorization = jwtTokenProvider.getJwtFromStompRequest(accessor);
3232
jwtTokenProvider.validateStompJwt(authorization);
3333

34-
Authentication authentication = jwtTokenProvider.getAuthenticationJwt(authorization);
34+
Authentication authentication = jwtTokenProvider.getAuthentication(authorization);
3535
accessor.setUser(authentication);
3636
}
3737
return message;

src/main/java/org/inffy/global/security/jwt/util/JwtTokenProvider.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import org.inffy.domain.member.entity.Member;
88
import org.inffy.domain.member.repository.MemberRepository;
99
import org.inffy.global.exception.entity.RestApiException;
10+
import org.inffy.global.exception.entity.StompJwtException;
1011
import org.inffy.global.exception.error.CustomErrorCode;
1112
import org.springframework.beans.factory.InitializingBean;
1213
import org.springframework.beans.factory.annotation.Value;
14+
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
1315
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
1416
import org.springframework.security.core.Authentication;
1517
import org.springframework.security.core.GrantedAuthority;
@@ -124,4 +126,31 @@ public boolean validateToken(String token) {
124126
throw new RestApiException(CustomErrorCode.JWT_NOT_VALID); // 유효하지 않은 토큰
125127
}
126128
}
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+
}
127156
}

0 commit comments

Comments
 (0)