1- package io .methea .api .auth ;
1+ package io .github . metheax .api .auth ;
22
3- import io .methea .api .domain .RefreshTokenPayload ;
4- import io .methea .api .domain .RequestTokenPayload ;
5- import io .methea . api .domain .RevokeTokenPayload ;
6- import io .methea . api .domain . Token ;
7- import io .methea . api .service . MetheaAuthenticationService ;
8- import io .methea . constant .MConstant ;
3+ import io .github . metheax .api .domain .RefreshTokenPayload ;
4+ import io .github . metheax .api .domain .RequestTokenPayload ;
5+ import io .github . metheax . api .domain .Token ;
6+ import io .github . metheax . api .service . MetheaAuthenticationService ;
7+ import io .github . metheax . api .domain . RevokeTokenPayload ;
8+ import io .github . metheax . constant .MetheaConstant ;
99import org .slf4j .Logger ;
1010import org .slf4j .LoggerFactory ;
1111import org .springframework .context .annotation .Scope ;
1414import org .springframework .http .MediaType ;
1515import org .springframework .http .ResponseEntity ;
1616import org .springframework .util .ObjectUtils ;
17- import org .springframework .web .bind .annotation .GetMapping ;
1817import org .springframework .web .bind .annotation .PostMapping ;
1918import org .springframework .web .bind .annotation .RequestBody ;
2019import org .springframework .web .bind .annotation .RestController ;
2625import java .util .Map ;
2726
2827/**
29- * Author : DKSilverX
28+ * Author : Kuylim Tith
3029 * Date : 08/08/2020
3130 */
3231@ RestController
3332@ Scope (value = WebApplicationContext .SCOPE_REQUEST , proxyMode = ScopedProxyMode .TARGET_CLASS )
3433public class AuthenticationController {
3534 private static final Logger log = LoggerFactory .getLogger (AuthenticationController .class );
36- private static final String UNAUTHORIZED_ACCESS_URL = "/unauthorized-access" ;
3735 private static final String GET_ACCESS_TOKEN_URL = "/auth/token" ;
3836 private static final String VERIFY_REFRESH_TOKEN = "/auth/refresh/token" ;
3937 private static final String REVOKE_ACCESS_TOKEN_URL = "/auth/token/revoke" ;
@@ -45,29 +43,20 @@ public AuthenticationController(MetheaAuthenticationService authenticationServic
4543 this .authenticationService = authenticationService ;
4644 }
4745
48- @ GetMapping (value = UNAUTHORIZED_ACCESS_URL , produces = MediaType .APPLICATION_JSON_VALUE )
49- public ResponseEntity <Map <String , Object >> unauthorizedAccess () {
50- Map <String , Object > map = new HashMap <>();
51- map .put (MConstant .JSON_MESSAGE , "Unauthorized Access!!" );
52- map .put (MConstant .JSON_STATUS , 401 );
53-
54- return new ResponseEntity <>(map , HttpStatus .OK );
55- }
56-
5746 @ PostMapping (value = GET_ACCESS_TOKEN_URL , produces = MediaType .APPLICATION_JSON_VALUE , consumes = MediaType .APPLICATION_JSON_VALUE )
5847 public ResponseEntity <Map <String , Object >> generateTokenFromUser (@ RequestBody RequestTokenPayload client , HttpServletRequest req ) {
5948 Map <String , Object > map = new HashMap <>();
6049 try {
6150 Token token = authenticationService .generateTokenFromUser (client , req );
6251
6352 if (ObjectUtils .isEmpty (token )) {
64- map .put (MConstant .JSON_MESSAGE , "Invalid account!!" );
65- map .put (MConstant .JSON_STATUS , 400 );
53+ map .put (MetheaConstant .JSON_MESSAGE , "Invalid account!!" );
54+ map .put (MetheaConstant .JSON_STATUS , 400 );
6655 return new ResponseEntity <>(map , HttpStatus .OK );
6756 }
6857 map .put ("token" , token );
69- map .put (MConstant .JSON_MESSAGE , "Access token generated!!!" );
70- map .put (MConstant .JSON_STATUS , 200 );
58+ map .put (MetheaConstant .JSON_MESSAGE , "Access token generated!!!" );
59+ map .put (MetheaConstant .JSON_STATUS , 200 );
7160 } catch (Exception ex ) {
7261 log .error ("=========> Generate access token from user error: " , ex );
7362 }
@@ -82,13 +71,13 @@ public ResponseEntity<Map<String, Object>> generateTokenFromRefreshToken(@Reques
8271 try {
8372 Token token = authenticationService .generateTokenFromRefreshToken (payload , req );
8473 if (ObjectUtils .isEmpty (token )) {
85- map .put (MConstant .JSON_MESSAGE , "Invalid refresh token!!" );
86- map .put (MConstant .JSON_STATUS , 400 );
74+ map .put (MetheaConstant .JSON_MESSAGE , "Invalid refresh token!!" );
75+ map .put (MetheaConstant .JSON_STATUS , 400 );
8776 return new ResponseEntity <>(map , HttpStatus .OK );
8877 }
8978 map .put ("token" , token );
90- map .put (MConstant .JSON_MESSAGE , "Access token generated!!!" );
91- map .put (MConstant .JSON_STATUS , 200 );
79+ map .put (MetheaConstant .JSON_MESSAGE , "Access token generated!!!" );
80+ map .put (MetheaConstant .JSON_STATUS , 200 );
9281 } catch (Exception ex ) {
9382 log .error ("=========> Generate access token from refresh token error: " , ex );
9483 }
@@ -103,12 +92,12 @@ public ResponseEntity<Map<String, Object>> revokeAccessToken(@RequestBody Revoke
10392
10493 try {
10594 authenticationService .revokeAccessToken (payload , request );
106- map .put (MConstant .JSON_MESSAGE , "Access token revoked!!!" );
107- map .put (MConstant .JSON_STATUS , 200 );
95+ map .put (MetheaConstant .JSON_MESSAGE , "Access token revoked!!!" );
96+ map .put (MetheaConstant .JSON_STATUS , 200 );
10897 } catch (Exception ex ) {
10998 log .error ("=========> revokeAccessToken error: " , ex );
110- map .put (MConstant .JSON_MESSAGE , "Failed to revoke access token!!" );
111- map .put (MConstant .JSON_STATUS , 400 );
99+ map .put (MetheaConstant .JSON_MESSAGE , "Failed to revoke access token!!" );
100+ map .put (MetheaConstant .JSON_STATUS , 400 );
112101 }
113102
114103 return new ResponseEntity <>(map , HttpStatus .OK );
0 commit comments