21
21
public class AuthUtil {
22
22
23
23
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/ " ;
25
25
26
26
public static JSONArray getCourses (AuthRequestDto requestDto ) {
27
- return getData (requestDto , "/ UsrRecMatt/list.do" , "dsRecMattList" );
27
+ return getData (requestDto , "UsrRecMatt/list.do" , "dsRecMattList" );
28
28
}
29
29
30
30
public static JSONObject getInfo (AuthRequestDto requestDto ) {
31
- JSONArray response = getData (requestDto , "/ UsrSchMng/selectStdInfo.do" , "dsStdInfoList" );
31
+ JSONArray response = getData (requestDto , "UsrSchMng/selectStdInfo.do" , "dsStdInfoList" );
32
32
return response .getJSONObject (0 );
33
33
}
34
34
@@ -49,8 +49,8 @@ private static JSONObject getData(AuthRequestDto requestDto, String url) {
49
49
connection .getOutputStream ().write (createRequestData (requestDto ));
50
50
return readResponse (connection );
51
51
} 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 );
54
54
}
55
55
}
56
56
@@ -59,6 +59,7 @@ private static Map<String, String> login(AuthRequestDto requestDto) {
59
59
Connection .Response loginResponse = executeLogin (requestDto );
60
60
return getSessionCookies (loginResponse );
61
61
} catch (IOException e ) {
62
+ log .error ("[ERROR] Failed to Login." , e );
62
63
throw new GeneralException (ErrorCode .AUTH_LOGIN_FAIL );
63
64
}
64
65
}
@@ -75,11 +76,13 @@ private static Connection.Response executeLogin(AuthRequestDto requestDto) throw
75
76
}
76
77
77
78
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" )
79
80
.method (Connection .Method .GET )
80
81
.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 ();
83
86
}
84
87
85
88
private static HttpURLConnection createConnection (String url , Map <String , String > session ) throws IOException {
0 commit comments