jwt login support

This commit is contained in:
MaxKey
2022-05-15 09:05:56 +08:00
parent f1f41fe7dc
commit 36ea37aff2
20 changed files with 181 additions and 68 deletions

View File

@@ -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) {

View File

@@ -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) {