--- src/main/java/com/takensoft/ai_lms/lms/auth/service/AuthService.java
+++ src/main/java/com/takensoft/ai_lms/lms/auth/service/AuthService.java
... | ... | @@ -15,4 +15,6 @@ |
15 | 15 |
String login(LoginDTO loginDTO) throws Exception; |
16 | 16 |
|
17 | 17 |
void logout(String token) throws Exception; |
18 |
+ |
|
19 |
+ UserVO checkToken(String token) throws Exception; |
|
18 | 20 |
} |
--- src/main/java/com/takensoft/ai_lms/lms/auth/service/Impl/AuthServiceImpl.java
+++ src/main/java/com/takensoft/ai_lms/lms/auth/service/Impl/AuthServiceImpl.java
... | ... | @@ -5,6 +5,7 @@ |
5 | 5 |
import com.takensoft.ai_lms.lms.auth.dao.AuthDAO; |
6 | 6 |
import com.takensoft.ai_lms.lms.auth.dto.LoginDTO; |
7 | 7 |
import com.takensoft.ai_lms.lms.auth.service.AuthService; |
8 |
+import com.takensoft.ai_lms.lms.auth.vo.UserAuthorVO; |
|
8 | 9 |
import com.takensoft.ai_lms.lms.auth.vo.UserVO; |
9 | 10 |
import lombok.RequiredArgsConstructor; |
10 | 11 |
import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl; |
... | ... | @@ -19,6 +20,7 @@ |
19 | 20 |
import org.springframework.transaction.annotation.Transactional; |
20 | 21 |
|
21 | 22 |
import java.util.HashMap; |
23 |
+import java.util.List; |
|
22 | 24 |
import java.util.Map; |
23 | 25 |
import java.util.concurrent.TimeUnit; |
24 | 26 |
import java.util.stream.Collectors; |
... | ... | @@ -109,6 +111,11 @@ |
109 | 111 |
} |
110 | 112 |
} |
111 | 113 |
|
114 |
+ /** |
|
115 |
+ * @author : 박민혁 |
|
116 |
+ * @since : 2024.08.02 |
|
117 |
+ * 로그아웃 기능 |
|
118 |
+ */ |
|
112 | 119 |
@Override |
113 | 120 |
public void logout(String token) throws Exception { |
114 | 121 |
try { |
... | ... | @@ -123,6 +130,31 @@ |
123 | 130 |
} |
124 | 131 |
} |
125 | 132 |
|
133 |
+ /** |
|
134 |
+ * @author : 박민혁 |
|
135 |
+ * @since : 2024.08.07 |
|
136 |
+ * 토근 확인 기능 |
|
137 |
+ */ |
|
138 |
+ @Override |
|
139 |
+ public UserVO checkToken(String token) throws Exception{ |
|
140 |
+ UserVO userVO = new UserVO(); |
|
141 |
+ try { |
|
142 |
+ // 토큰에서 로그인 ID 추출 |
|
143 |
+ Boolean isExpire = jwtUtil.isExpired(token); |
|
144 |
+ |
|
145 |
+ if (!isExpire) { |
|
146 |
+ String userId = jwtUtil.getUsid(token); |
|
147 |
+ userVO.setUsid(userId); |
|
148 |
+ List<UserAuthorVO> author = jwtUtil.getRoles(token); |
|
149 |
+ userVO.setAuthor(author); |
|
150 |
+ return userVO; |
|
151 |
+ } else { |
|
152 |
+ throw new Exception("유효하지 않은 토큰"); |
|
153 |
+ } |
|
154 |
+ } catch (Exception e) { |
|
155 |
+ throw new Exception("토큰 확인 중 문제가 발생했습니다", e); |
|
156 |
+ } |
|
157 |
+ } |
|
126 | 158 |
} |
127 | 159 |
|
128 | 160 |
|
--- src/main/java/com/takensoft/ai_lms/lms/auth/web/AuthController.java
+++ src/main/java/com/takensoft/ai_lms/lms/auth/web/AuthController.java
... | ... | @@ -73,6 +73,7 @@ |
73 | 73 |
|
74 | 74 |
try { |
75 | 75 |
String token = authService.login(loginDTO); |
76 |
+ |
|
76 | 77 |
response.addProperty("status", "success"); |
77 | 78 |
response.addProperty("token", token); |
78 | 79 |
return gson.toJson(response); |
... | ... | @@ -83,6 +84,11 @@ |
83 | 84 |
} |
84 | 85 |
} |
85 | 86 |
|
87 |
+ /** |
|
88 |
+ * @author : 박민혁 |
|
89 |
+ * @since : 2024.08.02 |
|
90 |
+ * 로그아웃 기능 |
|
91 |
+ */ |
|
86 | 92 |
@PostMapping("/logout.json") |
87 | 93 |
@Operation(summary = "사용자 로그아웃") |
88 | 94 |
public String logout(@RequestHeader("Authorization") String token) { |
... | ... | @@ -102,4 +108,31 @@ |
102 | 108 |
} |
103 | 109 |
} |
104 | 110 |
|
111 |
+ @PostMapping("/validateToken.json") |
|
112 |
+ @Operation(summary = "토큰 유효성 검사") |
|
113 |
+ public String validateToken(@RequestHeader("Authorization") String token) { |
|
114 |
+ Gson gson = new Gson(); |
|
115 |
+ JsonObject response = new JsonObject(); |
|
116 |
+ |
|
117 |
+ try { |
|
118 |
+ // 토큰에서 사용자 ID 추출 |
|
119 |
+ UserVO result = authService.checkToken(token); |
|
120 |
+ |
|
121 |
+ if (result != null) { |
|
122 |
+ // 사용자 정보를 JSON으로 변환하여 반환 |
|
123 |
+ response.addProperty("status", "success"); |
|
124 |
+ response.add("userInfo", new Gson().toJsonTree(result)); |
|
125 |
+ return gson.toJson(response); |
|
126 |
+ } else { |
|
127 |
+ response.addProperty("status", "error"); |
|
128 |
+ response.addProperty("message", "유효하지 않은 사용자입니다."); |
|
129 |
+ return gson.toJson(response); |
|
130 |
+ } |
|
131 |
+ } catch (Exception e) { |
|
132 |
+ response.addProperty("status", "error"); |
|
133 |
+ response.addProperty("message", e.getMessage()); |
|
134 |
+ return gson.toJson(response); |
|
135 |
+ } |
|
136 |
+ } |
|
137 |
+ |
|
105 | 138 |
} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?