mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-07 17:38:32 +08:00
v3.0.0
This commit is contained in:
parent
5f4c44ec59
commit
2fdd018239
@ -24,6 +24,10 @@
|
|||||||
*(MAXKEY-210723) mgt登录错误提示信息
|
*(MAXKEY-210723) mgt登录错误提示信息
|
||||||
*(MAXKEY-210724) 依赖jar引用、更新和升级
|
*(MAXKEY-210724) 依赖jar引用、更新和升级
|
||||||
spring 5.3.10
|
spring 5.3.10
|
||||||
|
springBoot 2.5.5
|
||||||
|
springkafka 2.7.7
|
||||||
|
spring-cloud 3.0.4
|
||||||
|
springcloudalibabacspl 1.8.2
|
||||||
tomcat 9.0.53
|
tomcat 9.0.53
|
||||||
kafkaclients 2.8.1
|
kafkaclients 2.8.1
|
||||||
jibGradlePlugin 3.1.4
|
jibGradlePlugin 3.1.4
|
||||||
@ -31,10 +35,10 @@
|
|||||||
mysqlconnector 8.0.26
|
mysqlconnector 8.0.26
|
||||||
jedis 3.7.0
|
jedis 3.7.0
|
||||||
ehcache 3.9.6
|
ehcache 3.9.6
|
||||||
spring-cloud 3.0.3
|
|
||||||
springcloudalibabacspl 1.8.2
|
|
||||||
nacos 2.0.3
|
nacos 2.0.3
|
||||||
|
jacksonVersion 2.12.5
|
||||||
httpasyncclient 4.1.4
|
httpasyncclient 4.1.4
|
||||||
|
JustAuth 1.16.4
|
||||||
|
|
||||||
MaxKey v 2.9.0 GA 2021/08/24
|
MaxKey v 2.9.0 GA 2021/08/24
|
||||||
*(MAXKEY-210601) 企业微信扫描登录
|
*(MAXKEY-210601) 企业微信扫描登录
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#maxkey properties
|
#maxkey properties
|
||||||
group =maxkey.top
|
group =maxkey.top
|
||||||
version =2.9.0
|
version =3.0.0
|
||||||
vendor =https://www.maxkey.top
|
vendor =https://www.maxkey.top
|
||||||
author =MaxKeyTop
|
author =MaxKeyTop
|
||||||
|
|
||||||
@ -45,16 +45,16 @@ tomcatVersion =9.0.53
|
|||||||
tomcatembedloggingjuliVersion =8.5.2
|
tomcatembedloggingjuliVersion =8.5.2
|
||||||
#spring
|
#spring
|
||||||
springVersion =5.3.10
|
springVersion =5.3.10
|
||||||
springBootVersion =2.5.4
|
springBootVersion =2.5.5
|
||||||
springSecurityVersion =5.5.2
|
springSecurityVersion =5.5.2
|
||||||
springDataVersion =2.5.2
|
springDataVersion =2.5.2
|
||||||
springSessionVersion =2.5.2
|
springSessionVersion =2.5.2
|
||||||
springkafkaVersion =2.7.6
|
springkafkaVersion =2.7.7
|
||||||
springretryVersion =1.3.0
|
springretryVersion =1.3.0
|
||||||
springplugincoreVersion =2.0.0.RELEASE
|
springplugincoreVersion =2.0.0.RELEASE
|
||||||
springpluginmetadataVersion =2.0.0.RELEASE
|
springpluginmetadataVersion =2.0.0.RELEASE
|
||||||
springfoxVersion =3.0.0
|
springfoxVersion =3.0.0
|
||||||
springcloudVersion =3.0.3
|
springcloudVersion =3.0.4
|
||||||
springcloudalibabaVersion =2021.1
|
springcloudalibabaVersion =2021.1
|
||||||
springcloudalibabaspringVersion =1.0.11
|
springcloudalibabaspringVersion =1.0.11
|
||||||
springcloudalibabacsplVersion =1.8.2
|
springcloudalibabacsplVersion =1.8.2
|
||||||
@ -99,7 +99,7 @@ attoparserVersion =2.0.5.RELEASE
|
|||||||
unbescapeVersion =1.1.6.RELEASE
|
unbescapeVersion =1.1.6.RELEASE
|
||||||
jhlabsfiltersVersion =2.0.235-1
|
jhlabsfiltersVersion =2.0.235-1
|
||||||
slf4jVersion =1.7.32
|
slf4jVersion =1.7.32
|
||||||
jacksonVersion =2.12.4
|
jacksonVersion =2.12.5
|
||||||
bouncycastleVersion =1.64
|
bouncycastleVersion =1.64
|
||||||
junitVersion =4.11
|
junitVersion =4.11
|
||||||
mockitoallVersion =1.10.19
|
mockitoallVersion =1.10.19
|
||||||
@ -108,8 +108,8 @@ nimbusjosejwtVersion =9.4.1
|
|||||||
jcipannotationsVersion =1.0
|
jcipannotationsVersion =1.0
|
||||||
minidevjsonsmartVersion =2.3
|
minidevjsonsmartVersion =2.3
|
||||||
minidevasmVersion =1.0.2
|
minidevasmVersion =1.0.2
|
||||||
simplehttpVersion =1.0.3
|
simplehttpVersion =1.0.5
|
||||||
JustAuthVersion =1.16.3
|
JustAuthVersion =1.16.4
|
||||||
javassistVersion =3.23.0-GA
|
javassistVersion =3.23.0-GA
|
||||||
esapiVersion =2.2.0.0
|
esapiVersion =2.2.0.0
|
||||||
javaxmailVersion =1.6.2
|
javaxmailVersion =1.6.2
|
||||||
|
|||||||
@ -108,7 +108,7 @@ public class JwtAuthnAutoConfiguration implements InitializingBean {
|
|||||||
throws NoSuchAlgorithmException, InvalidKeySpecException, JOSEException {
|
throws NoSuchAlgorithmException, InvalidKeySpecException, JOSEException {
|
||||||
DefaultJwtEncryptionAndDecryptionService jwtEncryptionService =
|
DefaultJwtEncryptionAndDecryptionService jwtEncryptionService =
|
||||||
new DefaultJwtEncryptionAndDecryptionService(jwtSetKeyStore);
|
new DefaultJwtEncryptionAndDecryptionService(jwtSetKeyStore);
|
||||||
jwtEncryptionService.setDefaultAlgorithm(JWEAlgorithm.RSA1_5);//RSA1_5
|
jwtEncryptionService.setDefaultAlgorithm(JWEAlgorithm.RSA_OAEP_256);//RSA1_5
|
||||||
jwtEncryptionService.setDefaultDecryptionKeyId("maxkey_rsa");
|
jwtEncryptionService.setDefaultDecryptionKeyId("maxkey_rsa");
|
||||||
jwtEncryptionService.setDefaultEncryptionKeyId("maxkey_rsa");
|
jwtEncryptionService.setDefaultEncryptionKeyId("maxkey_rsa");
|
||||||
return jwtEncryptionService;
|
return jwtEncryptionService;
|
||||||
|
|||||||
@ -45,10 +45,10 @@ public class HmacOTP {
|
|||||||
return generateOTP(seed, count, digits);
|
return generateOTP(seed, count, digits);
|
||||||
} catch (InvalidKeyException e) {
|
} catch (InvalidKeyException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
LoggerFactory.getLogger(HmacOTP.class).error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
LoggerFactory.getLogger(HmacOTP.class).error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,13 +20,10 @@ package org.maxkey.password.onetimepwd.impl;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.maxkey.constants.ConstantsProperties;
|
|
||||||
import org.maxkey.entity.UserInfo;
|
import org.maxkey.entity.UserInfo;
|
||||||
import org.maxkey.password.onetimepwd.AbstractOtpAuthn;
|
import org.maxkey.password.onetimepwd.AbstractOtpAuthn;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
import org.springframework.core.io.Resource;
|
|
||||||
|
|
||||||
public class SmsOtpAuthn extends AbstractOtpAuthn {
|
public class SmsOtpAuthn extends AbstractOtpAuthn {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SmsOtpAuthn.class);
|
private static final Logger logger = LoggerFactory.getLogger(SmsOtpAuthn.class);
|
||||||
|
|||||||
@ -41,7 +41,7 @@ public class TimeBasedOTPTest {
|
|||||||
|
|
||||||
byte[]byteseed= Base32Utils.decode("DCGAGPE2BCDBD6D3FG4NX2QGACVIHXP4");//HexUtils.hex2Bytes( "a1270caecf007f2303cc9db12597a9694ff541aa");
|
byte[]byteseed= Base32Utils.decode("DCGAGPE2BCDBD6D3FG4NX2QGACVIHXP4");//HexUtils.hex2Bytes( "a1270caecf007f2303cc9db12597a9694ff541aa");
|
||||||
String seed=Base32Utils.encode(byteseed);
|
String seed=Base32Utils.encode(byteseed);
|
||||||
|
System.out.println(seed);
|
||||||
String hexString=Hex.encodeHexString(byteseed);
|
String hexString=Hex.encodeHexString(byteseed);
|
||||||
//String hexString=HexUtils.bytes2HexString(byteseed);
|
//String hexString=HexUtils.bytes2HexString(byteseed);
|
||||||
System.out.println(hexString);
|
System.out.println(hexString);
|
||||||
|
|||||||
@ -59,7 +59,8 @@ public class SocialSignOnProviderService{
|
|||||||
}else if(provider.equalsIgnoreCase("qq")) {
|
}else if(provider.equalsIgnoreCase("qq")) {
|
||||||
authRequest = new AuthQqRequest(authConfig);
|
authRequest = new AuthQqRequest(authConfig);
|
||||||
}else if(provider.equalsIgnoreCase("Alipay")) {
|
}else if(provider.equalsIgnoreCase("Alipay")) {
|
||||||
authRequest = new AuthAlipayRequest(authConfig);
|
String alipayPublicKey = "";
|
||||||
|
authRequest = new AuthAlipayRequest(authConfig,alipayPublicKey);
|
||||||
}else if(provider.equalsIgnoreCase("Twitter")) {
|
}else if(provider.equalsIgnoreCase("Twitter")) {
|
||||||
authRequest = new AuthTwitterRequest(authConfig);
|
authRequest = new AuthTwitterRequest(authConfig);
|
||||||
}else if(provider.equalsIgnoreCase("google")) {
|
}else if(provider.equalsIgnoreCase("google")) {
|
||||||
|
|||||||
@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* NameUtil.java
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.maxkey.crypto.cert;
|
|
||||||
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import javax.security.auth.x500.X500Principal;
|
|
||||||
|
|
||||||
import org.bouncycastle.asn1.x509.X509Name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides utility methods relating to X50* names.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public final class NameUtil {
|
|
||||||
/**
|
|
||||||
* Private to prevent construction.
|
|
||||||
*/
|
|
||||||
private NameUtil() {
|
|
||||||
// Nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the common name from the given X509Name.
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* the X.509 name
|
|
||||||
* @return the common name, null if not found
|
|
||||||
*/
|
|
||||||
public static String getCommonName(X509Name name) {
|
|
||||||
if (name == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector<?> values = name.getValues(X509Name.CN);
|
|
||||||
if (values == null || values.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return values.get(0).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the common name from the given X500Principal.
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* the X.500 principal
|
|
||||||
* @return the common name, null if not found
|
|
||||||
*/
|
|
||||||
public static String getCommonName(X500Principal name) {
|
|
||||||
if (name == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return getCommonName(new X509Name(name.getName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -29,7 +29,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.bouncycastle.asn1.DERInteger;
|
import org.bouncycastle.asn1.ASN1Integer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String utilities.
|
* String utilities.
|
||||||
@ -64,9 +64,9 @@ public class StringUtil
|
|||||||
{
|
{
|
||||||
bigInt = new BigInteger(1, (byte[]) obj);
|
bigInt = new BigInteger(1, (byte[]) obj);
|
||||||
}
|
}
|
||||||
else if (obj instanceof DERInteger)
|
else if (obj instanceof ASN1Integer)
|
||||||
{
|
{
|
||||||
bigInt = ((DERInteger) obj).getValue();
|
bigInt = ((ASN1Integer) obj).getValue();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -25,18 +25,13 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
import java.security.PrivateKey;
|
|
||||||
import java.security.PublicKey;
|
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.security.SignatureException;
|
import java.security.SignatureException;
|
||||||
import java.security.cert.Certificate;
|
import java.security.cert.Certificate;
|
||||||
@ -48,27 +43,12 @@ import java.text.MessageFormat;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Hashtable;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import javax.security.auth.x500.X500Principal;
|
import javax.security.auth.x500.X500Principal;
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.bouncycastle.asn1.DERObjectIdentifier;
|
|
||||||
import org.bouncycastle.asn1.x500.X500Name;
|
|
||||||
import org.bouncycastle.asn1.x509.X509Name;
|
|
||||||
import org.bouncycastle.cert.X509v3CertificateBuilder;
|
|
||||||
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
|
|
||||||
import org.bouncycastle.jce.PKCS10CertificationRequest;
|
|
||||||
import org.bouncycastle.jce.PrincipalUtil;
|
|
||||||
import org.bouncycastle.jce.X509Principal;
|
|
||||||
import org.bouncycastle.openssl.PEMParser;
|
import org.bouncycastle.openssl.PEMParser;
|
||||||
import org.bouncycastle.openssl.PEMWriter;
|
|
||||||
import org.bouncycastle.openssl.PasswordException;
|
|
||||||
import org.bouncycastle.x509.X509V3CertificateGenerator;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -82,16 +62,16 @@ public final class X509CertUtils {
|
|||||||
// Logger.getLogger(X509CertUtil.class.getCanonicalName());
|
// Logger.getLogger(X509CertUtil.class.getCanonicalName());
|
||||||
private static final Logger _logger = LoggerFactory.getLogger(X509CertUtils.class);
|
private static final Logger _logger = LoggerFactory.getLogger(X509CertUtils.class);
|
||||||
/** PKCS #7 encoding name */
|
/** PKCS #7 encoding name */
|
||||||
private static final String PKCS7_ENCODING = "PKCS7";
|
public static final String PKCS7_ENCODING = "PKCS7";
|
||||||
|
|
||||||
/** PkiPath encoding name */
|
/** PkiPath encoding name */
|
||||||
private static final String PKIPATH_ENCODING = "PkiPath";
|
public static final String PKIPATH_ENCODING = "PkiPath";
|
||||||
|
|
||||||
/** OpenSSL PEM encoding name */
|
/** OpenSSL PEM encoding name */
|
||||||
private static final String OPENSSL_PEM_ENCODING = "OpenSSL_PEM";
|
public static final String OPENSSL_PEM_ENCODING = "OpenSSL_PEM";
|
||||||
|
|
||||||
/** Type name for X.509 certificates */
|
/** Type name for X.509 certificates */
|
||||||
private static final String X509_CERT_TYPE = "X.509";
|
public static final String X509_CERT_TYPE = "X.509";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private to prevent construction.
|
* Private to prevent construction.
|
||||||
@ -100,40 +80,7 @@ public final class X509CertUtils {
|
|||||||
// Nothing to do
|
// Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Load one or more certificates from the specified URL, trying a built in
|
|
||||||
* list of certification encodings.
|
|
||||||
*
|
|
||||||
* @param url
|
|
||||||
* The URL to load certificates from
|
|
||||||
* @param exceptions
|
|
||||||
* Collection where exceptions occurred will be added
|
|
||||||
* @return The certificates
|
|
||||||
* @throws IOException
|
|
||||||
* if an error accessing the URL occurs
|
|
||||||
*/
|
|
||||||
public static X509Certificate[] loadCertificates(URL url,
|
|
||||||
Collection<Exception> exceptions) throws IOException {
|
|
||||||
URL downloadedUrl = NetUtil.download(url);
|
|
||||||
|
|
||||||
X509Certificate[] certs = null;
|
|
||||||
for (String certType : new String[] { PKCS7_ENCODING, PKIPATH_ENCODING,
|
|
||||||
null, OPENSSL_PEM_ENCODING }) {
|
|
||||||
try {
|
|
||||||
certs = loadCertificates(downloadedUrl, certType);
|
|
||||||
break; // Success!
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
// Don't bother with rest of the types, just show the exception
|
|
||||||
// once
|
|
||||||
exceptions.add(e);
|
|
||||||
break;
|
|
||||||
} catch (Exception e) {
|
|
||||||
exceptions.add(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return certs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static X509Certificate loadCertFromPEM(String strPEM) {
|
public static X509Certificate loadCertFromPEM(String strPEM) {
|
||||||
StringReader stringReader = new StringReader(strPEM);
|
StringReader stringReader = new StringReader(strPEM);
|
||||||
@ -179,109 +126,7 @@ public final class X509CertUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Load one or more certificates from the specified URL.
|
|
||||||
*
|
|
||||||
* @param url
|
|
||||||
* The URL to load certificates from
|
|
||||||
* @param encoding
|
|
||||||
* The certification path encoding. If null, treat as a normal
|
|
||||||
* certificate, not certification path. Use one of the
|
|
||||||
* <code>*_ENCODING</code> constants here.
|
|
||||||
* @return The certificates
|
|
||||||
* @throws CryptoException
|
|
||||||
* Problem encountered while loading the certificate(s)
|
|
||||||
* @throws FileNotFoundException
|
|
||||||
* If the certificate file does not exist, is a directory rather
|
|
||||||
* than a regular file, or for some other reason cannot be
|
|
||||||
* opened for reading
|
|
||||||
* @throws IOException
|
|
||||||
* An I/O error occurred
|
|
||||||
*/
|
|
||||||
private static X509Certificate[] loadCertificates(URL url, String encoding)
|
|
||||||
throws CryptoException, IOException {
|
|
||||||
// TODO: connect/read timeouts
|
|
||||||
|
|
||||||
InputStream in = NetUtil.openGetStream(url);
|
|
||||||
Collection certs;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (OPENSSL_PEM_ENCODING.equals(encoding)) {
|
|
||||||
// Special case; this is not a real JCE supported encoding.
|
|
||||||
// Note: let PEMReader use its default provider (BC as of BC
|
|
||||||
// 1.40) internally; for example the
|
|
||||||
// default "SUN" provider may not contain an RSA implementation
|
|
||||||
PEMParser pr = new PEMParser(new InputStreamReader(in));
|
|
||||||
|
|
||||||
// These beasts can contain just about anything, and
|
|
||||||
// unfortunately the PEMReader API (as of BC
|
|
||||||
// 1.25 to at least 1.43) won't allow us to really skip things
|
|
||||||
// we're not interested in; stuff
|
|
||||||
// happens already in readObject().
|
|
||||||
|
|
||||||
certs = new ArrayList<X509Certificate>();
|
|
||||||
Object cert;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
cert = pr.readObject();
|
|
||||||
} catch (IOException e) {
|
|
||||||
if (e instanceof PasswordException) {
|
|
||||||
// Some kind of a password protected item (BC >=
|
|
||||||
// 1.44): carry on, see
|
|
||||||
// http://www.bouncycastle.org/jira/browse/BJA-182
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cert == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cert instanceof X509Certificate) {
|
|
||||||
certs.add(cert);
|
|
||||||
}
|
|
||||||
// Skip other stuff, at least for now.
|
|
||||||
}
|
|
||||||
|
|
||||||
pr.close();
|
|
||||||
} else {
|
|
||||||
CertificateFactory cf = CertificateFactory
|
|
||||||
.getInstance(X509_CERT_TYPE);
|
|
||||||
|
|
||||||
if (encoding != null) {
|
|
||||||
// Try it as a certification path of the specified type
|
|
||||||
certs = cf.generateCertPath(in, encoding).getCertificates();
|
|
||||||
} else {
|
|
||||||
// "Normal" certificate(s)
|
|
||||||
certs = cf.generateCertificates(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note that we rely on cf.generateCert() above to never return
|
|
||||||
// null nor a collection
|
|
||||||
// containing nulls.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Some RuntimeExceptions which really should be CertificateExceptions
|
|
||||||
// may be thrown from
|
|
||||||
// cf.generateCert* above, for example Oracle's PKCS #7 parser tends to
|
|
||||||
// throw them... :P
|
|
||||||
catch (Exception ex) {
|
|
||||||
// TODO: don't throw if vCerts non-empty (eg. OpenSSL PEM above)?
|
|
||||||
throw new CryptoException("Could not load certificate.", ex);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
in.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
_logger.warn("Could not close input stream from " + url, e);
|
|
||||||
// LOG.log(Level.WARNING, "Could not close input stream from " +
|
|
||||||
// url, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (X509Certificate[]) certs.toArray(new X509Certificate[certs.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a CRL from the specified URL.
|
* Load a CRL from the specified URL.
|
||||||
@ -318,50 +163,7 @@ public final class X509CertUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Load a CSR from the specified URL.
|
|
||||||
*
|
|
||||||
* @param url
|
|
||||||
* The URL to load CSR from
|
|
||||||
* @return The CSR
|
|
||||||
* @throws CryptoException
|
|
||||||
* Problem encountered while loading the CSR
|
|
||||||
* @throws FileNotFoundException
|
|
||||||
* If the CSR file does not exist, is a directory rather than a
|
|
||||||
* regular file, or for some other reason cannot be opened for
|
|
||||||
* reading
|
|
||||||
* @throws IOException
|
|
||||||
* An I/O error occurred
|
|
||||||
*/
|
|
||||||
public static PKCS10CertificationRequest loadCSR(URL url)
|
|
||||||
throws CryptoException, IOException {
|
|
||||||
// TODO: handle DER encoded requests too?
|
|
||||||
PEMParser pr = new PEMParser(new InputStreamReader(
|
|
||||||
NetUtil.openGetStream(url)));
|
|
||||||
try {
|
|
||||||
PKCS10CertificationRequest csr = (PKCS10CertificationRequest) pr
|
|
||||||
.readObject();
|
|
||||||
if (!csr.verify()) {
|
|
||||||
throw new CryptoException(
|
|
||||||
"Could not verify certification request.");
|
|
||||||
}
|
|
||||||
return csr;
|
|
||||||
} catch (ClassCastException ex) {
|
|
||||||
throw new CryptoException("Could not load certification request.",
|
|
||||||
ex);
|
|
||||||
} catch (GeneralSecurityException ex) {
|
|
||||||
throw new CryptoException("Could not load certification request.",
|
|
||||||
ex);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
pr.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
_logger.warn("Could not close input stream from " + url, e);
|
|
||||||
// LOG.log(Level.WARNING, "Could not close input stream from " +
|
|
||||||
// url, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the supplied array of certificate objects into X509Certificate
|
* Convert the supplied array of certificate objects into X509Certificate
|
||||||
@ -574,249 +376,8 @@ public final class X509CertUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a self-signed X509 Version 1 certificate for the supplied key
|
|
||||||
* pair and signature algorithm.
|
|
||||||
*
|
|
||||||
* @return The generated certificate
|
|
||||||
* @param sCommonName
|
|
||||||
* Common name certificate attribute
|
|
||||||
* @param sOrganisationUnit
|
|
||||||
* Organization Unit certificate attribute
|
|
||||||
* @param sOrganisation
|
|
||||||
* Organization certificate attribute
|
|
||||||
* @param sLocality
|
|
||||||
* Locality certificate
|
|
||||||
* @param sState
|
|
||||||
* State certificate attribute
|
|
||||||
* @param sEmailAddress
|
|
||||||
* Email Address certificate attribute
|
|
||||||
* @param sCountryCode
|
|
||||||
* Country Code certificate attribute
|
|
||||||
* @param iValidity
|
|
||||||
* Validity period of certificate in days
|
|
||||||
* @param publicKey
|
|
||||||
* Public part of key pair
|
|
||||||
* @param privateKey
|
|
||||||
* Private part of key pair
|
|
||||||
* @param signatureType
|
|
||||||
* Signature Type
|
|
||||||
* @throws CryptoException
|
|
||||||
* If there was a problem generating the certificate
|
|
||||||
*/
|
|
||||||
public static X509Certificate generateCert(String sCommonName,
|
|
||||||
String sOrganisationUnit, String sOrganisation, String sLocality,
|
|
||||||
String sState, String sCountryCode, String sEmailAddress,
|
|
||||||
int iValidity, PublicKey publicKey, PrivateKey privateKey,
|
|
||||||
SignatureType signatureType) throws CryptoException {
|
|
||||||
// Holds certificate attributes
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Hashtable<DERObjectIdentifier, String> attrs = new Hashtable<DERObjectIdentifier, String>();
|
|
||||||
Vector<DERObjectIdentifier> vOrder = new Vector<DERObjectIdentifier>();
|
|
||||||
|
|
||||||
// Load certificate attributes
|
|
||||||
/*
|
|
||||||
if (sCommonName != null) {
|
|
||||||
attrs.put(X509Name.CN, sCommonName);
|
|
||||||
vOrder.add(0, X509Name.CN);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sOrganisationUnit != null) {
|
|
||||||
attrs.put(X509Name.OU, sOrganisationUnit);
|
|
||||||
vOrder.add(0, X509Name.OU);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sOrganisation != null) {
|
|
||||||
attrs.put(X509Name.O, sOrganisation);
|
|
||||||
vOrder.add(0, X509Name.O);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sLocality != null) {
|
|
||||||
attrs.put(X509Name.L, sLocality);
|
|
||||||
vOrder.add(0, X509Name.L);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sState != null) {
|
|
||||||
attrs.put(X509Name.ST, sState);
|
|
||||||
vOrder.add(0, X509Name.ST);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sCountryCode != null) {
|
|
||||||
attrs.put(X509Name.C, sCountryCode);
|
|
||||||
vOrder.add(0, X509Name.C);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sEmailAddress != null) {
|
|
||||||
attrs.put(X509Name.E, sEmailAddress);
|
|
||||||
vOrder.add(0, X509Name.E);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Get an X509 Version 1 Certificate generator
|
|
||||||
X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
|
|
||||||
|
|
||||||
// Load the generator with generation parameters
|
|
||||||
|
|
||||||
// Set the issuer distinguished name
|
|
||||||
certGen.setIssuerDN(new X509Principal(vOrder, attrs));
|
|
||||||
|
|
||||||
// Valid before and after dates now to iValidity days in the future
|
|
||||||
certGen.setNotBefore(new Date(System.currentTimeMillis()));
|
|
||||||
certGen.setNotAfter(new Date(System.currentTimeMillis()
|
|
||||||
+ ((long) iValidity * 24 * 60 * 60 * 1000)));
|
|
||||||
|
|
||||||
// Set the subject distinguished name (same as issuer for our purposes)
|
|
||||||
certGen.setSubjectDN(new X509Principal(vOrder, attrs));
|
|
||||||
|
|
||||||
// Set the public key
|
|
||||||
certGen.setPublicKey(publicKey);
|
|
||||||
|
|
||||||
// Set the algorithm
|
|
||||||
certGen.setSignatureAlgorithm(signatureType.name());
|
|
||||||
|
|
||||||
// Set the serial number
|
|
||||||
certGen.setSerialNumber(generateX509SerialNumber());
|
|
||||||
|
|
||||||
X509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder(
|
|
||||||
new X500Name("issueDn"),
|
|
||||||
generateX509SerialNumber(),
|
|
||||||
new Date(System.currentTimeMillis()),
|
|
||||||
new Date(System.currentTimeMillis()+ ((long) iValidity * 24 * 60 * 60 * 1000)),
|
|
||||||
new X500Name("subjectDn"),
|
|
||||||
publicKey);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Generate an X.509 certificate, based on the current issuer and
|
|
||||||
// subject
|
|
||||||
return certGen.generate(privateKey, "BC");
|
|
||||||
}
|
|
||||||
// Something went wrong
|
|
||||||
catch (GeneralSecurityException ex) {
|
|
||||||
throw new CryptoException("Certificate generation failed.", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renew a self-signed X509 Version 1 certificate.
|
|
||||||
*
|
|
||||||
* @return The renewed certificate
|
|
||||||
* @param oldCert
|
|
||||||
* old certificate
|
|
||||||
* @param iValidity
|
|
||||||
* Validity period of certificate in days to add to the old
|
|
||||||
* cert's expiry date, or current time if the certificate has
|
|
||||||
* expired
|
|
||||||
* @param publicKey
|
|
||||||
* Public part of key pair
|
|
||||||
* @param privateKey
|
|
||||||
* Private part of key pair
|
|
||||||
* @throws CryptoException
|
|
||||||
* If there was a problem generating the certificate
|
|
||||||
*/
|
|
||||||
public static X509Certificate renewCert(X509Certificate oldCert,
|
|
||||||
int iValidity, PublicKey publicKey, PrivateKey privateKey)
|
|
||||||
throws CryptoException {
|
|
||||||
// Get an X509 Version 1 Certificate generator
|
|
||||||
X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
|
|
||||||
|
|
||||||
// Load the generator with generation parameters
|
|
||||||
|
|
||||||
// Valid before and after dates now to iValidity days in the future from
|
|
||||||
// now or existing expiry date
|
|
||||||
Date now = new Date();
|
|
||||||
Date oldExpiry = oldCert.getNotAfter();
|
|
||||||
if (oldExpiry == null || oldExpiry.before(now)) {
|
|
||||||
oldExpiry = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
certGen.setNotBefore(now);
|
|
||||||
certGen.setNotAfter(new Date(oldExpiry.getTime()
|
|
||||||
+ ((long) iValidity * 24 * 60 * 60 * 1000)));
|
|
||||||
|
|
||||||
// Set the public key
|
|
||||||
certGen.setPublicKey(publicKey);
|
|
||||||
|
|
||||||
// Set the algorithm
|
|
||||||
certGen.setSignatureAlgorithm(oldCert.getSigAlgName());
|
|
||||||
|
|
||||||
// Set the serial number
|
|
||||||
certGen.setSerialNumber(generateX509SerialNumber());
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Set the issuer distinguished name
|
|
||||||
// TODO: verify/force self-signedness
|
|
||||||
certGen.setIssuerDN(PrincipalUtil.getIssuerX509Principal(oldCert));
|
|
||||||
|
|
||||||
// Set the subject distinguished name (same as issuer for our
|
|
||||||
// purposes)
|
|
||||||
certGen.setSubjectDN(PrincipalUtil.getSubjectX509Principal(oldCert));
|
|
||||||
|
|
||||||
// Generate an X.509 certificate, based on the current issuer and
|
|
||||||
// subject
|
|
||||||
return certGen.generate(privateKey, "BC");
|
|
||||||
}
|
|
||||||
// Something went wrong
|
|
||||||
catch (GeneralSecurityException ex) {
|
|
||||||
throw new CryptoException("Certificate generation failed.", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a unique serial number for use as an X509 serial number.
|
|
||||||
*
|
|
||||||
* @return The unique serial number
|
|
||||||
*/
|
|
||||||
private static BigInteger generateX509SerialNumber() {
|
|
||||||
// Time in seconds
|
|
||||||
return new BigInteger(Long.toString(System.currentTimeMillis() / 1000));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String generatePEMEncoded(Certificate cert) {
|
|
||||||
StringWriter encoded = new StringWriter();
|
|
||||||
PEMWriter pEMWriter = new PEMWriter(encoded);
|
|
||||||
try {
|
|
||||||
pEMWriter.writeObject(cert);
|
|
||||||
pEMWriter.close();
|
|
||||||
return encoded.toString();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a PKCS #10 certification request (CSR) using the supplied
|
|
||||||
* certificate and private key.
|
|
||||||
*
|
|
||||||
* @param cert
|
|
||||||
* The certificate
|
|
||||||
* @param privateKey
|
|
||||||
* The private key
|
|
||||||
* @throws CryptoException
|
|
||||||
* If there was a problem generating the CSR
|
|
||||||
* @return The CSR
|
|
||||||
*/
|
|
||||||
public static PKCS10CertificationRequest generatePKCS10CSR(
|
|
||||||
X509Certificate cert, PrivateKey privateKey) throws CryptoException {
|
|
||||||
X509Name subject = new X509Name(cert.getSubjectDN().toString());
|
|
||||||
|
|
||||||
try {
|
|
||||||
PKCS10CertificationRequest csr = new PKCS10CertificationRequest(
|
|
||||||
cert.getSigAlgName(), subject, cert.getPublicKey(), null,
|
|
||||||
privateKey);
|
|
||||||
if (!csr.verify()) {
|
|
||||||
throw new CryptoException(
|
|
||||||
"Could not verify generated certification request.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return csr;
|
|
||||||
} catch (GeneralSecurityException ex) {
|
|
||||||
throw new CryptoException(
|
|
||||||
"Could not generate a certification request.", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify that one X.509 certificate was signed using the private key that
|
* Verify that one X.509 certificate was signed using the private key that
|
||||||
* corresponds to the public key of a second certificate.
|
* corresponds to the public key of a second certificate.
|
||||||
@ -1008,22 +569,42 @@ public final class X509CertUtils {
|
|||||||
X500Principal subject = cert.getSubjectX500Principal();
|
X500Principal subject = cert.getSubjectX500Principal();
|
||||||
X500Principal issuer = cert.getIssuerX500Principal();
|
X500Principal issuer = cert.getIssuerX500Principal();
|
||||||
|
|
||||||
String sSubjectCN = NameUtil.getCommonName(subject);
|
String sSubjectCN = getCommonName(subject);
|
||||||
|
|
||||||
// Could not get a subject CN - return blank
|
// Could not get a subject CN - return blank
|
||||||
if (sSubjectCN == null) {
|
if (sSubjectCN == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
String sIssuerCN = NameUtil.getCommonName(issuer);
|
String sIssuerCN = getCommonName(issuer);
|
||||||
|
|
||||||
// Self-signed certificate or could not get an issuer CN
|
// Self-signed certificate or could not get an issuer CN
|
||||||
if (subject.equals(issuer) || sIssuerCN == null) {
|
if (subject.equals(issuer) || sIssuerCN == null) {
|
||||||
// Alias is the subject CN
|
// Alias is the subject CN
|
||||||
return sSubjectCN;
|
return sSubjectCN;
|
||||||
}
|
}
|
||||||
|
_logger.debug("{0} ({1})", sSubjectCN, sIssuerCN);
|
||||||
// else non-self-signed certificate
|
// else non-self-signed certificate
|
||||||
// Alias is the subject CN followed by the issuer CN in parenthesis
|
// Alias is the subject CN followed by the issuer CN in parenthesis
|
||||||
return MessageFormat.format("{0} ({1})", sSubjectCN, sIssuerCN);
|
return MessageFormat.format("{0} ({1})", sSubjectCN, sIssuerCN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getCommonName(X500Principal name) {
|
||||||
|
if (name == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String value = name.getName();
|
||||||
|
|
||||||
|
if(value.indexOf(",") > -1) {
|
||||||
|
value = value.split(",")[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(value.indexOf("=")>-1) {
|
||||||
|
value = value.split("=")[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,11 +61,15 @@ public final class X509V3CertGen {
|
|||||||
PrivateKey privateKey=keyPair.getPrivate();
|
PrivateKey privateKey=keyPair.getPrivate();
|
||||||
|
|
||||||
SubjectPublicKeyInfo subjectPublicKeyInfo = null;
|
SubjectPublicKeyInfo subjectPublicKeyInfo = null;
|
||||||
|
ASN1InputStream publicKeyInputStream =null;
|
||||||
try {
|
try {
|
||||||
Object aiStream=new ASN1InputStream(publicKey.getEncoded()).readObject();
|
publicKeyInputStream =new ASN1InputStream(publicKey.getEncoded());
|
||||||
|
Object aiStream=publicKeyInputStream.readObject();
|
||||||
subjectPublicKeyInfo = SubjectPublicKeyInfo.getInstance(aiStream);
|
subjectPublicKeyInfo = SubjectPublicKeyInfo.getInstance(aiStream);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if(publicKeyInputStream !=null)publicKeyInputStream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -23,14 +23,9 @@ package org.maxkey.crypto.jwt.encryption.service.impl;
|
|||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.spec.InvalidKeySpecException;
|
import java.security.spec.InvalidKeySpecException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.maxkey.crypto.jose.keystore.JWKSetKeyStore;
|
import org.maxkey.crypto.jose.keystore.JWKSetKeyStore;
|
||||||
import org.maxkey.crypto.jwt.encryption.service.JwtEncryptionAndDecryptionService;
|
import org.maxkey.crypto.jwt.encryption.service.JwtEncryptionAndDecryptionService;
|
||||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
import com.nimbusds.jose.JOSEException;
|
import com.nimbusds.jose.JOSEException;
|
||||||
import com.nimbusds.jose.jwk.JWKSet;
|
import com.nimbusds.jose.jwk.JWKSet;
|
||||||
|
|
||||||
|
|||||||
@ -34,9 +34,6 @@ import com.google.common.cache.LoadingCache;
|
|||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||||
import com.nimbusds.jose.jwk.JWK;
|
import com.nimbusds.jose.jwk.JWK;
|
||||||
import com.nimbusds.jose.jwk.KeyUse;
|
|
||||||
import com.nimbusds.jose.jwk.OctetSequenceKey;
|
|
||||||
import com.nimbusds.jose.util.Base64URL;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and caches symmetrical validators for clients based on client secrets.
|
* Creates and caches symmetrical validators for clients based on client secrets.
|
||||||
|
|||||||
@ -30,9 +30,6 @@ import org.maxkey.crypto.jwt.signer.service.JwtSigningAndValidationService;
|
|||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.nimbusds.jose.JOSEException;
|
import com.nimbusds.jose.JOSEException;
|
||||||
import com.nimbusds.jose.jwk.JWK;
|
import com.nimbusds.jose.jwk.JWK;
|
||||||
import com.nimbusds.jose.jwk.KeyUse;
|
|
||||||
import com.nimbusds.jose.jwk.OctetSequenceKey;
|
|
||||||
import com.nimbusds.jose.util.Base64URL;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Crystal.Sea
|
* @author Crystal.Sea
|
||||||
|
|||||||
@ -26,9 +26,7 @@ import java.util.Enumeration;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.util.ResourceUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* .
|
* .
|
||||||
|
|||||||
@ -56,6 +56,8 @@ import org.maxkey.crypto.Base64Utils;
|
|||||||
import org.maxkey.crypto.cert.CryptoException;
|
import org.maxkey.crypto.cert.CryptoException;
|
||||||
import org.maxkey.crypto.cert.X509CertUtils;
|
import org.maxkey.crypto.cert.X509CertUtils;
|
||||||
import org.maxkey.crypto.cert.X509V3CertGen;
|
import org.maxkey.crypto.cert.X509V3CertGen;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,6 +66,7 @@ import org.springframework.core.io.Resource;
|
|||||||
* UBER type keystores.
|
* UBER type keystores.
|
||||||
*/
|
*/
|
||||||
public final class KeyStoreUtil {
|
public final class KeyStoreUtil {
|
||||||
|
private static final Logger _logger = LoggerFactory.getLogger(KeyStoreUtil.class);
|
||||||
|
|
||||||
public static final String X509 = "X.509";
|
public static final String X509 = "X.509";
|
||||||
|
|
||||||
@ -536,15 +539,15 @@ public final class KeyStoreUtil {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
sMatchAlias = X509CertUtils.matchCertificate(keyStore, trustCert);
|
sMatchAlias = X509CertUtils.matchCertificate(keyStore, trustCert);
|
||||||
System.out.println("sMatchAlias : " + sMatchAlias);
|
_logger.debug("sMatchAlias : " + sMatchAlias);
|
||||||
if (sMatchAlias != null) {
|
if (sMatchAlias != null) {
|
||||||
System.out.println("The certificate already exists in the Keystore under alias ''" + sMatchAlias
|
_logger.debug("\nThe certificate already exists in the Keystore under alias ''" + sMatchAlias
|
||||||
+ "''.\nDo you still want to import it?");
|
+ "''.\nDo you still want to import it?");
|
||||||
} else {
|
} else {
|
||||||
KeyStore[] keyStores = { keyStore };
|
KeyStore[] keyStores = { keyStore };
|
||||||
if (X509CertUtils.establishTrust(keyStores, trustCert) == null) {
|
if (X509CertUtils.establishTrust(keyStores, trustCert) == null) {
|
||||||
System.out.println(
|
_logger.debug(
|
||||||
"Could not establish a trust path for the certficate.\nThe certficate information will now be displayed after\nwhich you may confirm whether or not you trust the\ncertificate.");
|
"\nCould not establish a trust path for the certficate.\nThe certficate information will now be displayed after\nwhich you may confirm whether or not you trust the certificate.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete old entry first
|
// Delete old entry first
|
||||||
|
|||||||
@ -58,6 +58,8 @@ public class BeanConvert {
|
|||||||
LogFactory.getLog(BeanConvert.class).debug("bean2Map() *******************************************");
|
LogFactory.getLog(BeanConvert.class).debug("bean2Map() *******************************************");
|
||||||
return mapBean;
|
return mapBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static <T> Object map2Bean(T bean,HashMap<?, ?> valueMap){
|
public static <T> Object map2Bean(T bean,HashMap<?, ?> valueMap){
|
||||||
Map<?, ?> beanFiledMap=null;
|
Map<?, ?> beanFiledMap=null;
|
||||||
try {
|
try {
|
||||||
@ -71,6 +73,7 @@ public class BeanConvert {
|
|||||||
LogFactory.getLog(BeanConvert.class).debug("map2Bean() "+bean.getClass().getName());
|
LogFactory.getLog(BeanConvert.class).debug("map2Bean() "+bean.getClass().getName());
|
||||||
int i=1;
|
int i=1;
|
||||||
while (fieldit.hasNext()) {
|
while (fieldit.hasNext()) {
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
Map.Entry entry = (Map.Entry) fieldit.next();
|
Map.Entry entry = (Map.Entry) fieldit.next();
|
||||||
String fieldName = entry.getKey().toString();
|
String fieldName = entry.getKey().toString();
|
||||||
Object value = null;
|
Object value = null;
|
||||||
|
|||||||
@ -167,7 +167,8 @@ public class BeanUtil {
|
|||||||
return Instance.newInstance(className, args);
|
return Instance.newInstance(className, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T newInstance(Class<T> cls, Object[] args) {
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> T newInstance(Class<T> cls, Object[] args) {
|
||||||
return (T) Instance.newInstance(cls, args);
|
return (T) Instance.newInstance(cls, args);
|
||||||
}
|
}
|
||||||
public static Object invokeMethod(Object bean, String methodName, Object[] args)
|
public static Object invokeMethod(Object bean, String methodName, Object[] args)
|
||||||
@ -201,7 +202,7 @@ public class BeanUtil {
|
|||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
for (int i = 0; i < flds.length; i++) {
|
for (int i = 0; i < flds.length; i++) {
|
||||||
String name = flds[i].getName();
|
String name = flds[i].getName();
|
||||||
map.put(flds[i].getName(), flds[i].getType().getName());
|
map.put(name, flds[i].getType().getName());
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
@ -311,10 +312,10 @@ public class BeanUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class[] getMethodParameterTypes(Class<?> c,String methodName){
|
public static Class<?>[] getMethodParameterTypes(Class<?> c,String methodName){
|
||||||
Method []methods=c.getMethods();
|
Method []methods=c.getMethods();
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
Class[] parameterTypes = method.getParameterTypes();
|
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||||
if(method.getName().equals(methodName)){
|
if(method.getName().equals(methodName)){
|
||||||
return parameterTypes;
|
return parameterTypes;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,7 +59,8 @@ public class DynaBean {
|
|||||||
beanMap.remove(name);
|
beanMap.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayValues(){
|
@SuppressWarnings("rawtypes")
|
||||||
|
public void displayValues(){
|
||||||
Iterator<?> beanMapit = beanMap.entrySet().iterator();
|
Iterator<?> beanMapit = beanMap.entrySet().iterator();
|
||||||
int i=1;
|
int i=1;
|
||||||
LogFactory.getLog(DynaBean.class).debug("displayValues() *******************************************");
|
LogFactory.getLog(DynaBean.class).debug("displayValues() *******************************************");
|
||||||
@ -84,7 +85,8 @@ public class DynaBean {
|
|||||||
return beanMap;
|
return beanMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DynaBean mapToDynaBean(Map<String, Object> map){
|
@SuppressWarnings("rawtypes")
|
||||||
|
public DynaBean mapToDynaBean(Map<String, Object> map){
|
||||||
|
|
||||||
if(map.getClass().getName()=="java.util.HashMap"){
|
if(map.getClass().getName()=="java.util.HashMap"){
|
||||||
beanMap=(HashMap<String, Object>)map;
|
beanMap=(HashMap<String, Object>)map;
|
||||||
|
|||||||
@ -62,7 +62,7 @@ public class Instance {
|
|||||||
Class<?> newClass;
|
Class<?> newClass;
|
||||||
try {
|
try {
|
||||||
newClass = Class.forName(className);
|
newClass = Class.forName(className);
|
||||||
Class[] argsClass = new Class[args.length];
|
Class<?>[] argsClass = new Class[args.length];
|
||||||
|
|
||||||
for (int i = 0, j = args.length; i < j; i++) {
|
for (int i = 0, j = args.length; i < j; i++) {
|
||||||
argsClass[i] = args[i].getClass();
|
argsClass[i] = args[i].getClass();
|
||||||
@ -79,7 +79,7 @@ public class Instance {
|
|||||||
|
|
||||||
public static <T> Object newInstance(Class<T> cls, Object[] args) {
|
public static <T> Object newInstance(Class<T> cls, Object[] args) {
|
||||||
try {
|
try {
|
||||||
Class[] argsClass = new Class[args.length];
|
Class<?>[] argsClass = new Class[args.length];
|
||||||
|
|
||||||
for (int i = 0, j = args.length; i < j; i++) {
|
for (int i = 0, j = args.length; i < j; i++) {
|
||||||
argsClass[i] = args[i].getClass();
|
argsClass[i] = args[i].getClass();
|
||||||
|
|||||||
@ -38,7 +38,7 @@ public class MethodInvoke {
|
|||||||
public static Object invokeMethod(Object bean, String methodName,
|
public static Object invokeMethod(Object bean, String methodName,
|
||||||
Object[] args) throws Exception {
|
Object[] args) throws Exception {
|
||||||
Class<? extends Object> beanClass = bean.getClass();
|
Class<? extends Object> beanClass = bean.getClass();
|
||||||
Class[] argsClass = new Class[args.length];
|
Class<?>[] argsClass = new Class[args.length];
|
||||||
for (int i = 0, j = args.length; i < j; i++) {
|
for (int i = 0, j = args.length; i < j; i++) {
|
||||||
argsClass[i] = args[i].getClass();
|
argsClass[i] = args[i].getClass();
|
||||||
//LogFactory.getLog(MethodInvoke.class).debug("invokeMethod args : "+args[i]+" argsClass:"+argsClass[i]);
|
//LogFactory.getLog(MethodInvoke.class).debug("invokeMethod args : "+args[i]+" argsClass:"+argsClass[i]);
|
||||||
@ -59,7 +59,7 @@ public class MethodInvoke {
|
|||||||
|
|
||||||
public static Object invokeStaticMethod(Class<?> beanClass, String methodName,
|
public static Object invokeStaticMethod(Class<?> beanClass, String methodName,
|
||||||
Object[] args) throws Exception {
|
Object[] args) throws Exception {
|
||||||
Class[] argsClass = new Class[args.length];
|
Class<?>[] argsClass = new Class[args.length];
|
||||||
for (int i = 0, j = args.length; i < j; i++) {
|
for (int i = 0, j = args.length; i < j; i++) {
|
||||||
argsClass[i] = args[i].getClass();
|
argsClass[i] = args[i].getClass();
|
||||||
//LogFactory.getLog(MethodInvoke.class).debug("invokeStaticMethod args : "+args[i]+" argsClass:"+argsClass[i]);
|
//LogFactory.getLog(MethodInvoke.class).debug("invokeStaticMethod args : "+args[i]+" argsClass:"+argsClass[i]);
|
||||||
|
|||||||
193
maxkey-common/src/test/java/org/maxkey/Copyright4RZ.java
Normal file
193
maxkey-common/src/test/java/org/maxkey/Copyright4RZ.java
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top ]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.maxkey;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 给java文件批量添加License信息.
|
||||||
|
* @author MaxKey Copyright Adder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Copyright4RZ {
|
||||||
|
// 存放java文件的文件夹,必须是文件夹
|
||||||
|
private static String srcFolder = "D:\\MaxKey\\Workspaces\\maxkey\\MaxKey\\maxkey-webs\\maxkey-web-mgt";
|
||||||
|
|
||||||
|
//已添加标识
|
||||||
|
private static String copyRightText = "http://www.apache.org/licenses/LICENSE-2.0";
|
||||||
|
//扫描目录
|
||||||
|
private String folder;
|
||||||
|
//待添加所以文件统计
|
||||||
|
private long fileCount = 0;
|
||||||
|
//添加的问题就统计
|
||||||
|
private long copyRightFileCount = 0;
|
||||||
|
private static String lineSeperator = System.getProperty("line.separator");
|
||||||
|
private static String encode = "UTF-8";
|
||||||
|
private static OutputStreamWriter writer;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
writer = new OutputStreamWriter(new FileOutputStream("D:/MaxKey/code.txt"), encode);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Copyright.
|
||||||
|
* @param folder java文件夹.
|
||||||
|
* @param copyRight 版权内容.
|
||||||
|
*/
|
||||||
|
public Copyright4RZ(String folder, String copyRight) {
|
||||||
|
this.folder = folder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main .
|
||||||
|
* @param args String
|
||||||
|
* @throws IOException IOException
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
// 从文件读取版权内容
|
||||||
|
// 在D盘创建一个copyright.txt文件,把版权内容放进去即可
|
||||||
|
String copyright = readCopyrightFromFile(
|
||||||
|
Copyright4RZ.class.getResource("copyright.txt").getFile());
|
||||||
|
new Copyright4RZ(srcFolder, copyright).process();
|
||||||
|
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* process.
|
||||||
|
* @throws IOException not
|
||||||
|
*/
|
||||||
|
public void process() throws IOException {
|
||||||
|
this.addCopyright(new File(folder));
|
||||||
|
System.out.println("fileCount " + fileCount);
|
||||||
|
System.out.println("copyRightFileCount " + copyRightFileCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addCopyright(File folder) throws IOException {
|
||||||
|
File[] files = folder.listFiles();
|
||||||
|
|
||||||
|
if (files == null || files.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (File f : files) {
|
||||||
|
if (f.isFile()) {
|
||||||
|
doAddCopyright(f);
|
||||||
|
} else {
|
||||||
|
addCopyright(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doAddCopyright(File file) throws IOException {
|
||||||
|
String fileName = file.getName();
|
||||||
|
boolean isJavaFile = fileName.toLowerCase().endsWith(".java");
|
||||||
|
//boolean isJavaFile = fileName.toLowerCase().endsWith(".ftl");
|
||||||
|
this.fileCount++;
|
||||||
|
if (isJavaFile) {
|
||||||
|
copyRightFileCount++;
|
||||||
|
System.out.println(file.getAbsolutePath());
|
||||||
|
try {
|
||||||
|
this.doWrite(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doWrite(File file) throws IOException {
|
||||||
|
StringBuilder javaFileContent = new StringBuilder();
|
||||||
|
String line = null;
|
||||||
|
boolean isAddCopyrightFile = isAddCopyrightFile(file.getAbsolutePath());
|
||||||
|
// 先添加copyright到文件头
|
||||||
|
//javaFileContent.append(copyRight).append(lineSeperator);
|
||||||
|
// 追加剩余内容
|
||||||
|
BufferedReader br = new BufferedReader(
|
||||||
|
new InputStreamReader(new FileInputStream(file), encode));
|
||||||
|
|
||||||
|
int i=0;
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
if(isAddCopyrightFile && i< 16) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(line.equals("")
|
||||||
|
||line.replaceAll(" ", "").equals("")
|
||||||
|
||line.replaceAll("\t", "").equals("")
|
||||||
|
) {
|
||||||
|
|
||||||
|
}else {
|
||||||
|
javaFileContent.append(line).append(lineSeperator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), encode);
|
||||||
|
writer.write(javaFileContent.toString());
|
||||||
|
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String readCopyrightFromFile(String copyFilePath) throws IOException {
|
||||||
|
StringBuilder copyright = new StringBuilder();
|
||||||
|
|
||||||
|
String line = null;
|
||||||
|
|
||||||
|
BufferedReader br = new BufferedReader(
|
||||||
|
new InputStreamReader(new FileInputStream(copyFilePath), encode));
|
||||||
|
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
copyright.append(line).append(lineSeperator);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
|
||||||
|
return copyright.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isAddCopyrightFile(String filePath) throws IOException {
|
||||||
|
boolean isAddCopyright = false;
|
||||||
|
String line = null;
|
||||||
|
|
||||||
|
BufferedReader br = new BufferedReader(
|
||||||
|
new InputStreamReader(new FileInputStream(filePath), encode));
|
||||||
|
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
if (line.indexOf(copyRightText) > -1) {
|
||||||
|
isAddCopyright = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
|
||||||
|
return isAddCopyright;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -22,11 +22,8 @@ package org.maxkey.cache;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.maxkey.cache.AbstractCache;
|
|
||||||
import org.maxkey.cache.CacheFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author amarsoft
|
* @author Crystal.sea
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class CacheFactoryTest {
|
public class CacheFactoryTest {
|
||||||
|
|||||||
@ -22,8 +22,6 @@ package org.maxkey.cache;
|
|||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.maxkey.cache.AbstractCache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author amarsoft
|
* @author amarsoft
|
||||||
*
|
*
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
package org.maxkey.crypto;
|
package org.maxkey.crypto;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.maxkey.crypto.Base64Utils;
|
|
||||||
|
|
||||||
public class Base64UtilsTest {
|
public class Base64UtilsTest {
|
||||||
|
|
||||||
|
|||||||
@ -18,10 +18,7 @@
|
|||||||
package org.maxkey.crypto;
|
package org.maxkey.crypto;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.maxkey.crypto.DigestUtils;
|
|
||||||
|
|
||||||
public class DigestUtilsTest {
|
public class DigestUtilsTest {
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -20,8 +20,6 @@ package org.maxkey.crypto;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
import org.maxkey.crypto.Md5Sum;
|
|
||||||
|
|
||||||
public class Md5SumTest {
|
public class Md5SumTest {
|
||||||
|
|
||||||
public Md5SumTest() {
|
public Md5SumTest() {
|
||||||
|
|||||||
@ -21,13 +21,11 @@ import java.security.Key;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.maxkey.crypto.Base64Utils;
|
|
||||||
import org.maxkey.crypto.HexUtils;
|
|
||||||
import org.maxkey.crypto.RSAUtils;
|
|
||||||
|
|
||||||
public class RSAUtilsTest {
|
public class RSAUtilsTest {
|
||||||
|
|
||||||
//@Test
|
@Test
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
|
|
||||||
// ˽Կ<EFBFBD><EFBFBD><EFBFBD>ܡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// ˽Կ<EFBFBD><EFBFBD><EFBFBD>ܡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|||||||
@ -20,7 +20,6 @@ package org.maxkey.crypto;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.maxkey.crypto.ReciprocalUtils;
|
|
||||||
|
|
||||||
public class ReciprocalUtilsTest {
|
public class ReciprocalUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -26,11 +26,10 @@ import java.util.Date;
|
|||||||
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.maxkey.crypto.cert.X509V3CertGen;
|
|
||||||
|
|
||||||
public class X509V3CertGenTest {
|
public class X509V3CertGenTest {
|
||||||
|
|
||||||
//@Test
|
@Test
|
||||||
public void generateV3() throws Exception {
|
public void generateV3() throws Exception {
|
||||||
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
|
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
|
||||||
KeyPair keyPair =X509V3CertGen.genRSAKeyPair();
|
KeyPair keyPair =X509V3CertGen.genRSAKeyPair();
|
||||||
|
|||||||
@ -21,7 +21,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.maxkey.crypto.KeyPairUtil;
|
import org.maxkey.crypto.KeyPairUtil;
|
||||||
import org.maxkey.crypto.signature.DsaSigner;
|
|
||||||
|
|
||||||
public final class DsaSignerTest {
|
public final class DsaSignerTest {
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -24,7 +24,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.maxkey.crypto.KeyPairUtil;
|
import org.maxkey.crypto.KeyPairUtil;
|
||||||
import org.maxkey.crypto.signature.RsaSigner;
|
|
||||||
|
|
||||||
|
|
||||||
public final class RsaSignerTest {
|
public final class RsaSignerTest {
|
||||||
|
|||||||
@ -20,7 +20,6 @@ package org.maxkey.mail;
|
|||||||
import org.apache.commons.mail.DefaultAuthenticator;
|
import org.apache.commons.mail.DefaultAuthenticator;
|
||||||
import org.apache.commons.mail.Email;
|
import org.apache.commons.mail.Email;
|
||||||
import org.apache.commons.mail.SimpleEmail;
|
import org.apache.commons.mail.SimpleEmail;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class MailTest {
|
public class MailTest {
|
||||||
|
|
||||||
|
|||||||
@ -95,6 +95,7 @@ END:VCARD
|
|||||||
"REV:2008-04-24T19:52:43Z\n" +
|
"REV:2008-04-24T19:52:43Z\n" +
|
||||||
"END:VCARD\n" ;
|
"END:VCARD\n" ;
|
||||||
|
|
||||||
|
System.out.println(str);
|
||||||
//String str = "CN:男;COP:公司;ZW:职务";// 二维码内容
|
//String str = "CN:男;COP:公司;ZW:职务";// 二维码内容
|
||||||
String path = "D:\\hwy.png";
|
String path = "D:\\hwy.png";
|
||||||
BitMatrix byteMatrix;
|
BitMatrix byteMatrix;
|
||||||
|
|||||||
@ -19,8 +19,6 @@ package org.maxkey.util;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.maxkey.util.DateUtils;
|
|
||||||
|
|
||||||
public class DateUtilsTest {
|
public class DateUtilsTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
package org.maxkey.util;
|
package org.maxkey.util;
|
||||||
|
|
||||||
import org.maxkey.util.EthernetAddress;
|
|
||||||
|
|
||||||
public class EthernetAddressTest {
|
public class EthernetAddressTest {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
package org.maxkey.util;
|
package org.maxkey.util;
|
||||||
|
|
||||||
import org.maxkey.util.MacAddress;
|
|
||||||
|
|
||||||
public class MacAddressTest {
|
public class MacAddressTest {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
package org.maxkey.util;
|
package org.maxkey.util;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import org.maxkey.util.ObjectTransformer;
|
|
||||||
|
|
||||||
public class ObjectTransformerTest {
|
public class ObjectTransformerTest {
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
package org.maxkey.util;
|
package org.maxkey.util;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.maxkey.util.PathUtils;
|
|
||||||
|
|
||||||
public class PathUtilsTest {
|
public class PathUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -20,7 +20,6 @@ package org.maxkey.util;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.maxkey.util.StringGenerator;
|
|
||||||
|
|
||||||
public class StringGeneratorTest {
|
public class StringGeneratorTest {
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -22,7 +22,6 @@ import java.util.Date;
|
|||||||
|
|
||||||
import org.maxkey.uuid.UUID;
|
import org.maxkey.uuid.UUID;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.maxkey.util.UUIDGenerator;
|
|
||||||
|
|
||||||
public class UUIDGeneratorTest {
|
public class UUIDGeneratorTest {
|
||||||
|
|
||||||
|
|||||||
@ -17,24 +17,8 @@
|
|||||||
|
|
||||||
package org.maxkey.util;
|
package org.maxkey.util;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.maxkey.pretty.PrettyFactory;
|
|
||||||
import org.maxkey.pretty.impl.XMLHelper;
|
import org.maxkey.pretty.impl.XMLHelper;
|
||||||
import org.w3c.dom.DOMConfiguration;
|
|
||||||
import org.w3c.dom.DOMImplementation;
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.ls.DOMImplementationLS;
|
|
||||||
import org.w3c.dom.ls.LSOutput;
|
|
||||||
import org.w3c.dom.ls.LSSerializer;
|
|
||||||
import org.w3c.dom.ls.LSSerializerFilter;
|
|
||||||
|
|
||||||
import net.shibboleth.utilities.java.support.collection.LazyMap;
|
|
||||||
|
|
||||||
public class XMLHelperTest {
|
public class XMLHelperTest {
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
|
import org.springframework.boot.actuate.endpoint.ApiVersion;
|
||||||
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
|
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
|
||||||
import org.springframework.boot.web.server.ErrorPage;
|
import org.springframework.boot.web.server.ErrorPage;
|
||||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||||
@ -164,6 +164,7 @@ public class MvcAutoConfiguration implements InitializingBean {
|
|||||||
mediaTypesList.add(MediaType.APPLICATION_XML);
|
mediaTypesList.add(MediaType.APPLICATION_XML);
|
||||||
mediaTypesList.add(MediaType.TEXT_XML);
|
mediaTypesList.add(MediaType.TEXT_XML);
|
||||||
mediaTypesList.add(MediaType.TEXT_PLAIN);
|
mediaTypesList.add(MediaType.TEXT_PLAIN);
|
||||||
|
_logger.debug("marshallingHttpMessageConverter MediaTypes " + mediaTypesList);
|
||||||
marshallingHttpMessageConverter.setSupportedMediaTypes(mediaTypesList);
|
marshallingHttpMessageConverter.setSupportedMediaTypes(mediaTypesList);
|
||||||
return marshallingHttpMessageConverter;
|
return marshallingHttpMessageConverter;
|
||||||
}
|
}
|
||||||
@ -178,9 +179,10 @@ public class MvcAutoConfiguration implements InitializingBean {
|
|||||||
new MappingJackson2HttpMessageConverter();
|
new MappingJackson2HttpMessageConverter();
|
||||||
ArrayList<MediaType> mediaTypesList = new ArrayList<MediaType>();
|
ArrayList<MediaType> mediaTypesList = new ArrayList<MediaType>();
|
||||||
mediaTypesList.add(MediaType.APPLICATION_JSON);
|
mediaTypesList.add(MediaType.APPLICATION_JSON);
|
||||||
mediaTypesList.add(MediaType.valueOf(ActuatorMediaType.V2_JSON));
|
mediaTypesList.add(MediaType.valueOf(ApiVersion.V2.getProducedMimeType().toString()));
|
||||||
mediaTypesList.add(MediaType.valueOf(ActuatorMediaType.V3_JSON));
|
mediaTypesList.add(MediaType.valueOf(ApiVersion.V3.getProducedMimeType().toString()));
|
||||||
//mediaTypesList.add(MediaType.TEXT_PLAIN);
|
//mediaTypesList.add(MediaType.TEXT_PLAIN);
|
||||||
|
_logger.debug("mappingJacksonHttpMessageConverter MediaTypes " + mediaTypesList);
|
||||||
mappingJacksonHttpMessageConverter.setSupportedMediaTypes(mediaTypesList);
|
mappingJacksonHttpMessageConverter.setSupportedMediaTypes(mediaTypesList);
|
||||||
return mappingJacksonHttpMessageConverter;
|
return mappingJacksonHttpMessageConverter;
|
||||||
}
|
}
|
||||||
@ -191,8 +193,8 @@ public class MvcAutoConfiguration implements InitializingBean {
|
|||||||
*/
|
*/
|
||||||
@Bean (name = "stringHttpMessageConverter")
|
@Bean (name = "stringHttpMessageConverter")
|
||||||
public HttpMessageConverter<String> responseBodyConverter() {
|
public HttpMessageConverter<String> responseBodyConverter() {
|
||||||
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(
|
StringHttpMessageConverter stringHttpMessageConverter =
|
||||||
Charset.forName("UTF-8"));
|
new StringHttpMessageConverter(Charset.forName("UTF-8"));
|
||||||
return stringHttpMessageConverter;
|
return stringHttpMessageConverter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -52,6 +52,7 @@ public class SwaggerConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 配置swagger信息
|
// 配置swagger信息
|
||||||
|
@SuppressWarnings(value = { })
|
||||||
private ApiInfo apiInfo() {
|
private ApiInfo apiInfo() {
|
||||||
Contact contact = new Contact(
|
Contact contact = new Contact(
|
||||||
"MaxKey.top",
|
"MaxKey.top",
|
||||||
@ -66,6 +67,6 @@ public class SwaggerConfig {
|
|||||||
contact,
|
contact,
|
||||||
"Apache License, Version 2.0",
|
"Apache License, Version 2.0",
|
||||||
"http://www.apache.org/licenses/LICENSE-2.0",
|
"http://www.apache.org/licenses/LICENSE-2.0",
|
||||||
new ArrayList());
|
new ArrayList<>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
package org.maxkey.configuration;
|
package org.maxkey.configuration;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@ -37,7 +35,6 @@ import org.springframework.stereotype.Component;
|
|||||||
@Component
|
@Component
|
||||||
@Configuration
|
@Configuration
|
||||||
public class ApplicationConfig {
|
public class ApplicationConfig {
|
||||||
private static final Logger _logger = LoggerFactory.getLogger(ApplicationConfig.class);
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
EmailConfig emailConfig;
|
EmailConfig emailConfig;
|
||||||
|
|||||||
@ -19,7 +19,6 @@ package org.maxkey.entity.xml;
|
|||||||
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
import org.apache.mybatis.jpa.persistence.JpaBaseEntity;
|
|
||||||
import org.apache.mybatis.jpa.persistence.JpaBaseEntity;
|
import org.apache.mybatis.jpa.persistence.JpaBaseEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -67,7 +67,7 @@ public class RedisConnection {
|
|||||||
* @param seconds
|
* @param seconds
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
public void setex(String key,int seconds, String value){
|
public void setex(String key,long seconds, String value){
|
||||||
if(seconds==0){
|
if(seconds==0){
|
||||||
conn.setex(key, RedisConnectionFactory.DEFAULT_CONFIG.DEFAULT_LIFETIME, value);
|
conn.setex(key, RedisConnectionFactory.DEFAULT_CONFIG.DEFAULT_LIFETIME, value);
|
||||||
}else{
|
}else{
|
||||||
@ -103,7 +103,7 @@ public class RedisConnection {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void expire(String key,int seconds){
|
public void expire(String key,long seconds){
|
||||||
conn.expire(key, seconds);
|
conn.expire(key, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -61,7 +61,7 @@ public class RedisConnectionFactory {
|
|||||||
/**
|
/**
|
||||||
* 默认过期时间
|
* 默认过期时间
|
||||||
*/
|
*/
|
||||||
public static int DEFAULT_LIFETIME = 600;
|
public static long DEFAULT_LIFETIME = 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
JedisPoolConfig poolConfig;
|
JedisPoolConfig poolConfig;
|
||||||
|
|||||||
@ -45,6 +45,7 @@ public class BasePathTagDirective implements TemplateDirectiveModel {
|
|||||||
private HttpServletRequest request;
|
private HttpServletRequest request;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||||
throws TemplateException, IOException {
|
throws TemplateException, IOException {
|
||||||
|
|
||||||
|
|||||||
@ -42,6 +42,7 @@ public class BaseTagDirective implements TemplateDirectiveModel {
|
|||||||
private HttpServletRequest request;
|
private HttpServletRequest request;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||||
throws TemplateException, IOException {
|
throws TemplateException, IOException {
|
||||||
//String url = params.get(URL).toString();
|
//String url = params.get(URL).toString();
|
||||||
|
|||||||
@ -42,6 +42,7 @@ public class BrowserTagDirective implements TemplateDirectiveModel {
|
|||||||
private HttpServletRequest request;
|
private HttpServletRequest request;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||||
throws TemplateException, IOException {
|
throws TemplateException, IOException {
|
||||||
String browser = params.get("name").toString();
|
String browser = params.get("name").toString();
|
||||||
|
|||||||
@ -42,6 +42,7 @@ public class CurrUrlTagDirective implements TemplateDirectiveModel {
|
|||||||
private HttpServletRequest request;
|
private HttpServletRequest request;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||||
throws TemplateException, IOException {
|
throws TemplateException, IOException {
|
||||||
//String url = params.get(URL).toString();
|
//String url = params.get(URL).toString();
|
||||||
|
|||||||
@ -20,10 +20,7 @@ package org.maxkey.web.tag;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import org.maxkey.util.DateUtils;
|
import org.maxkey.util.DateUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import freemarker.core.Environment;
|
import freemarker.core.Environment;
|
||||||
import freemarker.template.TemplateDirectiveBody;
|
import freemarker.template.TemplateDirectiveBody;
|
||||||
@ -39,10 +36,9 @@ import freemarker.template.TemplateModel;
|
|||||||
|
|
||||||
@FreemarkerTag("date")
|
@FreemarkerTag("date")
|
||||||
public class DateTagDirective implements TemplateDirectiveModel {
|
public class DateTagDirective implements TemplateDirectiveModel {
|
||||||
@Autowired
|
|
||||||
private HttpServletRequest request;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||||
throws TemplateException, IOException {
|
throws TemplateException, IOException {
|
||||||
String dateValue = params.get("value").toString();
|
String dateValue = params.get("value").toString();
|
||||||
|
|||||||
@ -22,7 +22,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.maxkey.util.DateUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import freemarker.core.Environment;
|
import freemarker.core.Environment;
|
||||||
@ -53,6 +52,7 @@ public class DialogTagDirective implements TemplateDirectiveModel {
|
|||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||||
throws TemplateException, IOException {
|
throws TemplateException, IOException {
|
||||||
|
|
||||||
|
|||||||
@ -37,6 +37,7 @@ import freemarker.template.TemplateModel;
|
|||||||
public class GenIdTagDirective implements TemplateDirectiveModel {
|
public class GenIdTagDirective implements TemplateDirectiveModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||||
throws TemplateException, IOException {
|
throws TemplateException, IOException {
|
||||||
env.getOut().append(UUID.randomUUID().toString().toLowerCase());
|
env.getOut().append(UUID.randomUUID().toString().toLowerCase());
|
||||||
|
|||||||
@ -45,6 +45,7 @@ public class ParameterTagDirective implements TemplateDirectiveModel {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||||
throws TemplateException, IOException {
|
throws TemplateException, IOException {
|
||||||
name=params.get("name").toString();
|
name=params.get("name").toString();
|
||||||
|
|||||||
@ -45,6 +45,7 @@ public class PathVarTagDirective implements TemplateDirectiveModel {
|
|||||||
String pathVariable;
|
String pathVariable;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||||
throws TemplateException, IOException {
|
throws TemplateException, IOException {
|
||||||
|
|
||||||
|
|||||||
@ -18,18 +18,12 @@
|
|||||||
package org.maxkey.web.tag;
|
package org.maxkey.web.tag;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.servlet.support.RequestContextUtils;
|
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
|
||||||
import org.springframework.web.servlet.support.RequestContext;
|
|
||||||
import org.springframework.web.servlet.tags.RequestContextAwareTag;
|
|
||||||
|
|
||||||
import freemarker.core.Environment;
|
import freemarker.core.Environment;
|
||||||
import freemarker.template.TemplateDirectiveBody;
|
import freemarker.template.TemplateDirectiveBody;
|
||||||
import freemarker.template.TemplateDirectiveModel;
|
import freemarker.template.TemplateDirectiveModel;
|
||||||
@ -51,6 +45,7 @@ public class RedirectTagDirective implements TemplateDirectiveModel {
|
|||||||
private String basePath = null;
|
private String basePath = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||||
throws TemplateException, IOException {
|
throws TemplateException, IOException {
|
||||||
String location=params.get("url").toString();
|
String location=params.get("url").toString();
|
||||||
|
|||||||
@ -38,6 +38,7 @@ public class StaticTagDirective implements TemplateDirectiveModel {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||||
throws TemplateException, IOException {
|
throws TemplateException, IOException {
|
||||||
|
|
||||||
|
|||||||
@ -59,6 +59,7 @@ public class TreeTagDirective implements TemplateDirectiveModel {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||||
throws TemplateException, IOException {
|
throws TemplateException, IOException {
|
||||||
id = params.get("id").toString();
|
id = params.get("id").toString();
|
||||||
|
|||||||
@ -20,11 +20,13 @@ package org.maxkey;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.apache.commons.text.StringEscapeUtils;
|
import org.apache.commons.text.StringEscapeUtils;
|
||||||
|
import org.springframework.boot.actuate.endpoint.ApiVersion;
|
||||||
|
|
||||||
public class EscapeHtml4Test {
|
public class EscapeHtml4Test {
|
||||||
public static void main(String[] args) throws SQLException {
|
public static void main(String[] args) throws SQLException {
|
||||||
String value="<IMG SRC=javascript:alert('XSS')<javascript>>";
|
String value="<IMG SRC=javascript:alert('XSS')<javascript>>";
|
||||||
System.out.println(StringEscapeUtils.escapeHtml4(value));
|
System.out.println(StringEscapeUtils.escapeHtml4(value));
|
||||||
System.out.println(StringEscapeUtils.escapeEcmaScript(value));
|
System.out.println(StringEscapeUtils.escapeEcmaScript(value));
|
||||||
|
System.out.println(ApiVersion.V2.getProducedMimeType().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,8 +20,6 @@ package org.maxkey.persistence.ldap;
|
|||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
import javax.naming.directory.DirContext;
|
import javax.naming.directory.DirContext;
|
||||||
|
|
||||||
import org.maxkey.persistence.ldap.ActiveDirectoryUtils;
|
|
||||||
|
|
||||||
public class ActiveDirectoryUtilsTest {
|
public class ActiveDirectoryUtilsTest {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
String trustStore="D:/JavaIDE/jdk1.6.0_30/jre/lib/security/cacerts";
|
String trustStore="D:/JavaIDE/jdk1.6.0_30/jre/lib/security/cacerts";
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#端口号
|
#端口号
|
||||||
application:
|
application:
|
||||||
name: maxkey-gateway-server
|
name: maxkey-gateway-server
|
||||||
formatted-version: v2.9.0 GA
|
formatted-version: v3.0.0 GA
|
||||||
server:
|
server:
|
||||||
port: 9000
|
port: 9000
|
||||||
spring:
|
spring:
|
||||||
|
|||||||
@ -59,7 +59,7 @@ public class ScimOrganizationController {
|
|||||||
public ResponseEntity<MappingJacksonValue> create(@RequestBody Organization user,
|
public ResponseEntity<MappingJacksonValue> create(@RequestBody Organization user,
|
||||||
@RequestParam(required = false) String attributes,
|
@RequestParam(required = false) String attributes,
|
||||||
UriComponentsBuilder builder) throws IOException {
|
UriComponentsBuilder builder) throws IOException {
|
||||||
Organization createdUser = null;
|
//Organization createdUser = null;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ public class ScimOrganizationController {
|
|||||||
@RequestBody Organization user,
|
@RequestBody Organization user,
|
||||||
@RequestParam(required = false) String attributes)
|
@RequestParam(required = false) String attributes)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Organization createdUser = null;
|
//Organization createdUser = null;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ public class ScimOrganizationController {
|
|||||||
|
|
||||||
@RequestMapping(value = "/.search", method = RequestMethod.POST)
|
@RequestMapping(value = "/.search", method = RequestMethod.POST)
|
||||||
public MappingJacksonValue searchWithPost(@RequestParam Map<String, String> requestParameters) {
|
public MappingJacksonValue searchWithPost(@RequestParam Map<String, String> requestParameters) {
|
||||||
ScimSearchResult<User> scimSearchResult = null;
|
//ScimSearchResult<User> scimSearchResult = null;
|
||||||
/*
|
/*
|
||||||
requestParameters.get("filter"),
|
requestParameters.get("filter"),
|
||||||
requestParameters.get("sortBy"),
|
requestParameters.get("sortBy"),
|
||||||
@ -94,7 +94,8 @@ public class ScimOrganizationController {
|
|||||||
Integer.parseInt(requestParameters.getOrDefault("count", "" + ScimServiceProviderConfigController.MAX_RESULTS)),
|
Integer.parseInt(requestParameters.getOrDefault("count", "" + ScimServiceProviderConfigController.MAX_RESULTS)),
|
||||||
Integer.parseInt(requestParameters.getOrDefault("startIndex", "1")); // scim default
|
Integer.parseInt(requestParameters.getOrDefault("startIndex", "1")); // scim default
|
||||||
*/
|
*/
|
||||||
String attributes = (requestParameters.containsKey("attributes") ? requestParameters.get("attributes") : "");
|
//String attributes = (requestParameters.containsKey("attributes") ? requestParameters.get("attributes") : "");
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,7 @@ public class ScimUserController {
|
|||||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||||
public MappingJacksonValue getUser(@PathVariable String id,
|
public MappingJacksonValue getUser(@PathVariable String id,
|
||||||
@RequestParam(required = false) String attributes) {
|
@RequestParam(required = false) String attributes) {
|
||||||
User user = null;
|
//User user = null;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ public class ScimUserController {
|
|||||||
public ResponseEntity<MappingJacksonValue> create(@RequestBody User user,
|
public ResponseEntity<MappingJacksonValue> create(@RequestBody User user,
|
||||||
@RequestParam(required = false) String attributes,
|
@RequestParam(required = false) String attributes,
|
||||||
UriComponentsBuilder builder) throws IOException {
|
UriComponentsBuilder builder) throws IOException {
|
||||||
User createdUser = null;
|
//User createdUser = null;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ public class ScimUserController {
|
|||||||
@RequestBody User user,
|
@RequestBody User user,
|
||||||
@RequestParam(required = false) String attributes)
|
@RequestParam(required = false) String attributes)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
User createdUser = null;
|
//User createdUser = null;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ public class ScimUserController {
|
|||||||
|
|
||||||
@RequestMapping(value = "/.search", method = RequestMethod.POST)
|
@RequestMapping(value = "/.search", method = RequestMethod.POST)
|
||||||
public MappingJacksonValue searchWithPost(@RequestParam Map<String, String> requestParameters) {
|
public MappingJacksonValue searchWithPost(@RequestParam Map<String, String> requestParameters) {
|
||||||
ScimSearchResult<User> scimSearchResult = null;
|
//ScimSearchResult<User> scimSearchResult = null;
|
||||||
/*
|
/*
|
||||||
requestParameters.get("filter"),
|
requestParameters.get("filter"),
|
||||||
requestParameters.get("sortBy"),
|
requestParameters.get("sortBy"),
|
||||||
@ -93,7 +93,7 @@ public class ScimUserController {
|
|||||||
Integer.parseInt(requestParameters.getOrDefault("count", "" + ScimServiceProviderConfigController.MAX_RESULTS)),
|
Integer.parseInt(requestParameters.getOrDefault("count", "" + ScimServiceProviderConfigController.MAX_RESULTS)),
|
||||||
Integer.parseInt(requestParameters.getOrDefault("startIndex", "1")); // scim default
|
Integer.parseInt(requestParameters.getOrDefault("startIndex", "1")); // scim default
|
||||||
*/
|
*/
|
||||||
String attributes = (requestParameters.containsKey("attributes") ? requestParameters.get("attributes") : "");
|
//String attributes = (requestParameters.containsKey("attributes") ? requestParameters.get("attributes") : "");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,10 +17,6 @@
|
|||||||
|
|
||||||
package org.maxkey.identity.scim.resources;
|
package org.maxkey.identity.scim.resources;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.maxkey.pretty.impl.JsonPretty;
|
import org.maxkey.pretty.impl.JsonPretty;
|
||||||
import org.maxkey.util.JsonUtils;
|
import org.maxkey.util.JsonUtils;
|
||||||
|
|
||||||
|
|||||||
@ -94,12 +94,8 @@ public class FormBasedDetailsServiceTest {
|
|||||||
|
|
||||||
_logger.info("queryPageResults...");
|
_logger.info("queryPageResults...");
|
||||||
AppsFormBasedDetails formBasedDetails=new AppsFormBasedDetails();
|
AppsFormBasedDetails formBasedDetails=new AppsFormBasedDetails();
|
||||||
//student.setId("af04d610-6092-481e-9558-30bd63ef783c");
|
formBasedDetails.setPageNumber(2);
|
||||||
// student.setStdGender("M");
|
_logger.info("queryPageResults "+service.queryPageResults(formBasedDetails));
|
||||||
//student.setStdMajor(政治");
|
|
||||||
//student.setPageResults(10);
|
|
||||||
//student.setPage(2);
|
|
||||||
//_logger.info("queryPageResults "+service.queryPageResults(formBasedDetails));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -107,12 +103,10 @@ public class FormBasedDetailsServiceTest {
|
|||||||
|
|
||||||
_logger.info("queryPageResults by mapperId...");
|
_logger.info("queryPageResults by mapperId...");
|
||||||
AppsFormBasedDetails formBasedDetails=new AppsFormBasedDetails();
|
AppsFormBasedDetails formBasedDetails=new AppsFormBasedDetails();
|
||||||
// student.setStdGender("M");
|
|
||||||
//student.setStdMajor(政治");
|
|
||||||
// student.setPageResults(10);
|
|
||||||
// student.setPage(2);
|
|
||||||
|
|
||||||
//_logger.info("queryPageResults by mapperId "+service.queryPageResults("queryPageResults1",formBasedDetails));
|
formBasedDetails.setPageNumber(2);
|
||||||
|
|
||||||
|
_logger.info("queryPageResults by mapperId "+service.queryPageResults("queryPageResults1",formBasedDetails));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,8 +25,6 @@ package org.maxkey.authz.cas.endpoint.ticket;
|
|||||||
* @since 4.2.0
|
* @since 4.2.0
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractTicketException{
|
public abstract class AbstractTicketException{
|
||||||
private static final long serialVersionUID = -5128676415951733624L;
|
|
||||||
|
|
||||||
String code;
|
String code;
|
||||||
String msg;
|
String msg;
|
||||||
Throwable throwable;
|
Throwable throwable;
|
||||||
|
|||||||
@ -33,8 +33,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractWebApplicationService {
|
public abstract class AbstractWebApplicationService {
|
||||||
|
|
||||||
private static final long serialVersionUID = 610105280927740076L;
|
|
||||||
|
|
||||||
/** Logger instance. **/
|
/** Logger instance. **/
|
||||||
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractWebApplicationService.class);
|
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractWebApplicationService.class);
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,7 @@ package org.maxkey.authz.cas.endpoint.ticket;
|
|||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public interface Service {
|
public interface Service {
|
||||||
boolean getId();
|
String getId();
|
||||||
|
|
||||||
boolean matches(Service service);
|
boolean matches(Service service);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,8 +26,6 @@ package org.maxkey.authz.cas.endpoint.ticket;
|
|||||||
*/
|
*/
|
||||||
public final class SimpleWebApplicationServiceImpl extends AbstractWebApplicationService {
|
public final class SimpleWebApplicationServiceImpl extends AbstractWebApplicationService {
|
||||||
|
|
||||||
private static final long serialVersionUID = 8334068957483758042L;
|
|
||||||
|
|
||||||
public SimpleWebApplicationServiceImpl(final String id) {
|
public SimpleWebApplicationServiceImpl(final String id) {
|
||||||
this(id, id, null);
|
this(id, id, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,9 +17,6 @@
|
|||||||
|
|
||||||
package org.maxkey.authz.cas.endpoint.ticket.generator;
|
package org.maxkey.authz.cas.endpoint.ticket.generator;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,7 +26,6 @@ import java.net.InetAddress;
|
|||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
*/
|
*/
|
||||||
public final class InetAddressUtils {
|
public final class InetAddressUtils {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(InetAddressUtils.class);
|
|
||||||
|
|
||||||
private InetAddressUtils() {
|
private InetAddressUtils() {
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,6 @@ public class RestTestClient {
|
|||||||
String password ="maxkey";
|
String password ="maxkey";
|
||||||
String serviceUrl = "http://cas.demo.maxkey.top:9521/demo-cas/";
|
String serviceUrl = "http://cas.demo.maxkey.top:9521/demo-cas/";
|
||||||
CasConfiguration casConfiguration = new CasConfiguration(casUrlPrefix);
|
CasConfiguration casConfiguration = new CasConfiguration(casUrlPrefix);
|
||||||
final CasRestAuthenticator authenticator = new CasRestAuthenticator(casConfiguration);
|
|
||||||
final CasRestFormClient client = new CasRestFormClient(casConfiguration,"username","password");
|
final CasRestFormClient client = new CasRestFormClient(casConfiguration,"username","password");
|
||||||
final MockHttpServletRequest request = new MockHttpServletRequest();
|
final MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
final MockHttpServletResponse response = new MockHttpServletResponse();
|
final MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
@ -61,7 +60,7 @@ public class RestTestClient {
|
|||||||
|
|
||||||
Map<String,Object> attributes = casProfile.getAttributes();
|
Map<String,Object> attributes = casProfile.getAttributes();
|
||||||
Set<Map.Entry<String,Object>> mapEntries = attributes.entrySet();
|
Set<Map.Entry<String,Object>> mapEntries = attributes.entrySet();
|
||||||
for (Map.Entry entry : mapEntries) {
|
for (Map.Entry<String,Object> entry : mapEntries) {
|
||||||
System.out.println(entry.getKey() + ":" + entry.getValue());
|
System.out.println(entry.getKey() + ":" + entry.getValue());
|
||||||
}
|
}
|
||||||
client.destroyTicketGrantingTicket(profile,webContext);
|
client.destroyTicketGrantingTicket(profile,webContext);
|
||||||
|
|||||||
@ -64,7 +64,8 @@ public class ExtendApiCndnsApiMailAdapter extends AbstractAuthorizeAdapter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
|
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
|
||||||
HttpsTrusts.beforeConnection();
|
HttpsTrusts.beforeConnection();
|
||||||
|
|
||||||
|
|||||||
@ -53,18 +53,21 @@ public class ExtendApiQQExmailAdapter extends AbstractAuthorizeAdapter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
|
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
|
||||||
HttpsTrusts.beforeConnection();
|
HttpsTrusts.beforeConnection();
|
||||||
|
|
||||||
Apps details=(Apps)app;
|
Apps details=(Apps)app;
|
||||||
String username = data.substring(0, data.indexOf("="));
|
String username = data.substring(0, data.indexOf("="));
|
||||||
String password = data.substring(data.indexOf("=") + 1);
|
String password = data.substring(data.indexOf("=") + 1);
|
||||||
|
_logger.trace("username " + username +" password " + password);
|
||||||
//extraAttrs from Applications
|
//extraAttrs from Applications
|
||||||
ExtraAttrs extraAttrs=null;
|
ExtraAttrs extraAttrs=null;
|
||||||
if(details.getIsExtendAttr()==1){
|
if(details.getIsExtendAttr()==1){
|
||||||
extraAttrs=new ExtraAttrs(details.getExtendAttr());
|
extraAttrs=new ExtraAttrs(details.getExtendAttr());
|
||||||
}
|
}
|
||||||
|
_logger.debug("Extra Attrs "+extraAttrs);
|
||||||
OAuthClient tokenRestClient=new OAuthClient(
|
OAuthClient tokenRestClient=new OAuthClient(
|
||||||
String.format(TOKEN_URI,details.getPrincipal(),details.getCredentials()));
|
String.format(TOKEN_URI,details.getPrincipal(),details.getCredentials()));
|
||||||
Token token =tokenRestClient.requestAccessToken();
|
Token token =tokenRestClient.requestAccessToken();
|
||||||
|
|||||||
@ -62,6 +62,7 @@ public class ExtendApiZentaoAdapter extends AbstractAuthorizeAdapter {
|
|||||||
if(details.getIsExtendAttr()==1){
|
if(details.getIsExtendAttr()==1){
|
||||||
extraAttrs=new ExtraAttrs(details.getExtendAttr());
|
extraAttrs=new ExtraAttrs(details.getExtendAttr());
|
||||||
}
|
}
|
||||||
|
_logger.trace("Extra Attrs " + extraAttrs);
|
||||||
String code = details.getPrincipal();
|
String code = details.getPrincipal();
|
||||||
String key = details.getCredentials();
|
String key = details.getCredentials();
|
||||||
String time = ""+Instant.now().getEpochSecond();
|
String time = ""+Instant.now().getEpochSecond();
|
||||||
|
|||||||
@ -26,6 +26,11 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
|||||||
*/
|
*/
|
||||||
public class OAuth2ExceptionJackson2Serializer extends StdSerializer<OAuth2Exception> {
|
public class OAuth2ExceptionJackson2Serializer extends StdSerializer<OAuth2Exception> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -767680428859994107L;
|
||||||
|
|
||||||
public OAuth2ExceptionJackson2Serializer() {
|
public OAuth2ExceptionJackson2Serializer() {
|
||||||
super(OAuth2Exception.class);
|
super(OAuth2Exception.class);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -113,7 +113,7 @@ class JwtHeaderHelper {
|
|||||||
static HeaderParameters parseParams(byte[] header) {
|
static HeaderParameters parseParams(byte[] header) {
|
||||||
JsonParser jp = null;
|
JsonParser jp = null;
|
||||||
try {
|
try {
|
||||||
jp = f.createJsonParser(header);
|
jp = f.createParser(header);
|
||||||
String alg = null, enc = null, iv = null;
|
String alg = null, enc = null, iv = null;
|
||||||
jp.nextToken();
|
jp.nextToken();
|
||||||
while (jp.nextToken() != JsonToken.END_OBJECT) {
|
while (jp.nextToken() != JsonToken.END_OBJECT) {
|
||||||
@ -163,7 +163,7 @@ class JwtHeaderHelper {
|
|||||||
JsonGenerator g = null;
|
JsonGenerator g = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
g = f.createJsonGenerator(baos);
|
g = f.createGenerator(baos);
|
||||||
g.writeStartObject();
|
g.writeStartObject();
|
||||||
g.writeStringField("alg", params.alg);
|
g.writeStringField("alg", params.alg);
|
||||||
if (params.enc != null) {
|
if (params.enc != null) {
|
||||||
|
|||||||
@ -649,6 +649,11 @@ final class Base64Codec {
|
|||||||
|
|
||||||
class InvalidBase64CharacterException extends IllegalArgumentException {
|
class InvalidBase64CharacterException extends IllegalArgumentException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -616861303718228577L;
|
||||||
|
|
||||||
InvalidBase64CharacterException(String message) {
|
InvalidBase64CharacterException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,11 @@ package org.maxkey.authz.oauth2.jwt.crypto.sign;
|
|||||||
* @author Luke Taylor
|
* @author Luke Taylor
|
||||||
*/
|
*/
|
||||||
public class InvalidSignatureException extends RuntimeException {
|
public class InvalidSignatureException extends RuntimeException {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 7078872206905207270L;
|
||||||
|
|
||||||
public InvalidSignatureException(String message) {
|
public InvalidSignatureException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,10 +20,8 @@ import org.maxkey.authn.online.OnlineTicket;
|
|||||||
import org.maxkey.entity.UserInfo;
|
import org.maxkey.entity.UserInfo;
|
||||||
import org.maxkey.persistence.db.LoginService;
|
import org.maxkey.persistence.db.LoginService;
|
||||||
import org.maxkey.web.WebConstants;
|
import org.maxkey.web.WebConstants;
|
||||||
import org.maxkey.web.WebContext;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import org.maxkey.authz.oauth2.common.util.JsonDateDeserializer;
|
|||||||
import org.maxkey.authz.oauth2.common.util.JsonDateSerializer;
|
import org.maxkey.authz.oauth2.common.util.JsonDateSerializer;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|||||||
* @author Vidya Val
|
* @author Vidya Val
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class Approval {
|
public class Approval {
|
||||||
|
|
||||||
private String userId;
|
private String userId;
|
||||||
@ -97,7 +98,8 @@ public class Approval {
|
|||||||
this.scope = scope == null ? "" : scope;
|
this.scope = scope == null ? "" : scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonSerialize(using = JsonDateSerializer.class, include = JsonSerialize.Inclusion.NON_NULL)
|
@JsonSerialize(using = JsonDateSerializer.class)
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public Date getExpiresAt() {
|
public Date getExpiresAt() {
|
||||||
return expiresAt;
|
return expiresAt;
|
||||||
}
|
}
|
||||||
@ -112,7 +114,8 @@ public class Approval {
|
|||||||
this.expiresAt = expiresAt;
|
this.expiresAt = expiresAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonSerialize(using = JsonDateSerializer.class, include = JsonSerialize.Inclusion.NON_NULL)
|
@JsonSerialize(using = JsonDateSerializer.class)
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public Date getLastUpdatedAt() {
|
public Date getLastUpdatedAt() {
|
||||||
return lastUpdatedAt;
|
return lastUpdatedAt;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,7 +83,7 @@ public class JdbcApprovalStore implements ApprovalStore {
|
|||||||
private boolean handleRevocationsAsExpiry = false;
|
private boolean handleRevocationsAsExpiry = false;
|
||||||
|
|
||||||
public JdbcApprovalStore(DataSource dataSource) {
|
public JdbcApprovalStore(DataSource dataSource) {
|
||||||
Assert.notNull(dataSource);
|
Assert.notNull(dataSource,"DataSource must not null");
|
||||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,6 @@ package org.maxkey.authz.oauth2.provider.code;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.maxkey.authz.oauth2.common.exceptions.InvalidGrantException;
|
import org.maxkey.authz.oauth2.common.exceptions.InvalidGrantException;
|
||||||
import org.maxkey.authz.oauth2.common.util.RandomValueStringGenerator;
|
|
||||||
import org.maxkey.authz.oauth2.provider.OAuth2Authentication;
|
import org.maxkey.authz.oauth2.provider.OAuth2Authentication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +31,7 @@ import org.maxkey.authz.oauth2.provider.OAuth2Authentication;
|
|||||||
public abstract class RandomValueAuthorizationCodeServices implements AuthorizationCodeServices {
|
public abstract class RandomValueAuthorizationCodeServices implements AuthorizationCodeServices {
|
||||||
|
|
||||||
//default Random code Generator
|
//default Random code Generator
|
||||||
private RandomValueStringGenerator generator = new RandomValueStringGenerator();
|
//private RandomValueStringGenerator generator = new RandomValueStringGenerator();
|
||||||
|
|
||||||
protected abstract void store(String code, OAuth2Authentication authentication);
|
protected abstract void store(String code, OAuth2Authentication authentication);
|
||||||
|
|
||||||
|
|||||||
@ -36,14 +36,11 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.maxkey.authz.oauth2.common.OAuth2AccessToken;
|
import org.maxkey.authz.oauth2.common.OAuth2AccessToken;
|
||||||
import org.maxkey.authz.oauth2.common.OAuth2Constants;
|
import org.maxkey.authz.oauth2.common.OAuth2Constants;
|
||||||
import org.maxkey.authz.oauth2.common.exceptions.InvalidTokenException;
|
import org.maxkey.authz.oauth2.common.exceptions.InvalidTokenException;
|
||||||
import org.maxkey.authz.oauth2.common.exceptions.OAuth2Exception;
|
|
||||||
import org.maxkey.authz.oauth2.provider.OAuth2Authentication;
|
import org.maxkey.authz.oauth2.provider.OAuth2Authentication;
|
||||||
import org.maxkey.authz.oauth2.provider.token.AccessTokenConverter;
|
import org.maxkey.authz.oauth2.provider.token.AccessTokenConverter;
|
||||||
import org.maxkey.authz.oauth2.provider.token.DefaultAccessTokenConverter;
|
import org.maxkey.authz.oauth2.provider.token.DefaultAccessTokenConverter;
|
||||||
import org.maxkey.authz.oauth2.provider.token.ResourceServerTokenServices;
|
import org.maxkey.authz.oauth2.provider.token.ResourceServerTokenServices;
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|||||||
@ -31,6 +31,7 @@ package org.maxkey.authz.oauth2.provider.token;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
@ -44,7 +45,6 @@ import org.springframework.http.HttpMethod;
|
|||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.client.ClientHttpResponse;
|
import org.springframework.http.client.ClientHttpResponse;
|
||||||
import org.springframework.security.core.AuthenticationException;
|
import org.springframework.security.core.AuthenticationException;
|
||||||
import org.springframework.security.crypto.codec.Base64;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
@ -134,7 +134,7 @@ public class RemoteTokenServices implements ResourceServerTokenServices {
|
|||||||
private String getAuthorizationHeader(String clientId, String clientSecret) {
|
private String getAuthorizationHeader(String clientId, String clientSecret) {
|
||||||
String creds = String.format("%s:%s", clientId, clientSecret);
|
String creds = String.format("%s:%s", clientId, clientSecret);
|
||||||
try {
|
try {
|
||||||
return "Basic " + new String(Base64.encode(creds.getBytes("UTF-8")));
|
return "Basic " + new String(Base64.getEncoder().encodeToString(creds.getBytes("UTF-8")));
|
||||||
}
|
}
|
||||||
catch (UnsupportedEncodingException e) {
|
catch (UnsupportedEncodingException e) {
|
||||||
throw new IllegalStateException("Could not convert String");
|
throw new IllegalStateException("Could not convert String");
|
||||||
|
|||||||
@ -33,6 +33,7 @@ import java.security.KeyPair;
|
|||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.interfaces.RSAPrivateKey;
|
import java.security.interfaces.RSAPrivateKey;
|
||||||
import java.security.interfaces.RSAPublicKey;
|
import java.security.interfaces.RSAPublicKey;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -62,7 +63,6 @@ import org.maxkey.authz.oauth2.provider.token.AccessTokenConverter;
|
|||||||
import org.maxkey.authz.oauth2.provider.token.DefaultAccessTokenConverter;
|
import org.maxkey.authz.oauth2.provider.token.DefaultAccessTokenConverter;
|
||||||
import org.maxkey.authz.oauth2.provider.token.TokenEnhancer;
|
import org.maxkey.authz.oauth2.provider.token.TokenEnhancer;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.security.crypto.codec.Base64;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,7 +144,7 @@ public class JwtAccessTokenConverter implements TokenEnhancer, AccessTokenConver
|
|||||||
signer = new RsaSigner((RSAPrivateKey) privateKey);
|
signer = new RsaSigner((RSAPrivateKey) privateKey);
|
||||||
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
|
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
|
||||||
verifier = new RsaVerifier(publicKey);
|
verifier = new RsaVerifier(publicKey);
|
||||||
verifierKey = "-----BEGIN PUBLIC KEY-----\n" + new String(Base64.encode(publicKey.getEncoded()))
|
verifierKey = "-----BEGIN PUBLIC KEY-----\n" + new String(Base64.getMimeEncoder().encodeToString(publicKey.getEncoded()))
|
||||||
+ "\n-----END PUBLIC KEY-----";
|
+ "\n-----END PUBLIC KEY-----";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ public class JwtAccessTokenConverter implements TokenEnhancer, AccessTokenConver
|
|||||||
* @param key the key to be used for signing JWTs.
|
* @param key the key to be used for signing JWTs.
|
||||||
*/
|
*/
|
||||||
public void setSigningKey(String key) {
|
public void setSigningKey(String key) {
|
||||||
Assert.hasText(key);
|
Assert.hasText(key,"key must not be empty");
|
||||||
key = key.trim();
|
key = key.trim();
|
||||||
|
|
||||||
this.signingKey = key;
|
this.signingKey = key;
|
||||||
|
|||||||
@ -43,20 +43,22 @@ import java.util.Date;
|
|||||||
public class RedisTokenStore implements TokenStore {
|
public class RedisTokenStore implements TokenStore {
|
||||||
static final Logger _logger = LoggerFactory.getLogger(RedisTokenStore.class);
|
static final Logger _logger = LoggerFactory.getLogger(RedisTokenStore.class);
|
||||||
|
|
||||||
private static final String ACCESS = "REDIS_OAUTH_V20_ACCESS_";
|
private static final String PREFIX = "REDIS_OAUTH_V20_";
|
||||||
private static final String AUTH_TO_ACCESS = "REDIS_OAUTH_V20_AUTH_TO_ACCESS_";
|
|
||||||
private static final String AUTH = "REDIS_OAUTH_V20_AUTH_";
|
private static final String ACCESS = PREFIX + "ACCESS_";
|
||||||
private static final String REFRESH_AUTH = "REDIS_OAUTH_V20_REFRESH_AUTH_";
|
private static final String AUTH_TO_ACCESS = PREFIX + "AUTH_TO_ACCESS_";
|
||||||
private static final String ACCESS_TO_REFRESH = "REDIS_OAUTH_V20_ACCESS_TO_REFRESH_";
|
private static final String AUTH = PREFIX + "AUTH_";
|
||||||
private static final String REFRESH = "REDIS_OAUTH_V20_REFRESH_";
|
private static final String REFRESH_AUTH = PREFIX + "REFRESH_AUTH_";
|
||||||
private static final String REFRESH_TO_ACCESS = "REDIS_OAUTH_V20_REFRESH_TO_ACCESS_";
|
private static final String ACCESS_TO_REFRESH = PREFIX + "ACCESS_TO_REFRESH_";
|
||||||
private static final String CLIENT_ID_TO_ACCESS = "REDIS_OAUTH_V20_CLIENT_ID_TO_ACCESS_";
|
private static final String REFRESH = PREFIX + "REFRESH_";
|
||||||
private static final String UNAME_TO_ACCESS = "REDIS_OAUTH_V20_UNAME_TO_ACCESS_";
|
private static final String REFRESH_TO_ACCESS = PREFIX + "REFRESH_TO_ACCESS_";
|
||||||
|
private static final String CLIENT_ID_TO_ACCESS = PREFIX + "CLIENT_ID_TO_ACCESS_";
|
||||||
|
private static final String UNAME_TO_ACCESS = PREFIX + "UNAME_TO_ACCESS_";
|
||||||
|
|
||||||
private final RedisConnectionFactory connectionFactory;
|
private final RedisConnectionFactory connectionFactory;
|
||||||
private AuthenticationKeyGenerator authenticationKeyGenerator = new DefaultAuthenticationKeyGenerator();
|
private AuthenticationKeyGenerator authenticationKeyGenerator = new DefaultAuthenticationKeyGenerator();
|
||||||
|
|
||||||
private String prefix = "";
|
|
||||||
|
|
||||||
public RedisTokenStore(RedisConnectionFactory connectionFactory) {
|
public RedisTokenStore(RedisConnectionFactory connectionFactory) {
|
||||||
this.connectionFactory = connectionFactory;
|
this.connectionFactory = connectionFactory;
|
||||||
@ -66,11 +68,6 @@ public class RedisTokenStore implements TokenStore {
|
|||||||
this.authenticationKeyGenerator = authenticationKeyGenerator;
|
this.authenticationKeyGenerator = authenticationKeyGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setPrefix(String prefix) {
|
|
||||||
this.prefix = prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
private RedisConnection getConnection() {
|
private RedisConnection getConnection() {
|
||||||
return connectionFactory.getConnection();
|
return connectionFactory.getConnection();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,6 +47,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
import com.nimbusds.jose.Algorithm;
|
||||||
import com.nimbusds.jose.EncryptionMethod;
|
import com.nimbusds.jose.EncryptionMethod;
|
||||||
import com.nimbusds.jose.JWEAlgorithm;
|
import com.nimbusds.jose.JWEAlgorithm;
|
||||||
import com.nimbusds.jose.JWEHeader;
|
import com.nimbusds.jose.JWEHeader;
|
||||||
@ -164,7 +165,7 @@ public class OIDCIdTokenEnhancer implements TokenEnhancer {
|
|||||||
logger.error("Couldn't create Jwt Encryption Service");
|
logger.error("Couldn't create Jwt Encryption Service");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (signingAlg==null||signingAlg.equals("none")) {
|
if (signingAlg==null||signingAlg.equals(Algorithm.NONE)) {
|
||||||
// unsigned ID token
|
// unsigned ID token
|
||||||
idToken = new PlainJWT(builder.build());
|
idToken = new PlainJWT(builder.build());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -150,7 +150,7 @@ public class Oauth20AutoConfiguration implements InitializingBean {
|
|||||||
throws NoSuchAlgorithmException, InvalidKeySpecException, JOSEException {
|
throws NoSuchAlgorithmException, InvalidKeySpecException, JOSEException {
|
||||||
DefaultJwtEncryptionAndDecryptionService jwtEncryptionService =
|
DefaultJwtEncryptionAndDecryptionService jwtEncryptionService =
|
||||||
new DefaultJwtEncryptionAndDecryptionService(jwtSetKeyStore);
|
new DefaultJwtEncryptionAndDecryptionService(jwtSetKeyStore);
|
||||||
jwtEncryptionService.setDefaultAlgorithm(JWEAlgorithm.RSA1_5);//RSA1_5
|
jwtEncryptionService.setDefaultAlgorithm(JWEAlgorithm.RSA_OAEP_256);//RSA1_5
|
||||||
jwtEncryptionService.setDefaultDecryptionKeyId("maxkey_rsa");
|
jwtEncryptionService.setDefaultDecryptionKeyId("maxkey_rsa");
|
||||||
jwtEncryptionService.setDefaultEncryptionKeyId("maxkey_rsa");
|
jwtEncryptionService.setDefaultEncryptionKeyId("maxkey_rsa");
|
||||||
return jwtEncryptionService;
|
return jwtEncryptionService;
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
Manifest-Version: 1.0
|
|
||||||
Class-Path:
|
|
||||||
|
|
||||||
@ -35,6 +35,7 @@ import org.maxkey.authz.saml.common.EndpointGenerator;
|
|||||||
import org.maxkey.authz.saml.common.TrustResolver;
|
import org.maxkey.authz.saml.common.TrustResolver;
|
||||||
import org.maxkey.authz.saml.service.IDService;
|
import org.maxkey.authz.saml.service.IDService;
|
||||||
import org.maxkey.authz.saml.service.TimeService;
|
import org.maxkey.authz.saml.service.TimeService;
|
||||||
|
import org.maxkey.authz.saml20.binding.BindingAdapter;
|
||||||
import org.maxkey.authz.saml20.binding.ExtractBindingAdapter;
|
import org.maxkey.authz.saml20.binding.ExtractBindingAdapter;
|
||||||
import org.maxkey.authz.saml20.consumer.AuthnRequestGenerator;
|
import org.maxkey.authz.saml20.consumer.AuthnRequestGenerator;
|
||||||
import org.maxkey.authz.saml20.consumer.spring.IdentityProviderAuthenticationException;
|
import org.maxkey.authz.saml20.consumer.spring.IdentityProviderAuthenticationException;
|
||||||
@ -51,6 +52,7 @@ import org.opensaml.common.binding.security.MessageReplayRule;
|
|||||||
import org.opensaml.saml2.core.Assertion;
|
import org.opensaml.saml2.core.Assertion;
|
||||||
import org.opensaml.saml2.core.Response;
|
import org.opensaml.saml2.core.Response;
|
||||||
import org.opensaml.saml2.core.StatusCode;
|
import org.opensaml.saml2.core.StatusCode;
|
||||||
|
import org.opensaml.ws.message.decoder.MessageDecodingException;
|
||||||
import org.opensaml.xml.security.CriteriaSet;
|
import org.opensaml.xml.security.CriteriaSet;
|
||||||
import org.opensaml.xml.security.SecurityException;
|
import org.opensaml.xml.security.SecurityException;
|
||||||
import org.opensaml.xml.security.credential.Credential;
|
import org.opensaml.xml.security.credential.Credential;
|
||||||
@ -77,6 +79,8 @@ public class ConsumerEndpoint {
|
|||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(ConsumerEndpoint.class);
|
private final static Logger logger = LoggerFactory.getLogger(ConsumerEndpoint.class);
|
||||||
|
|
||||||
|
private BindingAdapter bindingAdapter;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("spKeyStoreLoader")
|
@Qualifier("spKeyStoreLoader")
|
||||||
private KeyStoreLoader keyStoreLoader;
|
private KeyStoreLoader keyStoreLoader;
|
||||||
@ -129,8 +133,8 @@ public class ConsumerEndpoint {
|
|||||||
initCredential(spId);
|
initCredential(spId);
|
||||||
|
|
||||||
SAMLMessageContext messageContext=null;
|
SAMLMessageContext messageContext=null;
|
||||||
|
/*
|
||||||
/*try {
|
try {
|
||||||
messageContext = bindingAdapter.extractSAMLMessageContext(request);
|
messageContext = bindingAdapter.extractSAMLMessageContext(request);
|
||||||
} catch (MessageDecodingException me) {
|
} catch (MessageDecodingException me) {
|
||||||
logger.error("Could not decode SAML Response", me);
|
logger.error("Could not decode SAML Response", me);
|
||||||
|
|||||||
@ -18,12 +18,6 @@
|
|||||||
package org.maxkey.authz.saml20.jit;
|
package org.maxkey.authz.saml20.jit;
|
||||||
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.maxkey.entity.UserInfo;
|
|
||||||
|
|
||||||
|
|
||||||
public interface ProvisioningAdapter {
|
public interface ProvisioningAdapter {
|
||||||
|
|
||||||
//HashMap<String,String> construct(UserInfo userInfo,Companys company,List<Roles> listRoles) ;
|
//HashMap<String,String> construct(UserInfo userInfo,Companys company,List<Roles> listRoles) ;
|
||||||
|
|||||||
@ -21,7 +21,6 @@ import org.opensaml.xml.Configuration;
|
|||||||
import org.opensaml.xml.XMLObject;
|
import org.opensaml.xml.XMLObject;
|
||||||
import org.opensaml.xml.validation.ValidationException;
|
import org.opensaml.xml.validation.ValidationException;
|
||||||
import org.opensaml.xml.validation.ValidatorSuite;
|
import org.opensaml.xml.validation.ValidatorSuite;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
|
|
||||||
public class SAML2ValidatorSuite {
|
public class SAML2ValidatorSuite {
|
||||||
|
|
||||||
|
|||||||
@ -107,6 +107,7 @@ public class Saml20AutoConfiguration implements InitializingBean {
|
|||||||
@Bean(name = "authnResponseGenerator")
|
@Bean(name = "authnResponseGenerator")
|
||||||
public AuthnResponseGenerator authnResponseGenerator(TimeService timeService,IDService idService,
|
public AuthnResponseGenerator authnResponseGenerator(TimeService timeService,IDService idService,
|
||||||
@Value("${maxkey.saml.v20.idp.issuer}") String issuerEntityName) {
|
@Value("${maxkey.saml.v20.idp.issuer}") String issuerEntityName) {
|
||||||
|
_logger.debug("issuerEntityName " + issuerEntityName);
|
||||||
AuthnResponseGenerator generator = new AuthnResponseGenerator(issuerEntityName,timeService,idService);
|
AuthnResponseGenerator generator = new AuthnResponseGenerator(issuerEntityName,timeService,idService);
|
||||||
return generator;
|
return generator;
|
||||||
}
|
}
|
||||||
@ -163,6 +164,7 @@ public class Saml20AutoConfiguration implements InitializingBean {
|
|||||||
* MapBasedStorageService.
|
* MapBasedStorageService.
|
||||||
* @return mapBasedStorageService
|
* @return mapBasedStorageService
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
@Bean(name = "mapBasedStorageService")
|
@Bean(name = "mapBasedStorageService")
|
||||||
public MapBasedStorageService mapBasedStorageService() {
|
public MapBasedStorageService mapBasedStorageService() {
|
||||||
MapBasedStorageService mapBasedStorageService = new MapBasedStorageService();
|
MapBasedStorageService mapBasedStorageService = new MapBasedStorageService();
|
||||||
@ -175,6 +177,7 @@ public class Saml20AutoConfiguration implements InitializingBean {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws VelocityException
|
* @throws VelocityException
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({ "deprecation"})
|
||||||
@Bean(name = "velocityEngine")
|
@Bean(name = "velocityEngine")
|
||||||
public VelocityEngine velocityEngine() throws VelocityException, IOException {
|
public VelocityEngine velocityEngine() throws VelocityException, IOException {
|
||||||
VelocityEngineFactoryBean factory = new VelocityEngineFactoryBean();
|
VelocityEngineFactoryBean factory = new VelocityEngineFactoryBean();
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
application.title =MaxKey
|
application.title =MaxKey
|
||||||
#for dynamic service discovery
|
#for dynamic service discovery
|
||||||
spring.application.name =maxkey-monitor
|
spring.application.name =maxkey-monitor
|
||||||
application.formatted-version =v2.9.0 GA
|
application.formatted-version =v3.0.0 GA
|
||||||
#nacos
|
#nacos
|
||||||
spring.cloud.nacos.discovery.enabled =${NACOS_DISCOVERY_ENABLED:false}
|
spring.cloud.nacos.discovery.enabled =${NACOS_DISCOVERY_ENABLED:false}
|
||||||
spring.cloud.nacos.discovery.instance-enabled =false
|
spring.cloud.nacos.discovery.instance-enabled =false
|
||||||
|
|||||||
@ -25,7 +25,6 @@ import javax.servlet.ServletException;
|
|||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.ServletResponse;
|
import javax.servlet.ServletResponse;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import org.maxkey.util.StringUtils;
|
import org.maxkey.util.StringUtils;
|
||||||
import org.maxkey.web.WebConstants;
|
import org.maxkey.web.WebConstants;
|
||||||
@ -47,7 +46,6 @@ public class SingleSignOnFilter implements Filter {
|
|||||||
ServletResponse response, FilterChain chain)throws IOException, ServletException {
|
ServletResponse response, FilterChain chain)throws IOException, ServletException {
|
||||||
|
|
||||||
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
||||||
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
|
|
||||||
HttpSession session = httpServletRequest.getSession();
|
HttpSession session = httpServletRequest.getSession();
|
||||||
// 浠巗ession涓幏鍙栧瓨鏀剧殑appid
|
// 浠巗ession涓幏鍙栧瓨鏀剧殑appid
|
||||||
String appId = (String) session.getAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID);
|
String appId = (String) session.getAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID);
|
||||||
|
|||||||
@ -21,11 +21,7 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import org.apache.mybatis.jpa.persistence.JpaPageResults;
|
import org.apache.mybatis.jpa.persistence.JpaPageResults;
|
||||||
import org.maxkey.entity.HistoryLogin;
|
import org.maxkey.entity.HistoryLogin;
|
||||||
import org.maxkey.entity.HistoryLoginApps;
|
|
||||||
import org.maxkey.entity.HistoryLogs;
|
|
||||||
import org.maxkey.persistence.service.HistoryLoginAppsService;
|
|
||||||
import org.maxkey.persistence.service.HistoryLoginService;
|
import org.maxkey.persistence.service.HistoryLoginService;
|
||||||
import org.maxkey.persistence.service.HistorySystemLogsService;
|
|
||||||
import org.maxkey.util.DateUtils;
|
import org.maxkey.util.DateUtils;
|
||||||
import org.maxkey.web.WebContext;
|
import org.maxkey.web.WebContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|||||||
@ -21,7 +21,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.maxkey.authn.SigninPrincipal;
|
import org.maxkey.authn.SigninPrincipal;
|
||||||
import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
|
|
||||||
import org.maxkey.entity.HistoryLoginApps;
|
import org.maxkey.entity.HistoryLoginApps;
|
||||||
import org.maxkey.entity.UserInfo;
|
import org.maxkey.entity.UserInfo;
|
||||||
import org.maxkey.entity.apps.Apps;
|
import org.maxkey.entity.apps.Apps;
|
||||||
|
|||||||
@ -20,7 +20,6 @@ package org.maxkey.web.interceptor;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.maxkey.entity.UserInfo;
|
|
||||||
import org.maxkey.web.WebConstants;
|
import org.maxkey.web.WebConstants;
|
||||||
import org.maxkey.web.WebContext;
|
import org.maxkey.web.WebContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -38,7 +37,6 @@ public class PreLoginAppAdapter implements AsyncHandlerInterceptor {
|
|||||||
HttpServletResponse response, Object handler)
|
HttpServletResponse response, Object handler)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
_logger.debug("preHandle");
|
_logger.debug("preHandle");
|
||||||
UserInfo userInfo = WebContext.getUserInfo();
|
|
||||||
String redirect_uri = request.getRequestURL().toString();
|
String redirect_uri = request.getRequestURL().toString();
|
||||||
String appId = getAppIdFromRequestUrl(request);
|
String appId = getAppIdFromRequestUrl(request);
|
||||||
_logger.debug("preHandle app Id " + appId);
|
_logger.debug("preHandle app Id " + appId);
|
||||||
@ -47,6 +45,7 @@ public class PreLoginAppAdapter implements AsyncHandlerInterceptor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
* UserInfo userInfo = WebContext.getUserInfo();
|
||||||
* if(userInfo.getProtectedAppsMap().get(appId)!=null){
|
* if(userInfo.getProtectedAppsMap().get(appId)!=null){
|
||||||
*
|
*
|
||||||
* request.setAttribute("redirect_uri",redirect_uri);
|
* request.setAttribute("redirect_uri",redirect_uri);
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user