diff --git a/membership-service/src/main/java/com/ns/membership/adapter/in/web/FriendController.java b/membership-service/src/main/java/com/ns/membership/adapter/in/web/FriendController.java index c9a9e13..12b3028 100644 --- a/membership-service/src/main/java/com/ns/membership/adapter/in/web/FriendController.java +++ b/membership-service/src/main/java/com/ns/membership/adapter/in/web/FriendController.java @@ -36,7 +36,6 @@ public class FriendController { @GetMapping("/{membershipId}") ResponseEntity GetFriendList(@PathVariable String membershipId){ - //Todo 친구 목록을 표시합니다. String memberId = jwtTokenProvider.getMembershipIdbyToken().toString(); if(memberId != membershipId) @@ -78,7 +77,6 @@ ResponseEntity GetFriendList(@PathVariable String membershipId @GetMapping("/wanted/{membershipId}") ResponseEntity GetWantedFriendList(@PathVariable String membershipId){ - //Todo 친구신청 목록을 표시합니다. String memberId = jwtTokenProvider.getMembershipIdbyToken().toString(); if(memberId != membershipId) @@ -119,7 +117,6 @@ ResponseEntity GetWantedFriendList(@PathVariable String member @PostMapping("/wanted/add") ResponseEntity PostSendWantFriend(@RequestBody FriendRequest request){ - //Todo 친구 신청합니다. String memberId = jwtTokenProvider.getMembershipIdbyToken().toString(); if(memberId != request.getMembershipId().toString()) @@ -172,7 +169,6 @@ ResponseEntity PostSendWantFriend(@RequestBody FriendRequest request @PostMapping("/add") ResponseEntity PostSendFriendAgree(@RequestBody FriendRequest request){ - //Todo 친구 신청을 수락합니다. String memberId = jwtTokenProvider.getMembershipIdbyToken().toString(); @@ -236,7 +232,6 @@ ResponseEntity PostSendFriendAgree(@RequestBody FriendRequest reques @PostMapping("/delete") ResponseEntity PostDeleteFriend(@RequestBody FriendRequest request){ - //Todo 친구를 삭제합니다. String memberId = jwtTokenProvider.getMembershipIdbyToken().toString(); diff --git a/membership-service/src/main/java/com/ns/membership/adapter/in/web/dto/PasswordResetRequest.java b/membership-service/src/main/java/com/ns/membership/adapter/in/web/dto/PasswordResetRequest.java index b49b6e1..3047758 100644 --- a/membership-service/src/main/java/com/ns/membership/adapter/in/web/dto/PasswordResetRequest.java +++ b/membership-service/src/main/java/com/ns/membership/adapter/in/web/dto/PasswordResetRequest.java @@ -9,7 +9,7 @@ @NoArgsConstructor public class PasswordResetRequest { private String membershipId; - private String newAddress; + private String newPassword; private String verify; } diff --git a/membership-service/src/main/java/com/ns/membership/adapter/out/JwtTokenProvider.java b/membership-service/src/main/java/com/ns/membership/adapter/out/JwtTokenProvider.java index e48154c..a5e518d 100644 --- a/membership-service/src/main/java/com/ns/membership/adapter/out/JwtTokenProvider.java +++ b/membership-service/src/main/java/com/ns/membership/adapter/out/JwtTokenProvider.java @@ -40,13 +40,15 @@ public Long getMembershipIdbyToken() { .parseClaimsJws(token) .getBody(); + System.out.println("claims: "+claims); + String membershipIdString = claims.get("sub", String.class); Long membershipId = Long.parseLong(membershipIdString); return membershipId; } @Override - public String generateJwtToken(Membership.MembershipId membershipId) { + public String generateJwtToken(Membership.MembershipId membershipId, Membership.MembershipRole membershipRole) { Date now = new Date(); Date expiryDate = new Date(now.getTime() + jwtExpirationInMs); @@ -54,6 +56,7 @@ public String generateJwtToken(Membership.MembershipId membershipId) { .setSubject(membershipId.getMembershipId()) .setHeaderParam("type", "jwt") .claim("id", membershipId.getMembershipId()) + .claim("role",membershipRole.getMembershipRole()) .setIssuedAt(now) .setExpiration(expiryDate) .signWith(SignatureAlgorithm.HS256, jwtSecret) @@ -78,16 +81,14 @@ public String generateRefreshToken(Membership.MembershipId membershipId) { public boolean validateJwtToken(String token) { try { - Jwts.parser().setSigningKey(jwtSecret).parseClaimsJws(token); + Jwts.parserBuilder().setSigningKey(jwtSecret).build().parseClaimsJws(token); return true; - } catch (MalformedJwtException ex) { + } catch (MalformedJwtException | ExpiredJwtException | UnsupportedJwtException | IllegalArgumentException ex) { // Invalid JWT token: 유효하지 않은 JWT 토큰일 때 발생하는 예외 - } catch (ExpiredJwtException ex) { // Expired JWT token: 토큰의 유효기간이 만료된 경우 발생하는 예외 - } catch (UnsupportedJwtException ex) { // Unsupported JWT token: 지원하지 않는 JWT 토큰일 때 발생하는 예외 - } catch (IllegalArgumentException ex) { // JWT claims string is empty: JWT 토큰이 비어있을 때 발생하는 예외 + System.out.println("[ERROR] jwtToken error : "+ex); } return false; } @@ -96,4 +97,35 @@ public Membership.MembershipId parseMembershipIdFromToken(String token) { Claims claims = Jwts.parser().setSigningKey(jwtSecret).parseClaimsJws(token).getBody(); return new Membership.MembershipId(claims.getSubject()); } + + public String getMembershipRolebyToken(String token) { + if (token == null || token.length() == 0) { + throw new RuntimeException("JwtToken is Invalid."); + } + + Claims claims = Jwts.parserBuilder() + .setSigningKey(jwtSecret) + .build() + .parseClaimsJws(token) + .getBody(); + + return claims.get("role", String.class); + } + + public Long getMembershipIdbyToken(String token) { + if(token == null || token.length() == 0){ + throw new RuntimeException("JwtToken is Invalid."); + } + + Claims claims = Jwts.parserBuilder() + .setSigningKey(jwtSecret) + .build() + .parseClaimsJws(token) + .getBody(); + + String membershipIdString = claims.get("sub", String.class); + Long membershipId = Long.parseLong(membershipIdString); + return membershipId; + } + } \ No newline at end of file