mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-06 08:59:10 +08:00
Compare commits
4 Commits
cfb09a2f1a
...
fbc735b93d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fbc735b93d | ||
|
|
62ea99f99e | ||
|
|
2e709e7352 | ||
|
|
66a8569f44 |
@ -32,14 +32,14 @@ jibToAuthPassword =docker registry credential
|
||||
|
||||
#maxkey used jars version
|
||||
#spring
|
||||
springVersion =6.2.12
|
||||
springBootVersion =3.4.11
|
||||
springSecurityVersion =6.5.6
|
||||
springDataVersion =3.5.5
|
||||
springkafkaVersion =3.3.10
|
||||
springVersion =6.2.14
|
||||
springBootVersion =3.4.12
|
||||
springSecurityVersion =6.5.7
|
||||
springDataVersion =3.5.6
|
||||
springkafkaVersion =3.3.11
|
||||
springretryVersion =2.0.11
|
||||
#spring plugin
|
||||
springbootpluginVersion =3.4.11
|
||||
springbootpluginVersion =3.4.12
|
||||
springplugincoreVersion =3.0.0
|
||||
springpluginmetadataVersion =3.0.0
|
||||
#spring cloud
|
||||
@ -84,7 +84,7 @@ freemarkerVersion =2.3.34
|
||||
xmlbeansVersion =5.0.2
|
||||
poiVersion =5.2.3
|
||||
#tomcat
|
||||
tomcatVersion =10.1.48
|
||||
tomcatVersion =10.1.49
|
||||
#logs
|
||||
log4jVersion =2.25.2
|
||||
slf4jVersion =2.0.17
|
||||
|
||||
@ -15,11 +15,10 @@
|
||||
*/
|
||||
|
||||
|
||||
package org.dromara.maxkey.util;
|
||||
package org.dromara.maxkey.http;
|
||||
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.maxkey.http.AuthorizationHeaderUtils;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
@ -1,140 +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.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.dromara.maxkey.util;
|
||||
|
||||
import java.util.Date;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 20位的流水号
|
||||
* 8位系统日期YYYYMMDD+2位节点号+6位时间戳为HHMMSS+4位顺序流水号。
|
||||
* 其中4位顺序流水号要求为“数值格式,位数不足左补零,各系统顺序生成”,为了避免顺序号重复,4位流水为该秒内的顺序流水,即每秒内每个节点最多1万笔交易
|
||||
*
|
||||
* @author Crystal.sea
|
||||
*
|
||||
*/
|
||||
public class IdSequence {
|
||||
|
||||
public static String OLD_DATETIME="";
|
||||
/**
|
||||
* 静态属性
|
||||
*/
|
||||
public static int STATIC_SEQUENCE=0;
|
||||
|
||||
/**
|
||||
* 默认节点
|
||||
*/
|
||||
public static String DEFAULT_NODE_NUMBER="01";
|
||||
|
||||
public static String STATIC_NODE_NUMBER="--";
|
||||
|
||||
/**
|
||||
* 生成20位的流水号
|
||||
* @return 流水号
|
||||
*/
|
||||
public static synchronized String next(){
|
||||
String currentDateTime=getCurrentSystemDateTime();
|
||||
|
||||
if(null==currentDateTime){
|
||||
LoggerFactory.getLogger(IdSequence.class).error("获取系统日期失败");
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuffer sequenceNumber=new StringBuffer();
|
||||
|
||||
sequenceNumber.append(currentDateTime.substring(0, 8));
|
||||
sequenceNumber.append(getNodeNumber());
|
||||
sequenceNumber.append(currentDateTime.substring(8));
|
||||
sequenceNumber.append(nextSequence());
|
||||
return sequenceNumber.toString();
|
||||
}
|
||||
|
||||
public static final String initNodeNumber(String nodeNumbers){
|
||||
if(STATIC_NODE_NUMBER.equals("--")){
|
||||
if(null!=nodeNumbers&&!nodeNumbers.equals("")){
|
||||
|
||||
String ipAddressConfigValue=nodeNumbers;
|
||||
LoggerFactory.getLogger(IdSequence.class).info("ARE config.node.number : "+ipAddressConfigValue);
|
||||
if(ipAddressConfigValue.indexOf(",")>-1){
|
||||
|
||||
String hostIpAddress=MacAddress.getAllHostMacAddress();//获得本机IP
|
||||
|
||||
LoggerFactory.getLogger(IdSequence.class).info("hostIpAddress : "+hostIpAddress);
|
||||
|
||||
String []ipAddressValues=ipAddressConfigValue.split(",");
|
||||
for(String ipvalue : ipAddressValues){
|
||||
String[] ipNode=ipvalue.split("=");
|
||||
if(ipNode!=null&&ipNode.length>0&&hostIpAddress.indexOf(ipNode[0])>-1){
|
||||
STATIC_NODE_NUMBER=ipNode[1];
|
||||
}
|
||||
}
|
||||
|
||||
if(STATIC_NODE_NUMBER.equals("--")){
|
||||
LoggerFactory.getLogger(IdSequence.class).error("GET MAC BIND NODE ERROR . ");
|
||||
STATIC_NODE_NUMBER=DEFAULT_NODE_NUMBER;
|
||||
}
|
||||
|
||||
}else{
|
||||
STATIC_NODE_NUMBER=nodeNumbers;
|
||||
}
|
||||
LoggerFactory.getLogger(IdSequence.class).info("STATIC_NODE_SEQUENCE_NUMBER : "+STATIC_NODE_NUMBER);
|
||||
if(STATIC_NODE_NUMBER.length()!=2){
|
||||
LoggerFactory.getLogger(IdSequence.class).error("系统节点号必须2位");
|
||||
}
|
||||
}else{
|
||||
STATIC_NODE_NUMBER=DEFAULT_NODE_NUMBER;
|
||||
}
|
||||
}
|
||||
return STATIC_NODE_NUMBER;
|
||||
}
|
||||
|
||||
public static final String getNodeNumber(){
|
||||
return STATIC_NODE_NUMBER;
|
||||
}
|
||||
/**
|
||||
* 同一时刻只有一个访问
|
||||
* @return
|
||||
*/
|
||||
private static final synchronized String nextSequence(){
|
||||
STATIC_SEQUENCE=(STATIC_SEQUENCE+1)%10000;
|
||||
return String.format("%04d", STATIC_SEQUENCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统当前日期,格式为yyyyMMddHHmmSS
|
||||
* @return 当前系统日期
|
||||
*/
|
||||
private static synchronized String getCurrentSystemDateTime(){
|
||||
String currentdatetime=null;
|
||||
synchronized(OLD_DATETIME)
|
||||
{
|
||||
currentdatetime=(new java.text.SimpleDateFormat("yyyyMMddHHmmss")).format(new Date());
|
||||
/**
|
||||
* 判断是否是新的时间,如果是新时间则STATIC_SEQUENCE从0开始计数
|
||||
*/
|
||||
if(!currentdatetime.equals(OLD_DATETIME)){
|
||||
STATIC_SEQUENCE=0;
|
||||
OLD_DATETIME=currentdatetime;
|
||||
}
|
||||
}
|
||||
return currentdatetime;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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.dromara.maxkey.util;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 20位的流水号
|
||||
* 8位系统日期YYYYMMDD+2位节点号+6位时间戳为HHMMSS+4位顺序流水号。
|
||||
* 其中4位顺序流水号要求为“数值格式,位数不足左补零,各系统顺序生成”,为了避免顺序号重复,4位流水为该秒内的顺序流水,即每秒内每个节点最多1万笔交易
|
||||
*
|
||||
* @author Crystal.sea
|
||||
*
|
||||
*/
|
||||
public class IdTimeSequence {
|
||||
private static final Logger logger = LoggerFactory.getLogger(IdTimeSequence.class);
|
||||
|
||||
/**
|
||||
* 默认节点编码
|
||||
*/
|
||||
public static final String DEFAULT_NODE_NUMBER = "01";
|
||||
/**
|
||||
* 历史的时间 yyyyMMddHHmmss 20250101010101
|
||||
*/
|
||||
public static String OLD_DATETIME = "";
|
||||
|
||||
/**
|
||||
* 节点编码
|
||||
*/
|
||||
public static String NODE_NUMBER = "--";
|
||||
/**
|
||||
* 静态属性
|
||||
*/
|
||||
public static int STATIC_SEQUENCE = 0;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 生成20位的流水号
|
||||
* @return 流水号
|
||||
*/
|
||||
public static synchronized String next(){
|
||||
String currentDateTime = getSystemDateTime();
|
||||
StringBuilder sequenceNumber = new StringBuilder();
|
||||
sequenceNumber.append(currentDateTime.substring(0, 8))
|
||||
.append(getNodeNumber())
|
||||
.append(currentDateTime.substring(8))
|
||||
.append(nextSequence());
|
||||
return sequenceNumber.toString();
|
||||
}
|
||||
|
||||
public static final String initNode(String nodeNumber){
|
||||
if(NODE_NUMBER.equals("--")){
|
||||
if(StringUtils.isNotBlank(nodeNumber)
|
||||
&& StringUtils.length(nodeNumber) == 2){
|
||||
NODE_NUMBER = nodeNumber;
|
||||
}else if(NODE_NUMBER.length()!=2){
|
||||
logger.error("系统节点号必须2位");
|
||||
}else{
|
||||
NODE_NUMBER = DEFAULT_NODE_NUMBER;
|
||||
}
|
||||
logger.info("NODE_NUMBER : {}",NODE_NUMBER);
|
||||
}
|
||||
return NODE_NUMBER;
|
||||
}
|
||||
|
||||
public static final String getNodeNumber(){
|
||||
return NODE_NUMBER;
|
||||
}
|
||||
/**
|
||||
* 同一时刻只有一个访问
|
||||
* @return
|
||||
*/
|
||||
private static final synchronized String nextSequence(){
|
||||
STATIC_SEQUENCE = (STATIC_SEQUENCE + 1 ) %10000;
|
||||
return String.format("%04d", STATIC_SEQUENCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统当前日期,格式为yyyyMMddHHmmSS
|
||||
* @return 当前系统日期
|
||||
*/
|
||||
private static synchronized String getSystemDateTime(){
|
||||
String currentDateTime = (new java.text.SimpleDateFormat("yyyyMMddHHmmss")).format(new Date());
|
||||
/**
|
||||
* 判断是否是新的时间,如果是新时间则STATIC_SEQUENCE从0开始计数
|
||||
*/
|
||||
if(!currentDateTime.equals(OLD_DATETIME)){
|
||||
STATIC_SEQUENCE = 0;
|
||||
OLD_DATETIME = currentDateTime;
|
||||
}
|
||||
return currentDateTime;
|
||||
}
|
||||
}
|
||||
@ -26,8 +26,8 @@ import org.dromara.maxkey.authz.oauth2.provider.OAuth2Authentication;
|
||||
import org.dromara.maxkey.authz.oauth2.provider.token.DefaultTokenServices;
|
||||
import org.dromara.maxkey.http.AuthorizationHeader;
|
||||
import org.dromara.maxkey.http.HttpResponseAdapter;
|
||||
import org.dromara.maxkey.http.RequestTokenUtils;
|
||||
import org.dromara.maxkey.util.JsonUtils;
|
||||
import org.dromara.maxkey.util.RequestTokenUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@ -33,11 +33,11 @@ import org.dromara.maxkey.entity.apps.Apps;
|
||||
import org.dromara.maxkey.entity.apps.oauth2.provider.ClientDetails;
|
||||
import org.dromara.maxkey.entity.idm.UserInfo;
|
||||
import org.dromara.maxkey.http.HttpResponseAdapter;
|
||||
import org.dromara.maxkey.http.RequestTokenUtils;
|
||||
import org.dromara.maxkey.persistence.service.AppsService;
|
||||
import org.dromara.maxkey.persistence.service.UserInfoService;
|
||||
import org.dromara.maxkey.util.Instance;
|
||||
import org.dromara.maxkey.util.JsonUtils;
|
||||
import org.dromara.maxkey.util.RequestTokenUtils;
|
||||
import org.dromara.maxkey.util.StringGenerator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -39,10 +39,10 @@ import org.dromara.maxkey.crypto.jwt.signer.service.impl.DefaultJwtSigningAndVal
|
||||
import org.dromara.maxkey.entity.apps.oauth2.provider.ClientDetails;
|
||||
import org.dromara.maxkey.entity.idm.UserInfo;
|
||||
import org.dromara.maxkey.http.HttpResponseAdapter;
|
||||
import org.dromara.maxkey.http.RequestTokenUtils;
|
||||
import org.dromara.maxkey.persistence.service.AppsService;
|
||||
import org.dromara.maxkey.persistence.service.UserInfoService;
|
||||
import org.dromara.maxkey.util.JsonUtils;
|
||||
import org.dromara.maxkey.util.RequestTokenUtils;
|
||||
import org.dromara.maxkey.util.StringGenerator;
|
||||
import org.dromara.maxkey.web.WebConstants;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@ -17,8 +17,18 @@
|
||||
|
||||
package org.dromara.maxkey.autoconfigure;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.dromara.maxkey.configuration.EmailConfig;
|
||||
import org.dromara.maxkey.constants.ConstsPersistence;
|
||||
import org.dromara.maxkey.password.onetimepwd.AbstractOtpAuthn;
|
||||
import org.dromara.maxkey.password.onetimepwd.MailOtpAuthnService;
|
||||
import org.dromara.maxkey.password.onetimepwd.algorithm.OtpKeyUriFormat;
|
||||
import org.dromara.maxkey.password.onetimepwd.impl.MailOtpAuthn;
|
||||
import org.dromara.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
|
||||
import org.dromara.maxkey.password.onetimepwd.token.RedisOtpTokenStore;
|
||||
import org.dromara.maxkey.persistence.redis.RedisConnectionFactory;
|
||||
import org.dromara.maxkey.persistence.service.CnfEmailSendersService;
|
||||
@ -27,17 +37,35 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
|
||||
@AutoConfiguration
|
||||
public class OneTimePasswordAutoConfiguration {
|
||||
private static final Logger _logger =
|
||||
LoggerFactory.getLogger(OneTimePasswordAutoConfiguration.class);
|
||||
private static final Logger _logger = LoggerFactory.getLogger(OneTimePasswordAutoConfiguration.class);
|
||||
|
||||
@Bean
|
||||
OtpKeyUriFormat otpKeyUriFormat(
|
||||
@Value("${maxkey.otp.policy.type:totp}")
|
||||
String type,
|
||||
@Value("${maxkey.otp.policy.domain:MaxKey.top}")
|
||||
String domain,
|
||||
@Value("${maxkey.otp.policy.issuer:MaxKey}")
|
||||
String issuer,
|
||||
@Value("${maxkey.otp.policy.digits:6}")
|
||||
int digits,
|
||||
@Value("${maxkey.otp.policy.period:30}")
|
||||
int period) {
|
||||
|
||||
OtpKeyUriFormat otpKeyUriFormat=new OtpKeyUriFormat(type,issuer,domain,digits,period);
|
||||
_logger.debug("OTP KeyUri Format {}" , otpKeyUriFormat);
|
||||
return otpKeyUriFormat;
|
||||
}
|
||||
|
||||
@Bean(name = "mailOtpAuthnService")
|
||||
MailOtpAuthnService mailOtpAuthnService(
|
||||
@Value("${maxkey.server.persistence}") int persistence,
|
||||
@Value("${maxkey.server.persistence:0}") int persistence,
|
||||
CnfEmailSendersService emailSendersService,
|
||||
RedisConnectionFactory redisConnFactory) {
|
||||
MailOtpAuthnService otpAuthnService =
|
||||
@ -53,4 +81,68 @@ public class OneTimePasswordAutoConfiguration {
|
||||
return otpAuthnService;
|
||||
}
|
||||
|
||||
@Bean
|
||||
TimeBasedOtpAuthn timeBasedOtpAuthn(
|
||||
@Value("${maxkey.otp.policy.digits:6}")
|
||||
int digits,
|
||||
@Value("${maxkey.otp.policy.period:30}")
|
||||
int period) {
|
||||
TimeBasedOtpAuthn timeBasedOtpAuthn = new TimeBasedOtpAuthn(digits , period);
|
||||
_logger.debug("TimeBasedOtpAuthn inited.");
|
||||
return timeBasedOtpAuthn;
|
||||
}
|
||||
|
||||
@Bean
|
||||
AbstractOtpAuthn tfaOtpAuthn(
|
||||
@Value("${maxkey.login.mfa.type:TimeBasedOtpAuthn}") String mfaType,
|
||||
@Value("${maxkey.otp.policy.digits:6}")
|
||||
int digits,
|
||||
@Value("${maxkey.otp.policy.period:30}")
|
||||
int period,
|
||||
@Value("${maxkey.server.persistence:0}") int persistence,
|
||||
RedisConnectionFactory redisConnFactory) {
|
||||
AbstractOtpAuthn tfaOtpAuthn = new TimeBasedOtpAuthn(digits , period);
|
||||
_logger.debug("TFAOtpAuthn inited.");
|
||||
|
||||
if (persistence == ConstsPersistence.REDIS) {
|
||||
RedisOtpTokenStore redisOptTokenStore = new RedisOtpTokenStore(redisConnFactory);
|
||||
tfaOtpAuthn.setOptTokenStore(redisOptTokenStore);
|
||||
}
|
||||
|
||||
tfaOtpAuthn.initPropertys();
|
||||
return tfaOtpAuthn;
|
||||
}
|
||||
|
||||
@Bean
|
||||
MailOtpAuthn mailOtpAuthn(
|
||||
EmailConfig emailConfig,
|
||||
@Value("${spring.mail.properties.mailotp.message.subject:One Time PassWord}")
|
||||
String messageSubject,
|
||||
@Value("${spring.mail.properties.mailotp.message.template:You Token is %s }")
|
||||
String messageTemplate,
|
||||
@Value("${spring.mail.properties.mailotp.message.validity:300}")
|
||||
int messageValidity,
|
||||
@Value("${spring.mail.properties.mailotp.message.type:text}")
|
||||
String messageType
|
||||
) {
|
||||
if(messageType!= null && messageType.equalsIgnoreCase("html")) {
|
||||
Resource resource = new ClassPathResource("messages/email/forgotpassword.html");
|
||||
try {
|
||||
BufferedReader bufferedReader =new BufferedReader(new InputStreamReader(resource.getInputStream()));
|
||||
messageTemplate = bufferedReader.lines().collect(Collectors.joining("\n"));
|
||||
bufferedReader.close();
|
||||
} catch (IOException e) {
|
||||
_logger.error("mailOtpAuthn IOException ",e);
|
||||
}
|
||||
}
|
||||
_logger.trace("messageTemplate \n {}" ,messageTemplate);
|
||||
MailOtpAuthn mailOtpAuthn = new MailOtpAuthn();
|
||||
mailOtpAuthn.setSubject(messageSubject);
|
||||
mailOtpAuthn.setMessageTemplate(messageTemplate);
|
||||
mailOtpAuthn.setEmailConfig(emailConfig);
|
||||
mailOtpAuthn.setInterval(messageValidity);
|
||||
_logger.debug("MailOtpAuthn inited.");
|
||||
return mailOtpAuthn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,13 +17,8 @@
|
||||
|
||||
package org.dromara.maxkey.autoconfigure;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.dromara.maxkey.authn.listener.SessionListenerAdapter;
|
||||
import org.dromara.maxkey.authn.realm.jdbc.JdbcAuthenticationRealm;
|
||||
import org.dromara.maxkey.authn.realm.ldap.LdapAuthenticationRealmService;
|
||||
@ -32,16 +27,8 @@ import org.dromara.maxkey.authn.session.SessionManager;
|
||||
import org.dromara.maxkey.authn.support.kerberos.KerberosProxy;
|
||||
import org.dromara.maxkey.authn.support.kerberos.RemoteKerberosService;
|
||||
import org.dromara.maxkey.configuration.ApplicationConfig;
|
||||
import org.dromara.maxkey.configuration.EmailConfig;
|
||||
import org.dromara.maxkey.constants.ConstsPersistence;
|
||||
import org.dromara.maxkey.ip2location.IpLocationParser;
|
||||
import org.dromara.maxkey.password.onetimepwd.AbstractOtpAuthn;
|
||||
import org.dromara.maxkey.password.onetimepwd.MailOtpAuthnService;
|
||||
import org.dromara.maxkey.password.onetimepwd.algorithm.OtpKeyUriFormat;
|
||||
import org.dromara.maxkey.password.onetimepwd.impl.MailOtpAuthn;
|
||||
import org.dromara.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
|
||||
import org.dromara.maxkey.password.onetimepwd.token.RedisOtpTokenStore;
|
||||
import org.dromara.maxkey.persistence.redis.RedisConnectionFactory;
|
||||
import org.dromara.maxkey.persistence.service.CnfLdapContextService;
|
||||
import org.dromara.maxkey.persistence.service.HistoryLoginService;
|
||||
import org.dromara.maxkey.persistence.service.LoginService;
|
||||
@ -56,8 +43,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@ -65,25 +50,6 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
public class MaxKeyConfig {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MaxKeyConfig.class);
|
||||
|
||||
|
||||
@Bean
|
||||
OtpKeyUriFormat otpKeyUriFormat(
|
||||
@Value("${maxkey.otp.policy.type:totp}")
|
||||
String type,
|
||||
@Value("${maxkey.otp.policy.domain:MaxKey.top}")
|
||||
String domain,
|
||||
@Value("${maxkey.otp.policy.issuer:MaxKey}")
|
||||
String issuer,
|
||||
@Value("${maxkey.otp.policy.digits:6}")
|
||||
int digits,
|
||||
@Value("${maxkey.otp.policy.period:30}")
|
||||
int period) {
|
||||
|
||||
OtpKeyUriFormat otpKeyUriFormat=new OtpKeyUriFormat(type,issuer,domain,digits,period);
|
||||
logger.debug("OTP KeyUri Format {}" , otpKeyUriFormat);
|
||||
return otpKeyUriFormat;
|
||||
}
|
||||
|
||||
//可以在此实现其他的登陆认证方式,请实现AbstractAuthenticationRealm
|
||||
@Bean
|
||||
JdbcAuthenticationRealm authenticationRealm(
|
||||
@ -109,71 +75,6 @@ public class MaxKeyConfig {
|
||||
);
|
||||
}
|
||||
|
||||
@Bean
|
||||
TimeBasedOtpAuthn 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.");
|
||||
return tfaOtpAuthn;
|
||||
}
|
||||
|
||||
@Bean
|
||||
AbstractOtpAuthn tfaOtpAuthn(
|
||||
@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,
|
||||
RedisConnectionFactory redisConnFactory) {
|
||||
AbstractOtpAuthn tfaOtpAuthn = new TimeBasedOtpAuthn(digits , period);
|
||||
logger.debug("TimeBasedOtpAuthn inited.");
|
||||
|
||||
if (persistence == ConstsPersistence.REDIS) {
|
||||
RedisOtpTokenStore redisOptTokenStore = new RedisOtpTokenStore(redisConnFactory);
|
||||
tfaOtpAuthn.setOptTokenStore(redisOptTokenStore);
|
||||
}
|
||||
|
||||
tfaOtpAuthn.initPropertys();
|
||||
return tfaOtpAuthn;
|
||||
}
|
||||
|
||||
@Bean
|
||||
MailOtpAuthn mailOtpAuthn(
|
||||
EmailConfig emailConfig,
|
||||
@Value("${spring.mail.properties.mailotp.message.subject}")
|
||||
String messageSubject,
|
||||
@Value("${spring.mail.properties.mailotp.message.template}")
|
||||
String messageTemplate,
|
||||
@Value("${spring.mail.properties.mailotp.message.validity}")
|
||||
int messageValidity,
|
||||
@Value("${spring.mail.properties.mailotp.message.type}")
|
||||
String messageType
|
||||
) {
|
||||
if(messageType!= null && messageType.equalsIgnoreCase("html")) {
|
||||
Resource resource = new ClassPathResource("messages/email/forgotpassword.html");
|
||||
try {
|
||||
BufferedReader bufferedReader =new BufferedReader(new InputStreamReader(resource.getInputStream()));
|
||||
messageTemplate = bufferedReader.lines().collect(Collectors.joining("\n"));
|
||||
bufferedReader.close();
|
||||
} catch (IOException e) {
|
||||
logger.error("mailOtpAuthn IOException ",e);
|
||||
}
|
||||
}
|
||||
logger.trace("messageTemplate \n {}" ,messageTemplate);
|
||||
MailOtpAuthn mailOtpAuthn = new MailOtpAuthn();
|
||||
mailOtpAuthn.setSubject(messageSubject);
|
||||
mailOtpAuthn.setMessageTemplate(messageTemplate);
|
||||
mailOtpAuthn.setEmailConfig(emailConfig);
|
||||
mailOtpAuthn.setInterval(messageValidity);
|
||||
logger.debug("MailOtpAuthn inited.");
|
||||
return mailOtpAuthn;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
RemoteKerberosService kerberosService(
|
||||
@Value("${maxkey.login.kerberos.default.userdomain}")
|
||||
|
||||
@ -19,8 +19,6 @@ package org.dromara.maxkey.autoconfigure;
|
||||
|
||||
import org.dromara.maxkey.authn.realm.jdbc.JdbcAuthenticationRealm;
|
||||
import org.dromara.maxkey.ip2location.IpLocationParser;
|
||||
import org.dromara.maxkey.password.onetimepwd.AbstractOtpAuthn;
|
||||
import org.dromara.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
|
||||
import org.dromara.maxkey.persistence.service.HistoryLoginService;
|
||||
import org.dromara.maxkey.persistence.service.LoginService;
|
||||
import org.dromara.maxkey.persistence.service.PasswordPolicyValidatorService;
|
||||
@ -62,19 +60,4 @@ public class MaxKeyMgtConfig {
|
||||
return authenticationRealm;
|
||||
}
|
||||
|
||||
@Bean
|
||||
AbstractOtpAuthn timeBasedOtpAuthn() {
|
||||
AbstractOtpAuthn tfaOtpAuthn = new TimeBasedOtpAuthn();
|
||||
logger.debug("TimeBasedOtpAuthn inited.");
|
||||
return tfaOtpAuthn;
|
||||
}
|
||||
|
||||
/*@Bean
|
||||
public ISynchronizerService ldapSynchronizerService() {
|
||||
LdapSynchronizerService ldapSynchronizerService = new LdapSynchronizerService();
|
||||
ldapSynchronizerService.setId("LDAP_11122");
|
||||
ldapSynchronizerService.syncOrg();
|
||||
return ldapSynchronizerService;
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ spring.mail.properties.ssl =true
|
||||
spring.mail.properties.sender =${MAIL_SENDER:maxkey@163.com}
|
||||
spring.mail.properties.mailotp.message.subject =MaxKey One Time PassWord
|
||||
spring.mail.properties.mailotp.message.template ={0} You Token is {1} , it validity in {2} minutes.
|
||||
spring.mail.properties.mailotp.message.type =html
|
||||
spring.mail.properties.mailotp.message.type =text
|
||||
spring.mail.properties.mailotp.message.validity =300
|
||||
|
||||
############################################################################
|
||||
|
||||
@ -19,8 +19,6 @@ package org.dromara.maxkey.autoconfigure;
|
||||
|
||||
import org.dromara.maxkey.authn.realm.jdbc.JdbcAuthenticationRealm;
|
||||
import org.dromara.maxkey.ip2location.IpLocationParser;
|
||||
import org.dromara.maxkey.password.onetimepwd.AbstractOtpAuthn;
|
||||
import org.dromara.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
|
||||
import org.dromara.maxkey.persistence.service.HistoryLoginService;
|
||||
import org.dromara.maxkey.persistence.service.LoginService;
|
||||
import org.dromara.maxkey.persistence.service.PasswordPolicyValidatorService;
|
||||
@ -62,10 +60,4 @@ public class MaxKeyOpenApiConfig{
|
||||
return authenticationRealm;
|
||||
}
|
||||
|
||||
@Bean
|
||||
AbstractOtpAuthn timeBasedOtpAuthn() {
|
||||
AbstractOtpAuthn tfaOtpAuthn = new TimeBasedOtpAuthn();
|
||||
logger.debug("TimeBasedOtpAuthn inited.");
|
||||
return tfaOtpAuthn;
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ spring.mail.properties.ssl =true
|
||||
spring.mail.properties.sender =${MAIL_SENDER:maxkey@163.com}
|
||||
spring.mail.properties.mailotp.message.subject =MaxKey One Time PassWord
|
||||
spring.mail.properties.mailotp.message.template ={0} You Token is {1} , it validity in {2} minutes.
|
||||
spring.mail.properties.mailotp.message.type =html
|
||||
spring.mail.properties.mailotp.message.type =text
|
||||
spring.mail.properties.mailotp.message.validity =300
|
||||
|
||||
############################################################################
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user