HMAC512Service to Hmac512Service

This commit is contained in:
shimingxy
2024-11-07 14:42:29 +08:00
parent 18f6f86b24
commit 205acfaaeb
6 changed files with 14 additions and 14 deletions

View File

@@ -22,7 +22,7 @@ import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import org.dromara.maxkey.authn.SignPrincipal;
import org.dromara.maxkey.crypto.jwt.HMAC512Service;
import org.dromara.maxkey.crypto.jwt.Hmac512Service;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.web.WebContext;
import org.joda.time.DateTime;
@@ -38,7 +38,7 @@ import com.nimbusds.jwt.SignedJWT;
public class AuthJwtService {
private static final Logger _logger = LoggerFactory.getLogger(AuthJwtService.class);
HMAC512Service hmac512Service;
Hmac512Service hmac512Service;
/**
* JWT with Authentication
@@ -60,7 +60,7 @@ public class AuthJwtService {
.issueTime(currentDateTime.toDate())
.expirationTime(expirationTime)
.claim("locale", userInfo.getLocale())
.claim("kid", HMAC512Service.MXK_AUTH_JWK)
.claim("kid", Hmac512Service.MXK_AUTH_JWK)
.claim("institution", userInfo.getInstId())
.build();

View File

@@ -18,7 +18,7 @@
package org.dromara.maxkey.authn.jwt;
import org.dromara.maxkey.configuration.AuthJwkConfig;
import org.dromara.maxkey.crypto.jwt.HMAC512Service;
import org.dromara.maxkey.crypto.jwt.Hmac512Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
@@ -33,7 +33,7 @@ public class AuthRefreshTokenService extends AuthJwtService{
public AuthRefreshTokenService(AuthJwkConfig authJwkConfig) throws JOSEException {
this.authJwkConfig = authJwkConfig;
this.hmac512Service = new HMAC512Service(authJwkConfig.getRefreshSecret());
this.hmac512Service = new Hmac512Service(authJwkConfig.getRefreshSecret());
}
/**

View File

@@ -20,7 +20,7 @@ package org.dromara.maxkey.authn.jwt;
import java.text.ParseException;
import org.apache.commons.lang3.StringUtils;
import org.dromara.maxkey.configuration.AuthJwkConfig;
import org.dromara.maxkey.crypto.jwt.HMAC512Service;
import org.dromara.maxkey.crypto.jwt.Hmac512Service;
import org.dromara.maxkey.persistence.cache.MomentaryService;
import org.dromara.maxkey.web.WebContext;
import org.slf4j.Logger;
@@ -54,7 +54,7 @@ public class AuthTokenService extends AuthJwtService{
this.refreshTokenService = refreshTokenService;
this.hmac512Service = new HMAC512Service(authJwkConfig.getSecret());
this.hmac512Service = new Hmac512Service(authJwkConfig.getSecret());
}

View File

@@ -23,7 +23,7 @@ import java.util.Date;
import org.dromara.maxkey.authn.SignPrincipal;
import org.dromara.maxkey.authn.jwt.AuthTokenService;
import org.dromara.maxkey.configuration.ApplicationConfig;
import org.dromara.maxkey.crypto.jwt.HMAC512Service;
import org.dromara.maxkey.crypto.jwt.Hmac512Service;
import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.util.DateUtils;
import org.dromara.maxkey.web.WebContext;
@@ -107,7 +107,7 @@ public abstract class AbstractRemeberMeManager {
.jwtID(remeberMe.getId())
.issueTime(remeberMe.getLastLoginTime())
.expirationTime(remeberMe.getExpirationTime())
.claim("kid", HMAC512Service.MXK_AUTH_JWK)
.claim("kid", Hmac512Service.MXK_AUTH_JWK)
.build();
return authTokenService.signedJWT(remeberMeJwtClaims);

View File

@@ -31,7 +31,7 @@ import com.nimbusds.jose.jwk.KeyUse;
import com.nimbusds.jose.jwk.OctetSequenceKey;
import com.nimbusds.jose.util.Base64URL;
public class HMAC512Service {
public class Hmac512Service {
public static final String MXK_AUTH_JWK = "mxk_auth_jwk";
@@ -39,11 +39,11 @@ public class HMAC512Service {
MACVerifier verifier;
public HMAC512Service() {
public Hmac512Service() {
super();
}
public HMAC512Service(String secretString) throws JOSEException {
public Hmac512Service(String secretString) throws JOSEException {
Base64URL secret=new Base64URL(secretString);
OctetSequenceKey octKey= new OctetSequenceKey.Builder(secret)
.keyID(MXK_AUTH_JWK)

View File

@@ -17,7 +17,7 @@
package org.maxkey.crypto.signature;
import org.dromara.maxkey.crypto.jwt.HMAC512Service;
import org.dromara.maxkey.crypto.jwt.Hmac512Service;
import com.nimbusds.jose.JOSEException;
@@ -26,7 +26,7 @@ public class HMAC512ServiceTest {
public static void main(String[] args) throws JOSEException {
// TODO Auto-generated method stub
String key ="7heM-14BtxjyKPuH3ITIm7q2-ps5MuBirWCsrrdbzzSAOuSPrbQYiaJ54AeA0uH2XdkYy3hHAkTFIsieGkyqxOJZ_dQzrCbaYISH9rhUZAKYx8tUY0wkE4ArOC6LqHDJarR6UIcMsARakK9U4dhoOPO1cj74XytemI-w6ACYfzRUn_Rn4e-CQMcnD1C56oNEukwalf06xVgXl41h6K8IBEzLVod58y_VfvFn-NGWpNG0fy_Qxng6dg8Dgva2DobvzMN2eejHGLGB-x809MvC4zbG7CKNVlcrzMYDt2Gt2sOVDrt2l9YqJNfgaLFjrOEVw5cuXemGkX1MvHj6TAsbLg";
HMAC512Service HMAC512Service = new HMAC512Service(key);
Hmac512Service HMAC512Service = new Hmac512Service(key);
String sign = HMAC512Service.sign("{\"sub\":\"hkkkk\"}");
System.out.println(sign);
boolean isverify = HMAC512Service.verify(sign);