配置文件优化,参数整合及日志优化
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package org.maxkey.password.onetimepwd.algorithm;
|
package org.maxkey.password.onetimepwd.algorithm;
|
||||||
|
|
||||||
public class KeyUriFormat {
|
public class OtpKeyUriFormat {
|
||||||
|
|
||||||
public class Types {
|
public class Types {
|
||||||
public static final String HOTP = "hotp";
|
public static final String HOTP = "hotp";
|
||||||
@@ -38,7 +38,7 @@ public class KeyUriFormat {
|
|||||||
|
|
||||||
String account;
|
String account;
|
||||||
|
|
||||||
public KeyUriFormat() {
|
public OtpKeyUriFormat() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ public class KeyUriFormat {
|
|||||||
* @param type
|
* @param type
|
||||||
* @param secret
|
* @param secret
|
||||||
*/
|
*/
|
||||||
public KeyUriFormat(String type, String secret) {
|
public OtpKeyUriFormat(String type, String secret) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.secret = secret;
|
this.secret = secret;
|
||||||
}
|
}
|
||||||
@@ -56,12 +56,35 @@ public class KeyUriFormat {
|
|||||||
* @param secret
|
* @param secret
|
||||||
* @param issuer
|
* @param issuer
|
||||||
*/
|
*/
|
||||||
public KeyUriFormat(String type, String secret, String issuer) {
|
public OtpKeyUriFormat(String type, String secret, String issuer) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.secret = secret;
|
this.secret = secret;
|
||||||
this.issuer = issuer;
|
this.issuer = issuer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OtpKeyUriFormat(String crypto, String type, String secret, String issuer, String domain, int digits,
|
||||||
|
Long counter, int period, String account) {
|
||||||
|
super();
|
||||||
|
this.crypto = crypto;
|
||||||
|
this.type = type;
|
||||||
|
this.secret = secret;
|
||||||
|
this.issuer = issuer;
|
||||||
|
this.domain = domain;
|
||||||
|
this.digits = digits;
|
||||||
|
this.counter = counter;
|
||||||
|
this.period = period;
|
||||||
|
this.account = account;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OtpKeyUriFormat(String type, String issuer, String domain, int digits,int period) {
|
||||||
|
super();
|
||||||
|
this.type = type;
|
||||||
|
this.issuer = issuer;
|
||||||
|
this.domain = domain;
|
||||||
|
this.digits = digits;
|
||||||
|
this.period = period;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the type
|
* @return the type
|
||||||
*/
|
*/
|
||||||
@@ -18,17 +18,17 @@
|
|||||||
package org.maxkey.password.onetimepwd.impl;
|
package org.maxkey.password.onetimepwd.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
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.env.StandardEnvironment;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
protected Properties properties;
|
protected StandardEnvironment properties;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -44,7 +44,7 @@ public class SmsOtpAuthn extends AbstractOtpAuthn {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProperties(Properties properties) {
|
public void setProperties(StandardEnvironment properties) {
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ public class TimeBasedOtpAuthn extends AbstractOtpAuthn {
|
|||||||
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TimeBasedOtpAuthn(int digits , int interval) {
|
||||||
|
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
super.digits = digits;
|
||||||
|
super.interval = interval;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean produce(UserInfo userInfo) {
|
public boolean produce(UserInfo userInfo) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -138,10 +138,10 @@ public class SmsOtpAuthnAliyun extends SmsOtpAuthn {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.accessKeyId = this.properties.getProperty("maxkey.otp.sms.aliyun.accesskeyid");
|
this.accessKeyId = properties.getProperty("maxkey.otp.sms.aliyun.accesskeyid");
|
||||||
this.accessSecret = this.properties.getProperty("maxkey.otp.sms.aliyun.accesssecret");
|
this.accessSecret = properties.getProperty("maxkey.otp.sms.aliyun.accesssecret");
|
||||||
this.templateCode = this.properties.getProperty("maxkey.otp.sms.aliyun.templatecode");
|
this.templateCode = properties.getProperty("maxkey.otp.sms.aliyun.templatecode");
|
||||||
this.signName = this.properties.getProperty("maxkey.otp.sms.aliyun.signname");
|
this.signName = properties.getProperty("maxkey.otp.sms.aliyun.signname");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ public class SmsOtpAuthnTencentCloud extends SmsOtpAuthn {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean produce(UserInfo userInfo) {
|
public boolean produce(UserInfo userInfo) {
|
||||||
// 手机号
|
// 手机号
|
||||||
@@ -181,11 +180,11 @@ public class SmsOtpAuthnTencentCloud extends SmsOtpAuthn {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.secretId = this.properties.getProperty("maxkey.otp.sms.tencentcloud.secretid");
|
this.secretId = properties.getProperty("maxkey.otp.sms.tencentcloud.secretid");
|
||||||
this.secretKey = this.properties.getProperty("maxkey.otp.sms.tencentcloud.secretkey");
|
this.secretKey = properties.getProperty("maxkey.otp.sms.tencentcloud.secretkey");
|
||||||
this.smsSdkAppid = this.properties.getProperty("maxkey.otp.sms.tencentcloud.smssdkappid");
|
this.smsSdkAppid = properties.getProperty("maxkey.otp.sms.tencentcloud.smssdkappid");
|
||||||
this.templateId = this.properties.getProperty("maxkey.otp.sms.tencentcloud.templateid");
|
this.templateId = properties.getProperty("maxkey.otp.sms.tencentcloud.templateid");
|
||||||
this.sign = this.properties.getProperty("maxkey.otp.sms.tencentcloud.sign");
|
this.sign = properties.getProperty("maxkey.otp.sms.tencentcloud.sign");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,9 +212,9 @@ public class SmsOtpAuthnYunxin extends SmsOtpAuthn {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.appKey = this.properties.getProperty("maxkey.otp.sms.yunxin.appkey");
|
this.appKey = properties.getProperty("maxkey.otp.sms.yunxin.appkey");
|
||||||
this.appSecret = this.properties.getProperty("maxkey.otp.sms.yunxin.appsecret");
|
this.appSecret = properties.getProperty("maxkey.otp.sms.yunxin.appsecret");
|
||||||
this.templateId = this.properties.getProperty("maxkey.otp.sms.yunxin.templateid");
|
this.templateId = properties.getProperty("maxkey.otp.sms.yunxin.templateid");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package org.maxkey.otp.algorithm;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import org.maxkey.password.onetimepwd.algorithm.KeyUriFormat;
|
import org.maxkey.password.onetimepwd.algorithm.OtpKeyUriFormat;
|
||||||
import org.maxkey.util.QRCode;
|
import org.maxkey.util.QRCode;
|
||||||
|
|
||||||
import com.google.zxing.BarcodeFormat;
|
import com.google.zxing.BarcodeFormat;
|
||||||
@@ -29,7 +29,7 @@ import com.google.zxing.common.BitMatrix;
|
|||||||
public class KeyUriFormatTest {
|
public class KeyUriFormatTest {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
KeyUriFormat kuf=new KeyUriFormat(KeyUriFormat.Types.TOTP,
|
OtpKeyUriFormat kuf=new OtpKeyUriFormat(OtpKeyUriFormat.Types.TOTP,
|
||||||
"GIWVWOL7EI5WLVZPDMROEPSTFBEVO77Q",
|
"GIWVWOL7EI5WLVZPDMROEPSTFBEVO77Q",
|
||||||
"connsec.com");
|
"connsec.com");
|
||||||
kuf.setPeriod(60);
|
kuf.setPeriod(60);
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
|
||||||
import org.springframework.core.env.StandardEnvironment;
|
import org.springframework.core.env.StandardEnvironment;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
@@ -44,26 +43,21 @@ public class SocialSignOnAutoConfiguration implements InitializingBean {
|
|||||||
@Bean(name = "socialSignOnProviderService")
|
@Bean(name = "socialSignOnProviderService")
|
||||||
@ConditionalOnClass(SocialSignOnProvider.class)
|
@ConditionalOnClass(SocialSignOnProvider.class)
|
||||||
public SocialSignOnProviderService socialSignOnProviderService(
|
public SocialSignOnProviderService socialSignOnProviderService(
|
||||||
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer) throws IOException {
|
StandardEnvironment environment) throws IOException {
|
||||||
SocialSignOnProviderService socialSignOnProviderService = new SocialSignOnProviderService();
|
SocialSignOnProviderService socialSignOnProviderService = new SocialSignOnProviderService();
|
||||||
|
|
||||||
StandardEnvironment properties = (StandardEnvironment) propertySourcesPlaceholderConfigurer
|
|
||||||
.getAppliedPropertySources()
|
|
||||||
.get(PropertySourcesPlaceholderConfigurer.ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME)
|
|
||||||
.getSource();
|
|
||||||
|
|
||||||
List<SocialSignOnProvider> socialSignOnProviderList = new ArrayList<SocialSignOnProvider>();
|
List<SocialSignOnProvider> socialSignOnProviderList = new ArrayList<SocialSignOnProvider>();
|
||||||
|
|
||||||
String [] providerList =properties.getProperty("maxkey.login.socialsignon.providers").toString().split(",");
|
String [] providerList =environment.getProperty("maxkey.login.socialsignon.providers").toString().split(",");
|
||||||
|
|
||||||
for(String provider : providerList) {
|
for(String provider : providerList) {
|
||||||
String providerName = properties.getProperty("maxkey.socialsignon."+provider+".provider.name");
|
String providerName = environment.getProperty("maxkey.socialsignon."+provider+".provider.name");
|
||||||
String icon=properties.getProperty("maxkey.socialsignon."+provider+".icon");
|
String icon=environment.getProperty("maxkey.socialsignon."+provider+".icon");
|
||||||
String clientId=properties.getProperty("maxkey.socialsignon."+provider+".client.id");
|
String clientId=environment.getProperty("maxkey.socialsignon."+provider+".client.id");
|
||||||
String clientSecret=properties.getProperty("maxkey.socialsignon."+provider+".client.secret");
|
String clientSecret=environment.getProperty("maxkey.socialsignon."+provider+".client.secret");
|
||||||
String sortOrder = properties.getProperty("maxkey.socialsignon."+provider+".sortorder");
|
String sortOrder = environment.getProperty("maxkey.socialsignon."+provider+".sortorder");
|
||||||
String agentId = properties.getProperty("maxkey.socialsignon."+provider+".agent.id");
|
String agentId = environment.getProperty("maxkey.socialsignon."+provider+".agent.id");
|
||||||
String hidden = properties.getProperty("maxkey.socialsignon."+provider+".hidden");
|
String hidden = environment.getProperty("maxkey.socialsignon."+provider+".hidden");
|
||||||
|
|
||||||
SocialSignOnProvider socialSignOnProvider = new SocialSignOnProvider();
|
SocialSignOnProvider socialSignOnProvider = new SocialSignOnProvider();
|
||||||
socialSignOnProvider.setProvider(provider);
|
socialSignOnProvider.setProvider(provider);
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.maxkey.authn.realm.jdbc.JdbcAuthenticationRealm;
|
import org.maxkey.authn.realm.jdbc.JdbcAuthenticationRealm;
|
||||||
@@ -38,7 +37,7 @@ import org.maxkey.authn.support.rememberme.AbstractRemeberMeService;
|
|||||||
import org.maxkey.configuration.EmailConfig;
|
import org.maxkey.configuration.EmailConfig;
|
||||||
import org.maxkey.constants.ConstantsPersistence;
|
import org.maxkey.constants.ConstantsPersistence;
|
||||||
import org.maxkey.password.onetimepwd.AbstractOtpAuthn;
|
import org.maxkey.password.onetimepwd.AbstractOtpAuthn;
|
||||||
import org.maxkey.password.onetimepwd.algorithm.KeyUriFormat;
|
import org.maxkey.password.onetimepwd.algorithm.OtpKeyUriFormat;
|
||||||
import org.maxkey.password.onetimepwd.impl.MailOtpAuthn;
|
import org.maxkey.password.onetimepwd.impl.MailOtpAuthn;
|
||||||
import org.maxkey.password.onetimepwd.impl.SmsOtpAuthn;
|
import org.maxkey.password.onetimepwd.impl.SmsOtpAuthn;
|
||||||
import org.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
|
import org.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
|
||||||
@@ -60,6 +59,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.env.StandardEnvironment;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
@@ -87,27 +87,22 @@ public class MaxKeyConfig implements InitializingBean {
|
|||||||
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyConfig.class);
|
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyConfig.class);
|
||||||
|
|
||||||
|
|
||||||
@Bean(name = "keyUriFormat")
|
@Bean(name = "otpKeyUriFormat")
|
||||||
public KeyUriFormat keyUriFormat(
|
public OtpKeyUriFormat otpKeyUriFormat(
|
||||||
@Value("${maxkey.otp.keyuri.format.type:totp}")
|
@Value("${maxkey.otp.policy.type:totp}")
|
||||||
String keyuriFormatType,
|
String type,
|
||||||
@Value("${maxkey.otp.keyuri.format.domain:MaxKey.top}")
|
@Value("${maxkey.otp.policy.domain:MaxKey.top}")
|
||||||
String keyuriFormatDomain,
|
String domain,
|
||||||
@Value("${maxkey.otp.keyuri.format.issuer:MaxKey}")
|
@Value("${maxkey.otp.policy.issuer:MaxKey}")
|
||||||
String keyuriFormatIssuer,
|
String issuer,
|
||||||
@Value("${maxkey.otp.keyuri.format.digits:6}")
|
@Value("${maxkey.otp.policy.digits:6}")
|
||||||
int keyuriFormatDigits,
|
int digits,
|
||||||
@Value("${maxkey.otp.keyuri.format.period:30}")
|
@Value("${maxkey.otp.policy.period:30}")
|
||||||
int keyuriFormatPeriod) {
|
int period) {
|
||||||
|
|
||||||
KeyUriFormat keyUriFormat=new KeyUriFormat();
|
OtpKeyUriFormat otpKeyUriFormat=new OtpKeyUriFormat(type,issuer,domain,digits,period);
|
||||||
keyUriFormat.setType(keyuriFormatType);
|
_logger.debug("OTP KeyUri Format " + otpKeyUriFormat);
|
||||||
keyUriFormat.setDomain(keyuriFormatDomain);
|
return otpKeyUriFormat;
|
||||||
keyUriFormat.setIssuer(keyuriFormatIssuer);
|
|
||||||
keyUriFormat.setDigits(keyuriFormatDigits);
|
|
||||||
keyUriFormat.setPeriod(keyuriFormatPeriod);
|
|
||||||
_logger.debug("KeyUri Format " + keyUriFormat);
|
|
||||||
return keyUriFormat;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractAuthenticationRealm ldapAuthenticationRealm(
|
public AbstractAuthenticationRealm ldapAuthenticationRealm(
|
||||||
@@ -194,8 +189,12 @@ public class MaxKeyConfig implements InitializingBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean(name = "timeBasedOtpAuthn")
|
@Bean(name = "timeBasedOtpAuthn")
|
||||||
public TimeBasedOtpAuthn timeBasedOtpAuthn() {
|
public TimeBasedOtpAuthn timeBasedOtpAuthn(
|
||||||
TimeBasedOtpAuthn tfaOtpAuthn = new TimeBasedOtpAuthn();
|
@Value("${maxkey.otp.policy.digits:6}")
|
||||||
|
int digits,
|
||||||
|
@Value("${maxkey.otp.policy.period:30}")
|
||||||
|
int period) {
|
||||||
|
TimeBasedOtpAuthn tfaOtpAuthn = new TimeBasedOtpAuthn(digits , period);
|
||||||
_logger.debug("TimeBasedOtpAuthn inited.");
|
_logger.debug("TimeBasedOtpAuthn inited.");
|
||||||
return tfaOtpAuthn;
|
return tfaOtpAuthn;
|
||||||
}
|
}
|
||||||
@@ -203,9 +202,13 @@ public class MaxKeyConfig implements InitializingBean {
|
|||||||
@Bean(name = "tfaOtpAuthn")
|
@Bean(name = "tfaOtpAuthn")
|
||||||
public AbstractOtpAuthn tfaOptAuthn(
|
public AbstractOtpAuthn tfaOptAuthn(
|
||||||
@Value("${maxkey.login.mfa.type}")String mfaType,
|
@Value("${maxkey.login.mfa.type}")String mfaType,
|
||||||
|
@Value("${maxkey.otp.policy.digits:6}")
|
||||||
|
int digits,
|
||||||
|
@Value("${maxkey.otp.policy.period:30}")
|
||||||
|
int period,
|
||||||
@Value("${maxkey.server.persistence}") int persistence,
|
@Value("${maxkey.server.persistence}") int persistence,
|
||||||
RedisConnectionFactory redisConnFactory) {
|
RedisConnectionFactory redisConnFactory) {
|
||||||
AbstractOtpAuthn tfaOtpAuthn = new TimeBasedOtpAuthn();
|
AbstractOtpAuthn tfaOtpAuthn = new TimeBasedOtpAuthn(digits , period);
|
||||||
_logger.debug("TimeBasedOtpAuthn inited.");
|
_logger.debug("TimeBasedOtpAuthn inited.");
|
||||||
|
|
||||||
if (persistence == ConstantsPersistence.REDIS) {
|
if (persistence == ConstantsPersistence.REDIS) {
|
||||||
@@ -251,14 +254,14 @@ public class MaxKeyConfig implements InitializingBean {
|
|||||||
|
|
||||||
@Bean(name = "smsOtpAuthn")
|
@Bean(name = "smsOtpAuthn")
|
||||||
public SmsOtpAuthn smsOtpAuthn(
|
public SmsOtpAuthn smsOtpAuthn(
|
||||||
@Value("${maxkey.otp.sms}")String optSmsProvider,
|
@Value("${maxkey.otp.sms.provider}")String provider,
|
||||||
@Value("${maxkey.server.persistence}") int persistence,
|
@Value("${maxkey.server.persistence}") int persistence,
|
||||||
Properties applicationProperty,
|
StandardEnvironment environment,
|
||||||
RedisConnectionFactory redisConnFactory) {
|
RedisConnectionFactory redisConnFactory) {
|
||||||
SmsOtpAuthn smsOtpAuthn = null;
|
SmsOtpAuthn smsOtpAuthn = null;
|
||||||
if(optSmsProvider.equalsIgnoreCase("SmsOtpAuthnAliyun")) {
|
if(provider.equalsIgnoreCase("aliyun")) {
|
||||||
smsOtpAuthn = new SmsOtpAuthnAliyun();
|
smsOtpAuthn = new SmsOtpAuthnAliyun();
|
||||||
}else if(optSmsProvider.equalsIgnoreCase("SmsOtpAuthnTencentCloud")) {
|
}else if(provider.equalsIgnoreCase("tencentcloud")) {
|
||||||
smsOtpAuthn = new SmsOtpAuthnTencentCloud();
|
smsOtpAuthn = new SmsOtpAuthnTencentCloud();
|
||||||
}else {
|
}else {
|
||||||
smsOtpAuthn = new SmsOtpAuthnYunxin();
|
smsOtpAuthn = new SmsOtpAuthnYunxin();
|
||||||
@@ -267,10 +270,11 @@ public class MaxKeyConfig implements InitializingBean {
|
|||||||
RedisOtpTokenStore redisOptTokenStore = new RedisOtpTokenStore(redisConnFactory);
|
RedisOtpTokenStore redisOptTokenStore = new RedisOtpTokenStore(redisConnFactory);
|
||||||
smsOtpAuthn.setOptTokenStore(redisOptTokenStore);
|
smsOtpAuthn.setOptTokenStore(redisOptTokenStore);
|
||||||
}
|
}
|
||||||
smsOtpAuthn.setProperties(applicationProperty);
|
|
||||||
|
smsOtpAuthn.setProperties(environment);
|
||||||
smsOtpAuthn.initPropertys();
|
smsOtpAuthn.initPropertys();
|
||||||
|
|
||||||
_logger.debug("SmsOtpAuthn inited.");
|
_logger.debug("SmsOtpAuthn {} inited." ,smsOtpAuthn.getClass().getCanonicalName());
|
||||||
return smsOtpAuthn;
|
return smsOtpAuthn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import org.apache.commons.codec.binary.Hex;
|
|||||||
import org.maxkey.crypto.Base32Utils;
|
import org.maxkey.crypto.Base32Utils;
|
||||||
import org.maxkey.crypto.password.PasswordReciprocal;
|
import org.maxkey.crypto.password.PasswordReciprocal;
|
||||||
import org.maxkey.entity.UserInfo;
|
import org.maxkey.entity.UserInfo;
|
||||||
import org.maxkey.password.onetimepwd.algorithm.KeyUriFormat;
|
import org.maxkey.password.onetimepwd.algorithm.OtpKeyUriFormat;
|
||||||
import org.maxkey.password.onetimepwd.algorithm.OtpSecret;
|
import org.maxkey.password.onetimepwd.algorithm.OtpSecret;
|
||||||
import org.maxkey.persistence.service.UserInfoService;
|
import org.maxkey.persistence.service.UserInfoService;
|
||||||
import org.maxkey.util.RQCodeUtils;
|
import org.maxkey.util.RQCodeUtils;
|
||||||
@@ -53,8 +53,8 @@ public class OneTimePasswordController {
|
|||||||
private UserInfoService userInfoService;
|
private UserInfoService userInfoService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("keyUriFormat")
|
@Qualifier("otpKeyUriFormat")
|
||||||
KeyUriFormat keyUriFormat;
|
OtpKeyUriFormat otpKeyUriFormat;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("passwordReciprocal")
|
@Qualifier("passwordReciprocal")
|
||||||
@@ -65,13 +65,13 @@ public class OneTimePasswordController {
|
|||||||
ModelAndView modelAndView = new ModelAndView("safe/timeBased");
|
ModelAndView modelAndView = new ModelAndView("safe/timeBased");
|
||||||
UserInfo userInfo = WebContext.getUserInfo();
|
UserInfo userInfo = WebContext.getUserInfo();
|
||||||
String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
|
String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
|
||||||
keyUriFormat.setSecret(sharedSecret);
|
otpKeyUriFormat.setSecret(sharedSecret);
|
||||||
String otpauth = keyUriFormat.format(userInfo.getUsername());
|
String otpauth = otpKeyUriFormat.format(userInfo.getUsername());
|
||||||
byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
|
byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
|
||||||
String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
|
String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
|
||||||
modelAndView.addObject("id", genRqCode(otpauth));
|
modelAndView.addObject("id", genRqCode(otpauth));
|
||||||
modelAndView.addObject("userInfo", userInfo);
|
modelAndView.addObject("userInfo", userInfo);
|
||||||
modelAndView.addObject("format", keyUriFormat);
|
modelAndView.addObject("format", otpKeyUriFormat);
|
||||||
modelAndView.addObject("sharedSecret", sharedSecret);
|
modelAndView.addObject("sharedSecret", sharedSecret);
|
||||||
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
|
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
|
||||||
return modelAndView;
|
return modelAndView;
|
||||||
@@ -80,7 +80,7 @@ public class OneTimePasswordController {
|
|||||||
@RequestMapping(value = {"gen/timebased"})
|
@RequestMapping(value = {"gen/timebased"})
|
||||||
public ModelAndView gentimebased() {
|
public ModelAndView gentimebased() {
|
||||||
UserInfo userInfo = WebContext.getUserInfo();
|
UserInfo userInfo = WebContext.getUserInfo();
|
||||||
byte[] byteSharedSecret = OtpSecret.generate(keyUriFormat.getCrypto());
|
byte[] byteSharedSecret = OtpSecret.generate(otpKeyUriFormat.getCrypto());
|
||||||
String sharedSecret = Base32Utils.encode(byteSharedSecret);
|
String sharedSecret = Base32Utils.encode(byteSharedSecret);
|
||||||
sharedSecret = passwordReciprocal.encode(sharedSecret);
|
sharedSecret = passwordReciprocal.encode(sharedSecret);
|
||||||
userInfo.setSharedSecret(sharedSecret);
|
userInfo.setSharedSecret(sharedSecret);
|
||||||
@@ -95,15 +95,15 @@ public class OneTimePasswordController {
|
|||||||
ModelAndView modelAndView = new ModelAndView("safe/counterBased");
|
ModelAndView modelAndView = new ModelAndView("safe/counterBased");
|
||||||
UserInfo userInfo = WebContext.getUserInfo();
|
UserInfo userInfo = WebContext.getUserInfo();
|
||||||
String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
|
String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
|
||||||
keyUriFormat.setSecret(sharedSecret);
|
otpKeyUriFormat.setSecret(sharedSecret);
|
||||||
keyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
|
otpKeyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
|
||||||
String otpauth = keyUriFormat.format(userInfo.getUsername());
|
String otpauth = otpKeyUriFormat.format(userInfo.getUsername());
|
||||||
|
|
||||||
byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
|
byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
|
||||||
String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
|
String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
|
||||||
modelAndView.addObject("id", genRqCode(otpauth));
|
modelAndView.addObject("id", genRqCode(otpauth));
|
||||||
modelAndView.addObject("userInfo", userInfo);
|
modelAndView.addObject("userInfo", userInfo);
|
||||||
modelAndView.addObject("format", keyUriFormat);
|
modelAndView.addObject("format", otpKeyUriFormat);
|
||||||
modelAndView.addObject("sharedSecret", sharedSecret);
|
modelAndView.addObject("sharedSecret", sharedSecret);
|
||||||
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
|
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
|
||||||
return modelAndView;
|
return modelAndView;
|
||||||
@@ -113,7 +113,7 @@ public class OneTimePasswordController {
|
|||||||
@RequestMapping(value = {"gen/counterbased"})
|
@RequestMapping(value = {"gen/counterbased"})
|
||||||
public ModelAndView gencounterbased() {
|
public ModelAndView gencounterbased() {
|
||||||
UserInfo userInfo = WebContext.getUserInfo();
|
UserInfo userInfo = WebContext.getUserInfo();
|
||||||
byte[] byteSharedSecret = OtpSecret.generate(keyUriFormat.getCrypto());
|
byte[] byteSharedSecret = OtpSecret.generate(otpKeyUriFormat.getCrypto());
|
||||||
String sharedSecret = Base32Utils.encode(byteSharedSecret);
|
String sharedSecret = Base32Utils.encode(byteSharedSecret);
|
||||||
sharedSecret = passwordReciprocal.encode(sharedSecret);
|
sharedSecret = passwordReciprocal.encode(sharedSecret);
|
||||||
userInfo.setSharedSecret(sharedSecret);
|
userInfo.setSharedSecret(sharedSecret);
|
||||||
@@ -128,14 +128,14 @@ public class OneTimePasswordController {
|
|||||||
ModelAndView modelAndView = new ModelAndView("safe/hotp");
|
ModelAndView modelAndView = new ModelAndView("safe/hotp");
|
||||||
UserInfo userInfo = WebContext.getUserInfo();
|
UserInfo userInfo = WebContext.getUserInfo();
|
||||||
String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
|
String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
|
||||||
keyUriFormat.setSecret(sharedSecret);
|
otpKeyUriFormat.setSecret(sharedSecret);
|
||||||
keyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
|
otpKeyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
|
||||||
String otpauth = keyUriFormat.format(userInfo.getUsername());
|
String otpauth = otpKeyUriFormat.format(userInfo.getUsername());
|
||||||
byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
|
byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
|
||||||
String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
|
String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
|
||||||
modelAndView.addObject("id", genRqCode(otpauth));
|
modelAndView.addObject("id", genRqCode(otpauth));
|
||||||
modelAndView.addObject("userInfo", userInfo);
|
modelAndView.addObject("userInfo", userInfo);
|
||||||
modelAndView.addObject("format", keyUriFormat);
|
modelAndView.addObject("format", otpKeyUriFormat);
|
||||||
modelAndView.addObject("sharedSecret", sharedSecret);
|
modelAndView.addObject("sharedSecret", sharedSecret);
|
||||||
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
|
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
|
||||||
return modelAndView;
|
return modelAndView;
|
||||||
@@ -145,7 +145,7 @@ public class OneTimePasswordController {
|
|||||||
@RequestMapping(value = {"gen/hotp"})
|
@RequestMapping(value = {"gen/hotp"})
|
||||||
public ModelAndView genhotp() {
|
public ModelAndView genhotp() {
|
||||||
UserInfo userInfo = WebContext.getUserInfo();
|
UserInfo userInfo = WebContext.getUserInfo();
|
||||||
byte[] byteSharedSecret = OtpSecret.generate(keyUriFormat.getCrypto());
|
byte[] byteSharedSecret = OtpSecret.generate(otpKeyUriFormat.getCrypto());
|
||||||
String sharedSecret = Base32Utils.encode(byteSharedSecret);
|
String sharedSecret = Base32Utils.encode(byteSharedSecret);
|
||||||
sharedSecret = passwordReciprocal.encode(sharedSecret);
|
sharedSecret = passwordReciprocal.encode(sharedSecret);
|
||||||
userInfo.setSharedSecret(sharedSecret);
|
userInfo.setSharedSecret(sharedSecret);
|
||||||
|
|||||||
@@ -176,10 +176,10 @@ spring.kafka.producer.value-serializer =org.apache.kafka.common.seriali
|
|||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
#SMS Message Login configuration #
|
#SMS Message Login configuration #
|
||||||
#SmsOtpAuthnYunxin SmsOtpAuthnAliyun SmsOtpAuthnTencentCloud #
|
#aliyun yunxin tencentcloud #
|
||||||
############################################################################
|
############################################################################
|
||||||
#default
|
#default
|
||||||
maxkey.otp.sms =${SMS_IMPL:SmsOtpAuthnYunxin}
|
maxkey.otp.sms.provider =${SMS_PROVIDER:yunxin}
|
||||||
#aliyun
|
#aliyun
|
||||||
maxkey.otp.sms.aliyun.accesskeyid =${SMS_ALIYUN_ACCESSKEYID:94395d754eb55693043f5d6a2b772ef4}
|
maxkey.otp.sms.aliyun.accesskeyid =${SMS_ALIYUN_ACCESSKEYID:94395d754eb55693043f5d6a2b772ef4}
|
||||||
maxkey.otp.sms.aliyun.accesssecret =${SMS_ALIYUN_ACCESSSECRET:05d5485357bc}
|
maxkey.otp.sms.aliyun.accesssecret =${SMS_ALIYUN_ACCESSSECRET:05d5485357bc}
|
||||||
@@ -199,11 +199,11 @@ maxkey.otp.sms.tencentcloud.sign =${SMS_TENCENTCLOUD_SIGN:1486009
|
|||||||
############################################################################
|
############################################################################
|
||||||
#Time-based One-Time Password configuration #
|
#Time-based One-Time Password configuration #
|
||||||
############################################################################
|
############################################################################
|
||||||
maxkey.otp.keyuri.format.type =totp
|
maxkey.otp.policy.type =totp
|
||||||
maxkey.otp.keyuri.format.digits =6
|
maxkey.otp.policy.digits =6
|
||||||
maxkey.otp.keyuri.format.issuer =${OTP_KEYURI_ISSUER:MaxKey}
|
maxkey.otp.policy.issuer =${OTP_POLICY_ISSUER:MaxKey}
|
||||||
maxkey.otp.keyuri.format.domain =${maxkey.server.domain}
|
maxkey.otp.policy.domain =${maxkey.server.domain}
|
||||||
maxkey.otp.keyuri.format.period =30
|
maxkey.otp.policy.period =30
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
#LDAP Login support configuration #
|
#LDAP Login support configuration #
|
||||||
|
|||||||
@@ -178,10 +178,10 @@ spring.kafka.producer.value-serializer =org.apache.kafka.common.seriali
|
|||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
#SMS Message Login configuration #
|
#SMS Message Login configuration #
|
||||||
#SmsOtpAuthnYunxin SmsOtpAuthnAliyun SmsOtpAuthnTencentCloud #
|
#aliyun yunxin tencentcloud #
|
||||||
############################################################################
|
############################################################################
|
||||||
#default
|
#default
|
||||||
maxkey.otp.sms =${SMS_IMPL:SmsOtpAuthnYunxin}
|
maxkey.otp.sms.provider =${SMS_PROVIDER:yunxin}
|
||||||
#aliyun
|
#aliyun
|
||||||
maxkey.otp.sms.aliyun.accesskeyid =${SMS_ALIYUN_ACCESSKEYID:94395d754eb55693043f5d6a2b772ef4}
|
maxkey.otp.sms.aliyun.accesskeyid =${SMS_ALIYUN_ACCESSKEYID:94395d754eb55693043f5d6a2b772ef4}
|
||||||
maxkey.otp.sms.aliyun.accesssecret =${SMS_ALIYUN_ACCESSSECRET:05d5485357bc}
|
maxkey.otp.sms.aliyun.accesssecret =${SMS_ALIYUN_ACCESSSECRET:05d5485357bc}
|
||||||
@@ -201,11 +201,11 @@ maxkey.otp.sms.tencentcloud.sign =${SMS_TENCENTCLOUD_SIGN:1486009
|
|||||||
############################################################################
|
############################################################################
|
||||||
#Time-based One-Time Password configuration #
|
#Time-based One-Time Password configuration #
|
||||||
############################################################################
|
############################################################################
|
||||||
maxkey.otp.keyuri.format.type =totp
|
maxkey.otp.policy.type =totp
|
||||||
maxkey.otp.keyuri.format.digits =6
|
maxkey.otp.policy.digits =6
|
||||||
maxkey.otp.keyuri.format.issuer =${OTP_KEYURI_ISSUER:MaxKey}
|
maxkey.otp.policy.issuer =${OTP_POLICY_ISSUER:MaxKey}
|
||||||
maxkey.otp.keyuri.format.domain =${maxkey.server.domain}
|
maxkey.otp.policy.domain =${maxkey.server.domain}
|
||||||
maxkey.otp.keyuri.format.period =30
|
maxkey.otp.policy.period =30
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
#LDAP Login support configuration #
|
#LDAP Login support configuration #
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
<Logger level="INFO" name="org.apache.logging" ></Logger>
|
<Logger level="INFO" name="org.apache.logging" ></Logger>
|
||||||
<Logger level="DEBUG" name="org.maxkey" ></Logger>
|
<Logger level="DEBUG" name="org.maxkey" ></Logger>
|
||||||
<Logger level="ERROR" name="org.reflections.Reflections" ></Logger>
|
<Logger level="ERROR" name="org.reflections.Reflections" ></Logger>
|
||||||
|
<Logger level="OFF" name="org.hibernate.validator.internal.util.Version" ></Logger>
|
||||||
|
|
||||||
|
|
||||||
<Root level="INFO">
|
<Root level="INFO">
|
||||||
<AppenderRef ref="consolePrint" />
|
<AppenderRef ref="consolePrint" />
|
||||||
|
|||||||
@@ -157,6 +157,14 @@ spring.kafka.producer.key-serializer =org.apache.kafka.common.seriali
|
|||||||
spring.kafka.producer.value-serializer =org.apache.kafka.common.serialization.StringSerializer
|
spring.kafka.producer.value-serializer =org.apache.kafka.common.serialization.StringSerializer
|
||||||
# partitioner
|
# partitioner
|
||||||
#spring.kafka.producer.properties.partitioner.class=com.felix.kafka.producer.CustomizePartitioner
|
#spring.kafka.producer.properties.partitioner.class=com.felix.kafka.producer.CustomizePartitioner
|
||||||
|
############################################################################
|
||||||
|
#Time-based One-Time Password configuration #
|
||||||
|
############################################################################
|
||||||
|
maxkey.otp.policy.type =totp
|
||||||
|
maxkey.otp.policy.digits =6
|
||||||
|
maxkey.otp.policy.issuer =${OTP_POLICY_ISSUER:MaxKey}
|
||||||
|
maxkey.otp.policy.domain =${maxkey.server.domain}
|
||||||
|
maxkey.otp.policy.period =30
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
#SAML V2.0 configuration #
|
#SAML V2.0 configuration #
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
<Logger level="DEBUG" name="org.maxkey" ></Logger>
|
<Logger level="DEBUG" name="org.maxkey" ></Logger>
|
||||||
<Logger level="DEBUG" name="org.apache.mybatis.jpa" ></Logger>
|
<Logger level="DEBUG" name="org.apache.mybatis.jpa" ></Logger>
|
||||||
<Logger level="ERROR" name="org.reflections.Reflections" ></Logger>
|
<Logger level="ERROR" name="org.reflections.Reflections" ></Logger>
|
||||||
|
<Logger level="OFF" name="org.hibernate.validator.internal.util.Version" ></Logger>
|
||||||
|
|
||||||
<Root level="INFO">
|
<Root level="INFO">
|
||||||
<AppenderRef ref="consolePrint" />
|
<AppenderRef ref="consolePrint" />
|
||||||
|
|||||||
Reference in New Issue
Block a user