2121public class AuthUtil {
2222
2323 private static final String LOGIN_URL = "https://smsso.smu.ac.kr/Login.do" ;
24- private static final String BASE_URL = "https://smul.smu.ac.kr" ;
24+ private static final String BASE_URL = "https://smul.smu.ac.kr/ " ;
2525
2626 public static JSONArray getCourses (AuthRequestDto requestDto ) {
27- return getData (requestDto , "/ UsrRecMatt/list.do" , "dsRecMattList" );
27+ return getData (requestDto , "UsrRecMatt/list.do" , "dsRecMattList" );
2828 }
2929
3030 public static JSONObject getInfo (AuthRequestDto requestDto ) {
31- JSONArray response = getData (requestDto , "/ UsrSchMng/selectStdInfo.do" , "dsStdInfoList" );
31+ JSONArray response = getData (requestDto , "UsrSchMng/selectStdInfo.do" , "dsStdInfoList" );
3232 return response .getJSONObject (0 );
3333 }
3434
@@ -49,8 +49,8 @@ private static JSONObject getData(AuthRequestDto requestDto, String url) {
4949 connection .getOutputStream ().write (createRequestData (requestDto ));
5050 return readResponse (connection );
5151 } catch (IOException e ) {
52- log .error ("[ERROR] Failed to fetch data from URL: '{}'. Request: {} " , url , requestDto , e );
53- throw new GeneralException (ErrorCode .AUTH_INTERNAL_SERVER_ERROR );
52+ log .error ("[ERROR] Failed to fetch data from URL: '{}'." , url , e );
53+ throw new GeneralException (ErrorCode .AUTH_FETCH_FAILURE );
5454 }
5555 }
5656
@@ -59,6 +59,7 @@ private static Map<String, String> login(AuthRequestDto requestDto) {
5959 Connection .Response loginResponse = executeLogin (requestDto );
6060 return getSessionCookies (loginResponse );
6161 } catch (IOException e ) {
62+ log .error ("[ERROR] Failed to Login." , e );
6263 throw new GeneralException (ErrorCode .AUTH_LOGIN_FAIL );
6364 }
6465 }
@@ -75,11 +76,13 @@ private static Connection.Response executeLogin(AuthRequestDto requestDto) throw
7576 }
7677
7778 private static Map <String , String > getSessionCookies (Connection .Response loginResponse ) throws IOException {
78- return Jsoup .connect (BASE_URL + "/ index.do" )
79+ Connection . Response response = Jsoup .connect (BASE_URL + "index.do" )
7980 .method (Connection .Method .GET )
8081 .cookies (loginResponse .cookies ())
81- .execute ()
82- .cookies ();
82+ .execute ();
83+ if (!response .url ().toString ().equals (BASE_URL ))
84+ throw new GeneralException (ErrorCode .AUTH_EXCEEDED_LOGIN_ATTEMPTS );
85+ return response .cookies ();
8386 }
8487
8588 private static HttpURLConnection createConnection (String url , Map <String , String > session ) throws IOException {
0 commit comments