MFA Enhance

MFA  Enhance
This commit is contained in:
shimingxy
2020-05-31 12:13:15 +08:00
parent 1c0ea6ce7e
commit 4b197b9c33
13 changed files with 241 additions and 126 deletions

View File

@@ -188,7 +188,7 @@ public abstract class AbstractAuthenticationProvider {
*/
protected void tftcaptchaValid(String otpCaptcha, String authType, UserInfo userInfo) {
// for one time password 2 factor
if (applicationConfig.getLoginConfig().isOneTimePwd() && authType.equalsIgnoreCase("tfa")) {
if (applicationConfig.getLoginConfig().isMfa() && authType.equalsIgnoreCase("tfa")) {
UserInfo validUserInfo = new UserInfo();
validUserInfo.setUsername(userInfo.getUsername());
String sharedSecret =

View File

@@ -15,8 +15,8 @@ public class LoginConfig {
@Value("${config.login.captcha.type:text}")
String captchaType;
@Value("${config.login.onetimepwd}")
boolean oneTimePwd;
@Value("${config.login.mfa}")
boolean mfa;
@Value("${config.login.socialsignon}")
boolean socialSignOn;
@@ -48,14 +48,6 @@ public class LoginConfig {
this.captcha = captcha;
}
public boolean isOneTimePwd() {
return oneTimePwd;
}
public void setOneTimePwd(boolean oneTimePwd) {
this.oneTimePwd = oneTimePwd;
}
public boolean isSocialSignOn() {
return socialSignOn;
}
@@ -72,6 +64,14 @@ public class LoginConfig {
this.kerberos = kerberos;
}
public boolean isMfa() {
return mfa;
}
public void setMfa(boolean mfa) {
this.mfa = mfa;
}
public String getDefaultUri() {
return defaultUri;
}
@@ -109,7 +109,7 @@ public class LoginConfig {
StringBuilder builder = new StringBuilder();
builder
.append("LoginConfig [captcha=").append(captcha)
.append(", oneTimePwd=").append(oneTimePwd)
.append(", mfa=").append(mfa)
.append(", socialSignOn=").append(socialSignOn)
.append(", kerberos=").append(kerberos)
.append(", remeberMe=").append(remeberMe)

View File

@@ -1,15 +1,26 @@
package org.maxkey.crypto.password.opt.impl;
import java.io.IOException;
import java.util.Properties;
import org.maxkey.constants.ConstantsProperties;
import org.maxkey.crypto.password.opt.AbstractOptAuthn;
import org.maxkey.domain.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class SmsOtpAuthn extends AbstractOptAuthn {
private static final Logger logger = LoggerFactory.getLogger(SmsOtpAuthn.class);
protected Properties properties;
@Override
public boolean produce(UserInfo userInfo) {
String token = this.genToken(userInfo);
// TODO:You must add send sms code here
logger.debug("send sms code" + token);
return true;
}
@@ -17,5 +28,18 @@ public class SmsOtpAuthn extends AbstractOptAuthn {
public boolean validate(UserInfo userInfo, String token) {
return true;
}
protected void loadProperties() throws IOException {
Resource resource = new ClassPathResource(
ConstantsProperties.classPathResource(
ConstantsProperties.classPathResource(
ConstantsProperties.maxKeyPropertySource)));
properties = new Properties();
properties.load(resource.getInputStream());
}
public void initPropertys() {
}
}

View File

@@ -6,6 +6,9 @@ import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import java.io.IOException;
import org.maxkey.crypto.password.opt.impl.SmsOtpAuthn;
import org.maxkey.domain.UserInfo;
import org.slf4j.Logger;
@@ -110,4 +113,18 @@ public class SmsOtpAuthnAliyun extends SmsOtpAuthn {
this.signName = signName;
}
@Override
public void initPropertys() {
try {
this.loadProperties();
} catch (IOException e) {
e.printStackTrace();
}
this.accessKeyId = this.properties.getProperty("config.otp.sms.aliyun.accesskeyid");
this.accessSecret = this.properties.getProperty("config.otp.sms.aliyun.accesssecret");
this.templateCode = this.properties.getProperty("config.otp.sms.aliyun.templatecode");
this.signName = this.properties.getProperty("config.otp.sms.aliyun.signname");
}
}

View File

@@ -6,6 +6,9 @@ import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
import java.io.IOException;
import org.maxkey.crypto.password.opt.impl.SmsOtpAuthn;
import org.maxkey.domain.UserInfo;
import org.slf4j.Logger;
@@ -153,4 +156,19 @@ public class SmsOtpAuthnTencentCloud extends SmsOtpAuthn {
this.sign = sign;
}
@Override
public void initPropertys() {
try {
this.loadProperties();
} catch (IOException e) {
e.printStackTrace();
}
this.secretId = this.properties.getProperty("config.otp.sms.tencentcloud.secretid");
this.secretKey = this.properties.getProperty("config.otp.sms.tencentcloud.secretkey");
this.smsSdkAppid = this.properties.getProperty("config.otp.sms.tencentcloud.smssdkappid");
this.templateId = this.properties.getProperty("config.otp.sms.tencentcloud.templateid");
this.sign = this.properties.getProperty("config.otp.sms.tencentcloud.sign");
}
}

View File

@@ -1,5 +1,6 @@
package org.maxkey.crypto.password.opt.impl.sms;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -184,6 +185,19 @@ public class SmsOtpAuthnYunxin extends SmsOtpAuthn {
}
@Override
public void initPropertys() {
try {
this.loadProperties();
} catch (IOException e) {
e.printStackTrace();
}
this.appKey = this.properties.getProperty("config.otp.sms.yunxin.appkey");
this.appSecret = this.properties.getProperty("config.otp.sms.yunxin.appsecret");
this.templateId = this.properties.getProperty("config.otp.sms.yunxin.templateid");
}
/**
* main.
* @param args String