配置文件优化,参数整合及日志优化

This commit is contained in:
Crystal.Sea
2021-10-06 19:42:10 +08:00
parent fe8c89a459
commit 1b70eec8a9
15 changed files with 139 additions and 102 deletions

View File

@@ -17,7 +17,7 @@
package org.maxkey.password.onetimepwd.algorithm;
public class KeyUriFormat {
public class OtpKeyUriFormat {
public class Types {
public static final String HOTP = "hotp";
@@ -38,7 +38,7 @@ public class KeyUriFormat {
String account;
public KeyUriFormat() {
public OtpKeyUriFormat() {
}
@@ -46,7 +46,7 @@ public class KeyUriFormat {
* @param type
* @param secret
*/
public KeyUriFormat(String type, String secret) {
public OtpKeyUriFormat(String type, String secret) {
this.type = type;
this.secret = secret;
}
@@ -56,12 +56,35 @@ public class KeyUriFormat {
* @param secret
* @param issuer
*/
public KeyUriFormat(String type, String secret, String issuer) {
public OtpKeyUriFormat(String type, String secret, String issuer) {
this.type = type;
this.secret = secret;
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
*/

View File

@@ -18,17 +18,17 @@
package org.maxkey.password.onetimepwd.impl;
import java.io.IOException;
import java.util.Properties;
import org.maxkey.entity.UserInfo;
import org.maxkey.password.onetimepwd.AbstractOtpAuthn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.StandardEnvironment;
public class SmsOtpAuthn extends AbstractOtpAuthn {
private static final Logger logger = LoggerFactory.getLogger(SmsOtpAuthn.class);
protected Properties properties;
protected StandardEnvironment properties;
@Override
@@ -44,7 +44,7 @@ public class SmsOtpAuthn extends AbstractOtpAuthn {
return true;
}
public void setProperties(Properties properties) {
public void setProperties(StandardEnvironment properties) {
this.properties = properties;
}

View File

@@ -38,6 +38,12 @@ public class TimeBasedOtpAuthn extends AbstractOtpAuthn {
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
}
public TimeBasedOtpAuthn(int digits , int interval) {
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
super.digits = digits;
super.interval = interval;
}
@Override
public boolean produce(UserInfo userInfo) {
return true;

View File

@@ -138,10 +138,10 @@ public class SmsOtpAuthnAliyun extends SmsOtpAuthn {
e.printStackTrace();
}
this.accessKeyId = this.properties.getProperty("maxkey.otp.sms.aliyun.accesskeyid");
this.accessSecret = this.properties.getProperty("maxkey.otp.sms.aliyun.accesssecret");
this.templateCode = this.properties.getProperty("maxkey.otp.sms.aliyun.templatecode");
this.signName = this.properties.getProperty("maxkey.otp.sms.aliyun.signname");
this.accessKeyId = properties.getProperty("maxkey.otp.sms.aliyun.accesskeyid");
this.accessSecret = properties.getProperty("maxkey.otp.sms.aliyun.accesssecret");
this.templateCode = properties.getProperty("maxkey.otp.sms.aliyun.templatecode");
this.signName = properties.getProperty("maxkey.otp.sms.aliyun.signname");
}
}

View File

@@ -55,7 +55,6 @@ public class SmsOtpAuthnTencentCloud extends SmsOtpAuthn {
otpType = OtpTypes.SMS;
}
@Override
@@ -181,11 +180,11 @@ public class SmsOtpAuthnTencentCloud extends SmsOtpAuthn {
e.printStackTrace();
}
this.secretId = this.properties.getProperty("maxkey.otp.sms.tencentcloud.secretid");
this.secretKey = this.properties.getProperty("maxkey.otp.sms.tencentcloud.secretkey");
this.smsSdkAppid = this.properties.getProperty("maxkey.otp.sms.tencentcloud.smssdkappid");
this.templateId = this.properties.getProperty("maxkey.otp.sms.tencentcloud.templateid");
this.sign = this.properties.getProperty("maxkey.otp.sms.tencentcloud.sign");
this.secretId = properties.getProperty("maxkey.otp.sms.tencentcloud.secretid");
this.secretKey = properties.getProperty("maxkey.otp.sms.tencentcloud.secretkey");
this.smsSdkAppid = properties.getProperty("maxkey.otp.sms.tencentcloud.smssdkappid");
this.templateId = properties.getProperty("maxkey.otp.sms.tencentcloud.templateid");
this.sign = properties.getProperty("maxkey.otp.sms.tencentcloud.sign");
}
}

View File

@@ -212,9 +212,9 @@ public class SmsOtpAuthnYunxin extends SmsOtpAuthn {
e.printStackTrace();
}
this.appKey = this.properties.getProperty("maxkey.otp.sms.yunxin.appkey");
this.appSecret = this.properties.getProperty("maxkey.otp.sms.yunxin.appsecret");
this.templateId = this.properties.getProperty("maxkey.otp.sms.yunxin.templateid");
this.appKey = properties.getProperty("maxkey.otp.sms.yunxin.appkey");
this.appSecret = properties.getProperty("maxkey.otp.sms.yunxin.appsecret");
this.templateId = properties.getProperty("maxkey.otp.sms.yunxin.templateid");
}
/**

View File

@@ -19,7 +19,7 @@ package org.maxkey.otp.algorithm;
import java.io.File;
import org.maxkey.password.onetimepwd.algorithm.KeyUriFormat;
import org.maxkey.password.onetimepwd.algorithm.OtpKeyUriFormat;
import org.maxkey.util.QRCode;
import com.google.zxing.BarcodeFormat;
@@ -29,7 +29,7 @@ import com.google.zxing.common.BitMatrix;
public class KeyUriFormatTest {
public static void main(String[] args) {
try {
KeyUriFormat kuf=new KeyUriFormat(KeyUriFormat.Types.TOTP,
OtpKeyUriFormat kuf=new OtpKeyUriFormat(OtpKeyUriFormat.Types.TOTP,
"GIWVWOL7EI5WLVZPDMROEPSTFBEVO77Q",
"connsec.com");
kuf.setPeriod(60);