mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-15 04:52:09 +08:00
jwt login support
This commit is contained in:
@@ -124,8 +124,9 @@ public class AuthJwtService {
|
||||
JWTClaimsSet claims = resolve(authToken);
|
||||
boolean isExpiration = claims.getExpirationTime().after(DateTime.now().toDate());
|
||||
boolean isVerify = hmac512Service.verify(authToken);
|
||||
_logger.trace("JWT Verify {} , now {} , ExpirationTime {} , isExpiration : {}" ,
|
||||
isVerify,DateTime.now().toDate(),claims.getExpirationTime(),isExpiration);
|
||||
_logger.debug("JWT Validate {} , Verify {} , now {} , ExpirationTime {} , isExpiration : {}" ,
|
||||
isVerify && isExpiration,isVerify,DateTime.now().toDate(),claims.getExpirationTime(),isExpiration);
|
||||
|
||||
return isVerify && isExpiration;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
|
||||
@@ -54,7 +54,7 @@ public class HttpJwtEntryPoint {
|
||||
JwtLoginService jwtLoginService;
|
||||
|
||||
@RequestMapping(value={"/jwt"}, produces = {MediaType.APPLICATION_JSON_VALUE})
|
||||
public ResponseEntity<?> jwt(@RequestParam(value = WebConstants.JWT_TOKEN_PARAMETER, required = false) String jwt) {
|
||||
public ResponseEntity<?> jwt(@RequestParam(value = WebConstants.JWT_TOKEN_PARAMETER, required = true) String jwt) {
|
||||
try {
|
||||
//for jwt Login
|
||||
_logger.debug("jwt : " + jwt);
|
||||
@@ -75,6 +75,32 @@ public class HttpJwtEntryPoint {
|
||||
|
||||
return new Message<AuthJwt>(Message.FAIL).buildResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* trust same HS512
|
||||
* @param jwt
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value={"/jwt/trust"}, produces = {MediaType.APPLICATION_JSON_VALUE})
|
||||
public ResponseEntity<?> jwtTrust(@RequestParam(value = WebConstants.JWT_TOKEN_PARAMETER, required = true) String jwt) {
|
||||
try {
|
||||
//for jwt Login
|
||||
_logger.debug("jwt : " + jwt);
|
||||
|
||||
if(authTokenService.validateJwtToken(jwt)) {
|
||||
String username =authTokenService.resolve(jwt).getSubject();
|
||||
LoginCredential loginCredential =new LoginCredential(username,"",ConstsLoginType.JWT);
|
||||
Authentication authentication = authenticationProvider.authenticate(loginCredential,true);
|
||||
_logger.debug("JWT Logined in , username " + username);
|
||||
AuthJwt authJwt = authTokenService.genAuthJwt(authentication);
|
||||
return new Message<AuthJwt>(authJwt).buildResponse();
|
||||
}
|
||||
}catch(Exception e) {
|
||||
_logger.error("Exception ",e);
|
||||
}
|
||||
|
||||
return new Message<AuthJwt>(Message.FAIL).buildResponse();
|
||||
}
|
||||
|
||||
|
||||
public void setApplicationConfig(ApplicationConfig applicationConfig) {
|
||||
|
||||
Reference in New Issue
Block a user