| Line 89... |
Line 89... |
| 89 |
}
|
89 |
}
|
| 90 |
|
90 |
|
| 91 |
public static UserInfo getUserInfo(String token)
|
91 |
public static UserInfo getUserInfo(String token)
|
| 92 |
throws ProfitMandiBusinessException{
|
92 |
throws ProfitMandiBusinessException{
|
| 93 |
DecodedJWT decodedJWT = parse(token);
|
93 |
DecodedJWT decodedJWT = parse(token);
|
| 94 |
Instant expireTime = decodedJWT.getExpiresAt().toInstant();
|
94 |
/*Instant expireTime = decodedJWT.getExpiresAt().toInstant();
|
| 95 |
Instant currentTime = Instant.now();
|
95 |
Instant currentTime = Instant.now();
|
| 96 |
if(currentTime.toEpochMilli() > expireTime.toEpochMilli()) {
|
96 |
if(currentTime.toEpochMilli() > expireTime.toEpochMilli()) {
|
| 97 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.TOKEN, token, "USR_1012");
|
97 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.TOKEN, token, "USR_1012");
|
| 98 |
}
|
98 |
}*/
|
| 99 |
Map<String, Claim> claims = decodedJWT.getClaims();
|
99 |
Map<String, Claim> claims = decodedJWT.getClaims();
|
| 100 |
if(claims.containsKey(USER_ID)){
|
100 |
if(claims.containsKey(USER_ID)){
|
| 101 |
final Claim userIdclaim = claims.get(USER_ID);
|
101 |
final Claim userIdclaim = claims.get(USER_ID);
|
| 102 |
int userId = userIdclaim.asInt();
|
102 |
int userId = userIdclaim.asInt();
|
| 103 |
final Claim roleNamesClaim = claims.get(ROLE_NAMES);
|
103 |
final Claim roleNamesClaim = claims.get(ROLE_NAMES);
|
| Line 135... |
Line 135... |
| 135 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.TOKEN, token, "USR_1010");
|
135 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.TOKEN, token, "USR_1010");
|
| 136 |
} catch(InvalidClaimException invalidClaimException){
|
136 |
} catch(InvalidClaimException invalidClaimException){
|
| 137 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.TOKEN, token, "USR_1012");
|
137 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.TOKEN, token, "USR_1012");
|
| 138 |
}
|
138 |
}
|
| 139 |
}
|
139 |
}
|
| - |
|
140 |
|
| - |
|
141 |
public static void main(String[] args) throws Throwable{
|
| - |
|
142 |
String token = JWTUtil.create("amit.gupta@shop2020.in");
|
| - |
|
143 |
//System.out.println(token);
|
| - |
|
144 |
//System.out.println(JWTUtil.isExpired(token));
|
| - |
|
145 |
//System.out.println(JWTUtil.getUserInfo(token));
|
| - |
|
146 |
DecodedJWT decodeJwt = JWTUtil.parse("eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJwcm9maXRtYW5kaSIsImV4cCI6MTUxNDk3MDY4OSwiaWF0IjoxNTA5Nzg2Njg5LCJ1c2VySWQiOjMzMjM1LCJyb2xlTmFtZXMiOlsiVVNFUiJdfQ.C1lE6XvGpvQaCISG4IlJKwzEYWa3dWMLn1jXKB7fFvc");
|
| - |
|
147 |
System.out.println(decodeJwt.getExpiresAt());
|
| - |
|
148 |
}
|
| 140 |
}
|
149 |
}
|