diff --git a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/autoconfigure/OneTimePasswordAutoConfiguration.java b/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/autoconfigure/OneTimePasswordAutoConfiguration.java index 694a26184b918cc9aaf690ad499b2aecb640dc55..9feac9db2c57f86d8669225c535d8fdf7b3466de 100644 --- a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/autoconfigure/OneTimePasswordAutoConfiguration.java +++ b/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/autoconfigure/OneTimePasswordAutoConfiguration.java @@ -18,11 +18,10 @@ package org.maxkey.autoconfigure; import org.maxkey.constants.ConstsPersistence; -import org.maxkey.password.onetimepwd.OtpAuthnService; +import org.maxkey.password.onetimepwd.MailOtpAuthnService; import org.maxkey.password.onetimepwd.token.RedisOtpTokenStore; import org.maxkey.persistence.redis.RedisConnectionFactory; import org.maxkey.persistence.service.EmailSendersService; -import org.maxkey.persistence.service.SmsProviderService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; @@ -37,21 +36,20 @@ public class OneTimePasswordAutoConfiguration implements InitializingBean { LoggerFactory.getLogger(OneTimePasswordAutoConfiguration.class); - @Bean(name = "otpAuthnService") - public OtpAuthnService otpAuthnService( + @Bean(name = "mailOtpAuthnService") + public MailOtpAuthnService mailOtpAuthnService( @Value("${maxkey.server.persistence}") int persistence, - SmsProviderService smsProviderService, EmailSendersService emailSendersService, RedisConnectionFactory redisConnFactory) { - OtpAuthnService otpAuthnService = - new OtpAuthnService(smsProviderService,emailSendersService); + MailOtpAuthnService otpAuthnService = + new MailOtpAuthnService(emailSendersService); if (persistence == ConstsPersistence.REDIS) { RedisOtpTokenStore redisOptTokenStore = new RedisOtpTokenStore(redisConnFactory); otpAuthnService.setRedisOptTokenStore(redisOptTokenStore); } - _logger.debug("OneTimePasswordService {} inited." , + _logger.debug("MailOtpAuthnService {} inited." , persistence == ConstsPersistence.REDIS ? "Redis" : "InMemory"); return otpAuthnService; } diff --git a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/MailOtpAuthnService.java b/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/MailOtpAuthnService.java new file mode 100644 index 0000000000000000000000000000000000000000..60e8d3b178f058472b3e96c48aed3a26a8b3cd2d --- /dev/null +++ b/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/MailOtpAuthnService.java @@ -0,0 +1,85 @@ +/* + * Copyright [2022] [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.password.onetimepwd; + +import java.sql.Types; +import java.util.concurrent.TimeUnit; + +import org.maxkey.configuration.EmailConfig; +import org.maxkey.constants.ConstsBoolean; +import org.maxkey.crypto.password.PasswordReciprocal; +import org.maxkey.entity.EmailSenders; +import org.maxkey.password.onetimepwd.impl.MailOtpAuthn; +import org.maxkey.password.onetimepwd.token.RedisOtpTokenStore; +import org.maxkey.persistence.service.EmailSendersService; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; + +public class MailOtpAuthnService { + + protected static final Cache otpAuthnStore = + Caffeine.newBuilder() + .expireAfterWrite(60, TimeUnit.MINUTES) + .build(); + + EmailSendersService emailSendersService; + + RedisOtpTokenStore redisOptTokenStore; + + public MailOtpAuthnService(EmailSendersService emailSendersService) { + this.emailSendersService = emailSendersService; + } + + public MailOtpAuthnService(RedisOtpTokenStore redisOptTokenStore) { + this.redisOptTokenStore = redisOptTokenStore; + } + + + public AbstractOtpAuthn getMailOtpAuthn(String instId) { + AbstractOtpAuthn otpAuthn = otpAuthnStore.getIfPresent(instId); + if(otpAuthn == null) { + EmailSenders emailSender = + emailSendersService.findOne("where instid = ? ", new Object[]{instId}, new int[]{Types.VARCHAR}); + + String credentials = PasswordReciprocal.getInstance().decoder(emailSender.getCredentials()); + EmailConfig emailConfig = + new EmailConfig( + emailSender.getAccount(), + credentials, + emailSender.getSmtpHost(), + emailSender.getPort(), + ConstsBoolean.isTrue(emailSender.getSslSwitch()), + emailSender.getSender()); + MailOtpAuthn mailOtpAuthn = new MailOtpAuthn(emailConfig); + mailOtpAuthn.setInterval(60 * 5);//5 minute + if(redisOptTokenStore != null) { + mailOtpAuthn.setOptTokenStore(redisOptTokenStore); + } + otpAuthn = mailOtpAuthn; + } + otpAuthnStore.put(instId, otpAuthn); + return otpAuthn; + } + + public void setRedisOptTokenStore(RedisOtpTokenStore redisOptTokenStore) { + this.redisOptTokenStore = redisOptTokenStore; + } + + +} diff --git a/maxkey-authentications/maxkey-authentication-provider/build.gradle b/maxkey-authentications/maxkey-authentication-provider/build.gradle index 5270778b6dbc25b8025ae05b5f00cb584fdf1796..424d3d32f78bb5fa8dae10143a6ce133f77347c5 100644 --- a/maxkey-authentications/maxkey-authentication-provider/build.gradle +++ b/maxkey-authentications/maxkey-authentication-provider/build.gradle @@ -11,5 +11,6 @@ dependencies { implementation project(":maxkey-persistence") implementation project(":maxkey-authentications:maxkey-authentication-core") implementation project(":maxkey-authentications:maxkey-authentication-otp") + implementation project(":maxkey-authentications:maxkey-authentication-sms") } \ No newline at end of file diff --git a/maxkey-authentications/maxkey-authentication-provider/src/main/java/org/maxkey/authn/provider/AbstractAuthenticationProvider.java b/maxkey-authentications/maxkey-authentication-provider/src/main/java/org/maxkey/authn/provider/AbstractAuthenticationProvider.java index 082f2abeb45ca85526f2551cceba227f33ce33ab..61e24a6e7cd13727cf517812e3b16c4156fabd9e 100644 --- a/maxkey-authentications/maxkey-authentication-provider/src/main/java/org/maxkey/authn/provider/AbstractAuthenticationProvider.java +++ b/maxkey-authentications/maxkey-authentication-provider/src/main/java/org/maxkey/authn/provider/AbstractAuthenticationProvider.java @@ -31,7 +31,7 @@ import org.maxkey.constants.ConstsLoginType; import org.maxkey.constants.ConstsStatus; import org.maxkey.entity.UserInfo; import org.maxkey.password.onetimepwd.AbstractOtpAuthn; -import org.maxkey.password.onetimepwd.OtpAuthnService; +import org.maxkey.password.onetimepwd.MailOtpAuthnService; import org.maxkey.web.WebConstants; import org.maxkey.web.WebContext; import org.slf4j.Logger; @@ -67,7 +67,7 @@ public abstract class AbstractAuthenticationProvider { protected AbstractOtpAuthn tfaOtpAuthn; - protected OtpAuthnService otpAuthnService; + protected MailOtpAuthnService otpAuthnService; protected SessionManager sessionManager; diff --git a/maxkey-authentications/maxkey-authentication-provider/src/main/java/org/maxkey/authn/provider/impl/MobileAuthenticationProvider.java b/maxkey-authentications/maxkey-authentication-provider/src/main/java/org/maxkey/authn/provider/impl/MobileAuthenticationProvider.java index 022c6465c7e1b46f226c1e99904eac786f78acab..ab80942c4e19867c3151b0d3da63a706df8b589b 100644 --- a/maxkey-authentications/maxkey-authentication-provider/src/main/java/org/maxkey/authn/provider/impl/MobileAuthenticationProvider.java +++ b/maxkey-authentications/maxkey-authentication-provider/src/main/java/org/maxkey/authn/provider/impl/MobileAuthenticationProvider.java @@ -25,7 +25,7 @@ import org.maxkey.configuration.ApplicationConfig; import org.maxkey.constants.ConstsLoginType; import org.maxkey.entity.UserInfo; import org.maxkey.password.onetimepwd.AbstractOtpAuthn; -import org.maxkey.password.onetimepwd.OtpAuthnService; +import org.maxkey.password.sms.SmsOtpAuthnService; import org.maxkey.web.WebConstants; import org.maxkey.web.WebContext; import org.slf4j.Logger; @@ -46,6 +46,8 @@ public class MobileAuthenticationProvider extends AbstractAuthenticationProvider private static final Logger _logger = LoggerFactory.getLogger(MobileAuthenticationProvider.class); + SmsOtpAuthnService smsOtpAuthnService; + public String getProviderName() { return "mobile" + PROVIDER_SUFFIX; } @@ -59,11 +61,11 @@ public class MobileAuthenticationProvider extends AbstractAuthenticationProvider public MobileAuthenticationProvider( AbstractAuthenticationRealm authenticationRealm, ApplicationConfig applicationConfig, - OtpAuthnService otpAuthnService, + SmsOtpAuthnService smsOtpAuthnService, SessionManager sessionManager) { this.authenticationRealm = authenticationRealm; this.applicationConfig = applicationConfig; - this.otpAuthnService = otpAuthnService; + this.smsOtpAuthnService = smsOtpAuthnService; this.sessionManager = sessionManager; } @@ -136,7 +138,7 @@ public class MobileAuthenticationProvider extends AbstractAuthenticationProvider UserInfo validUserInfo = new UserInfo(); validUserInfo.setUsername(userInfo.getUsername()); validUserInfo.setId(userInfo.getId()); - AbstractOtpAuthn smsOtpAuthn = otpAuthnService.getByInstId(userInfo.getInstId()); + AbstractOtpAuthn smsOtpAuthn = smsOtpAuthnService.getByInstId(userInfo.getInstId()); if (password == null || !smsOtpAuthn.validate(validUserInfo, password)) { String message = WebContext.getI18nValue("login.error.captcha"); _logger.debug("login captcha valid error."); diff --git a/maxkey-authentications/maxkey-authentication-provider/src/main/java/org/maxkey/autoconfigure/AuthnProviderAutoConfiguration.java b/maxkey-authentications/maxkey-authentication-provider/src/main/java/org/maxkey/autoconfigure/AuthnProviderAutoConfiguration.java index 947ab21b7cdb2ba5e53ad688d8b664fdd1759f1f..6b2e37675f4203259531cb5a713ffc897aec18da 100644 --- a/maxkey-authentications/maxkey-authentication-provider/src/main/java/org/maxkey/autoconfigure/AuthnProviderAutoConfiguration.java +++ b/maxkey-authentications/maxkey-authentication-provider/src/main/java/org/maxkey/autoconfigure/AuthnProviderAutoConfiguration.java @@ -28,15 +28,10 @@ import org.maxkey.authn.session.SessionManager; import org.maxkey.authn.support.rememberme.AbstractRemeberMeManager; import org.maxkey.authn.support.rememberme.JdbcRemeberMeManager; import org.maxkey.configuration.ApplicationConfig; -import org.maxkey.constants.ConstsPersistence; -import org.maxkey.password.onetimepwd.OtpAuthnService; -import org.maxkey.password.onetimepwd.token.RedisOtpTokenStore; -import org.maxkey.persistence.redis.RedisConnectionFactory; +import org.maxkey.password.sms.SmsOtpAuthnService; import org.maxkey.persistence.repository.LoginHistoryRepository; import org.maxkey.persistence.repository.LoginRepository; import org.maxkey.persistence.repository.PasswordPolicyValidator; -import org.maxkey.persistence.service.EmailSendersService; -import org.maxkey.persistence.service.SmsProviderService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; @@ -86,14 +81,14 @@ public class AuthnProviderAutoConfiguration implements InitializingBean { public AbstractAuthenticationProvider mobileAuthenticationProvider( AbstractAuthenticationRealm authenticationRealm, ApplicationConfig applicationConfig, - OtpAuthnService otpAuthnService, + SmsOtpAuthnService smsAuthnService, SessionManager sessionManager ) { _logger.debug("init Mobile authentication Provider ."); return new MobileAuthenticationProvider( authenticationRealm, applicationConfig, - otpAuthnService, + smsAuthnService, sessionManager ); } diff --git a/maxkey-authentications/maxkey-authentication-sms/build.gradle b/maxkey-authentications/maxkey-authentication-sms/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..1f56ccf8c9365c6ef1f2cb90691a355fba5495e4 --- /dev/null +++ b/maxkey-authentications/maxkey-authentication-sms/build.gradle @@ -0,0 +1,14 @@ + +description = "maxkey-authentication-sms" + + +dependencies { + //local jars + implementation fileTree(dir: '../maxkey-lib/', include: '*/*.jar') + + implementation project(":maxkey-common") + implementation project(":maxkey-core") + implementation project(":maxkey-persistence") + implementation project(":maxkey-authentications:maxkey-authentication-otp") + +} \ No newline at end of file diff --git a/maxkey-authentications/maxkey-authentication-sms/src/main/java/META-INF/MANIFEST.MF b/maxkey-authentications/maxkey-authentication-sms/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..254272e1c0740423e25eb40be9a98ce1556474b1 --- /dev/null +++ b/maxkey-authentications/maxkey-authentication-sms/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/autoconfigure/SmsAutoConfiguration.java b/maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/autoconfigure/SmsAutoConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..4b2669d6e6046396e0f7bc1ce5932559054830b9 --- /dev/null +++ b/maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/autoconfigure/SmsAutoConfiguration.java @@ -0,0 +1,63 @@ +/* + * Copyright [2022] [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.autoconfigure; + +import org.maxkey.constants.ConstsPersistence; +import org.maxkey.password.onetimepwd.token.RedisOtpTokenStore; +import org.maxkey.password.sms.SmsOtpAuthnService; +import org.maxkey.persistence.redis.RedisConnectionFactory; +import org.maxkey.persistence.service.EmailSendersService; +import org.maxkey.persistence.service.SmsProviderService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.context.annotation.Bean; + + +@AutoConfiguration +public class SmsAutoConfiguration implements InitializingBean { + private static final Logger _logger = + LoggerFactory.getLogger(SmsAutoConfiguration.class); + + + @Bean(name = "smsOtpAuthnService") + public SmsOtpAuthnService smsOtpAuthnService( + @Value("${maxkey.server.persistence}") int persistence, + SmsProviderService smsProviderService, + EmailSendersService emailSendersService, + RedisConnectionFactory redisConnFactory) { + SmsOtpAuthnService smsOtpAuthnService = + new SmsOtpAuthnService(smsProviderService,emailSendersService); + + if (persistence == ConstsPersistence.REDIS) { + RedisOtpTokenStore redisOptTokenStore = new RedisOtpTokenStore(redisConnFactory); + smsOtpAuthnService.setRedisOptTokenStore(redisOptTokenStore); + } + + _logger.debug("SmsOtpAuthnService {} inited." , + persistence == ConstsPersistence.REDIS ? "Redis" : "InMemory"); + return smsOtpAuthnService; + } + + @Override + public void afterPropertiesSet() throws Exception { + + } +} diff --git a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/impl/SmsOtpAuthn.java b/maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/SmsOtpAuthn.java similarity index 97% rename from maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/impl/SmsOtpAuthn.java rename to maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/SmsOtpAuthn.java index d8303d5d5ff64b17e73530b27cfd2e5bdd56311f..a32f124c2d3c2b41b2ea968021def002d34ba4bd 100644 --- a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/impl/SmsOtpAuthn.java +++ b/maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/SmsOtpAuthn.java @@ -15,7 +15,7 @@ */ -package org.maxkey.password.onetimepwd.impl; +package org.maxkey.password.sms; import java.io.IOException; diff --git a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/OtpAuthnService.java b/maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/SmsOtpAuthnService.java similarity index 73% rename from maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/OtpAuthnService.java rename to maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/SmsOtpAuthnService.java index 2847bdbfefc23ef0f31bda7fd0a5709cafe8cbf8..440f421555c7d73caf075e3c316786be4edf8d4c 100644 --- a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/OtpAuthnService.java +++ b/maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/SmsOtpAuthnService.java @@ -15,7 +15,7 @@ */ -package org.maxkey.password.onetimepwd; +package org.maxkey.password.sms; import java.sql.Types; import java.util.concurrent.TimeUnit; @@ -25,20 +25,21 @@ import org.maxkey.constants.ConstsBoolean; import org.maxkey.crypto.password.PasswordReciprocal; import org.maxkey.entity.EmailSenders; import org.maxkey.entity.SmsProvider; +import org.maxkey.password.onetimepwd.AbstractOtpAuthn; import org.maxkey.password.onetimepwd.impl.MailOtpAuthn; -import org.maxkey.password.onetimepwd.impl.sms.SmsOtpAuthnAliyun; -import org.maxkey.password.onetimepwd.impl.sms.SmsOtpAuthnTencentCloud; -import org.maxkey.password.onetimepwd.impl.sms.SmsOtpAuthnYunxin; import org.maxkey.password.onetimepwd.token.RedisOtpTokenStore; +import org.maxkey.password.sms.impl.SmsOtpAuthnAliyun; +import org.maxkey.password.sms.impl.SmsOtpAuthnTencentCloud; +import org.maxkey.password.sms.impl.SmsOtpAuthnYunxin; import org.maxkey.persistence.service.EmailSendersService; import org.maxkey.persistence.service.SmsProviderService; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; -public class OtpAuthnService { +public class SmsOtpAuthnService { - protected static final Cache otpAuthnStore = + protected static final Cache smsAuthnStore = Caffeine.newBuilder() .expireAfterWrite(60, TimeUnit.MINUTES) .build(); @@ -49,18 +50,19 @@ public class OtpAuthnService { RedisOtpTokenStore redisOptTokenStore; - public OtpAuthnService(SmsProviderService smsProviderService, EmailSendersService emailSendersService) { + public SmsOtpAuthnService(SmsProviderService smsProviderService, EmailSendersService emailSendersService) { this.smsProviderService = smsProviderService; this.emailSendersService = emailSendersService; } - public OtpAuthnService(SmsProviderService smsProviderService,RedisOtpTokenStore redisOptTokenStore) { + public SmsOtpAuthnService(SmsProviderService smsProviderService,EmailSendersService emailSendersService,RedisOtpTokenStore redisOptTokenStore) { this.smsProviderService = smsProviderService; + this.emailSendersService = emailSendersService; this.redisOptTokenStore = redisOptTokenStore; } public AbstractOtpAuthn getByInstId(String instId) { - AbstractOtpAuthn otpAuthn = otpAuthnStore.getIfPresent(instId); + AbstractOtpAuthn otpAuthn = smsAuthnStore.getIfPresent(instId); if(otpAuthn == null) { SmsProvider smsProvider = smsProviderService.findOne("where instid = ? ", new Object[]{instId}, new int[]{Types.VARCHAR}); @@ -119,37 +121,11 @@ public class OtpAuthnService { otpAuthn = mailOtpAuthn; } - otpAuthnStore.put(instId, otpAuthn); + smsAuthnStore.put(instId, otpAuthn); } } return otpAuthn; } - - public AbstractOtpAuthn getMailOtpAuthn(String instId) { - AbstractOtpAuthn otpAuthn = otpAuthnStore.getIfPresent(instId); - if(otpAuthn == null) { - EmailSenders emailSender = - emailSendersService.findOne("where instid = ? ", new Object[]{instId}, new int[]{Types.VARCHAR}); - - String credentials = PasswordReciprocal.getInstance().decoder(emailSender.getCredentials()); - EmailConfig emailConfig = - new EmailConfig( - emailSender.getAccount(), - credentials, - emailSender.getSmtpHost(), - emailSender.getPort(), - ConstsBoolean.isTrue(emailSender.getSslSwitch()), - emailSender.getSender()); - MailOtpAuthn mailOtpAuthn = new MailOtpAuthn(emailConfig); - mailOtpAuthn.setInterval(60 * 5);//5 minute - if(redisOptTokenStore != null) { - mailOtpAuthn.setOptTokenStore(redisOptTokenStore); - } - otpAuthn = mailOtpAuthn; - } - otpAuthnStore.put(instId, otpAuthn); - return otpAuthn; - } public void setRedisOptTokenStore(RedisOtpTokenStore redisOptTokenStore) { this.redisOptTokenStore = redisOptTokenStore; diff --git a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/impl/sms/SmsOtpAuthnAliyun.java b/maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/impl/SmsOtpAuthnAliyun.java similarity index 97% rename from maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/impl/sms/SmsOtpAuthnAliyun.java rename to maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/impl/SmsOtpAuthnAliyun.java index f401673fc5112d303a8ffe903870e78cae5c1606..b030028e51b030548d459051b5ec1479e3bd9842 100644 --- a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/impl/sms/SmsOtpAuthnAliyun.java +++ b/maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/impl/SmsOtpAuthnAliyun.java @@ -15,7 +15,7 @@ */ -package org.maxkey.password.onetimepwd.impl.sms; +package org.maxkey.password.sms.impl; import com.aliyuncs.CommonRequest; import com.aliyuncs.CommonResponse; @@ -25,7 +25,7 @@ import com.aliyuncs.http.MethodType; import com.aliyuncs.profile.DefaultProfile; import org.maxkey.entity.UserInfo; -import org.maxkey.password.onetimepwd.impl.SmsOtpAuthn; +import org.maxkey.password.sms.SmsOtpAuthn; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/impl/sms/SmsOtpAuthnTencentCloud.java b/maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/impl/SmsOtpAuthnTencentCloud.java similarity index 97% rename from maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/impl/sms/SmsOtpAuthnTencentCloud.java rename to maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/impl/SmsOtpAuthnTencentCloud.java index 7c60260fb086b23ab5216a5b9864f9b5eae78442..8eb0417b44bcd00c7705f689fefaad8e4fc7c578 100644 --- a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/impl/sms/SmsOtpAuthnTencentCloud.java +++ b/maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/impl/SmsOtpAuthnTencentCloud.java @@ -15,7 +15,7 @@ */ -package org.maxkey.password.onetimepwd.impl.sms; +package org.maxkey.password.sms.impl; import com.tencentcloudapi.common.Credential; import com.tencentcloudapi.common.profile.ClientProfile; @@ -25,7 +25,7 @@ import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest; import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse; import org.maxkey.entity.UserInfo; -import org.maxkey.password.onetimepwd.impl.SmsOtpAuthn; +import org.maxkey.password.sms.SmsOtpAuthn; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/impl/sms/SmsOtpAuthnYunxin.java b/maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/impl/SmsOtpAuthnYunxin.java similarity index 98% rename from maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/impl/sms/SmsOtpAuthnYunxin.java rename to maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/impl/SmsOtpAuthnYunxin.java index bf82ecdef833564341ee386e56fdea63f0338cd3..ecc3c2be168a5ce8bf136281f48619558808e35d 100644 --- a/maxkey-authentications/maxkey-authentication-otp/src/main/java/org/maxkey/password/onetimepwd/impl/sms/SmsOtpAuthnYunxin.java +++ b/maxkey-authentications/maxkey-authentication-sms/src/main/java/org/maxkey/password/sms/impl/SmsOtpAuthnYunxin.java @@ -15,7 +15,7 @@ */ -package org.maxkey.password.onetimepwd.impl.sms; +package org.maxkey.password.sms.impl; import java.security.MessageDigest; import java.util.ArrayList; @@ -30,7 +30,7 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import org.maxkey.entity.UserInfo; -import org.maxkey.password.onetimepwd.impl.SmsOtpAuthn; +import org.maxkey.password.sms.SmsOtpAuthn; import org.maxkey.util.JsonUtils; import org.maxkey.util.StringGenerator; import org.slf4j.Logger; diff --git a/maxkey-webs/maxkey-web-maxkey/build.gradle b/maxkey-webs/maxkey-web-maxkey/build.gradle index 54c9b478efb0e238edf19ce4f9d470b4c9c1450b..56173a66e5e08b03c2eb01ba00faf036647b1a65 100644 --- a/maxkey-webs/maxkey-web-maxkey/build.gradle +++ b/maxkey-webs/maxkey-web-maxkey/build.gradle @@ -13,6 +13,7 @@ dependencies { implementation project(":maxkey-authentications:maxkey-authentication-captcha") implementation project(":maxkey-authentications:maxkey-authentication-otp") implementation project(":maxkey-authentications:maxkey-authentication-provider") + implementation project(":maxkey-authentications:maxkey-authentication-sms") implementation project(":maxkey-protocols:maxkey-protocol-authorize") implementation project(":maxkey-protocols:maxkey-protocol-cas") diff --git a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/autoconfigure/MaxKeyConfig.java b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/autoconfigure/MaxKeyConfig.java index 70e39688dff774348331cd67030fd375903899de..e5c45a4772484fe507f2cf5b473826633df1fbf2 100644 --- a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/autoconfigure/MaxKeyConfig.java +++ b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/autoconfigure/MaxKeyConfig.java @@ -31,7 +31,7 @@ import org.maxkey.authn.support.kerberos.RemoteKerberosService; import org.maxkey.configuration.EmailConfig; import org.maxkey.constants.ConstsPersistence; import org.maxkey.password.onetimepwd.AbstractOtpAuthn; -import org.maxkey.password.onetimepwd.OtpAuthnService; +import org.maxkey.password.onetimepwd.MailOtpAuthnService; import org.maxkey.password.onetimepwd.algorithm.OtpKeyUriFormat; import org.maxkey.password.onetimepwd.impl.MailOtpAuthn; import org.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn; @@ -104,7 +104,7 @@ public class MaxKeyConfig implements InitializingBean { LoginHistoryRepository loginHistoryService, UserInfoService userInfoService, JdbcTemplate jdbcTemplate, - OtpAuthnService otpAuthnService, + MailOtpAuthnService otpAuthnService, LdapContextService ldapContextService) { LdapAuthenticationRealmService ldapRealmService = new LdapAuthenticationRealmService(ldapContextService); JdbcAuthenticationRealm authenticationRealm = new JdbcAuthenticationRealm( diff --git a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ForgotPasswordContorller.java b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ForgotPasswordContorller.java index a94de9933ec699cd9cbeec7bed9e9723e29fee4b..136f2b400bfa477e280b91d534c0907d7e68e89d 100644 --- a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ForgotPasswordContorller.java +++ b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ForgotPasswordContorller.java @@ -26,12 +26,12 @@ import org.maxkey.entity.ChangePassword; import org.maxkey.entity.Message; import org.maxkey.entity.UserInfo; import org.maxkey.password.onetimepwd.AbstractOtpAuthn; -import org.maxkey.password.onetimepwd.OtpAuthnService; +import org.maxkey.password.onetimepwd.MailOtpAuthnService; +import org.maxkey.password.sms.SmsOtpAuthnService; import org.maxkey.persistence.service.UserInfoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; @@ -74,8 +74,10 @@ public class ForgotPasswordContorller { UserInfoService userInfoService; @Autowired - @Qualifier("otpAuthnService") - OtpAuthnService otpAuthnService; + MailOtpAuthnService mailOtpAuthnService; + + @Autowired + SmsOtpAuthnService smsOtpAuthnService; @@ -100,7 +102,7 @@ public class ForgotPasswordContorller { if(userInfo != null) { change = new ChangePassword(userInfo); change.clearPassword(); - AbstractOtpAuthn smsOtpAuthn = otpAuthnService.getByInstId(userInfo.getInstId()); + AbstractOtpAuthn smsOtpAuthn = smsOtpAuthnService.getByInstId(userInfo.getInstId()); smsOtpAuthn.produce(userInfo); return new Message(change).buildResponse(); } @@ -127,7 +129,7 @@ public class ForgotPasswordContorller { if(userInfo != null) { change = new ChangePassword(userInfo); change.clearPassword(); - AbstractOtpAuthn mailOtpAuthn = otpAuthnService.getMailOtpAuthn(userInfo.getInstId()); + AbstractOtpAuthn mailOtpAuthn = mailOtpAuthnService.getMailOtpAuthn(userInfo.getInstId()); mailOtpAuthn.produce(userInfo); return new Message(change).buildResponse(); } @@ -146,8 +148,8 @@ public class ForgotPasswordContorller { && changePassword.getPassword().equals(changePassword.getConfirmPassword())) { UserInfo loadedUserInfo = userInfoService.get(changePassword.getUserId()); if(loadedUserInfo != null) { - AbstractOtpAuthn smsOtpAuthn = otpAuthnService.getByInstId(loadedUserInfo.getInstId()); - AbstractOtpAuthn mailOtpAuthn = otpAuthnService.getMailOtpAuthn(loadedUserInfo.getInstId()); + AbstractOtpAuthn smsOtpAuthn = smsOtpAuthnService.getByInstId(loadedUserInfo.getInstId()); + AbstractOtpAuthn mailOtpAuthn = mailOtpAuthnService.getMailOtpAuthn(loadedUserInfo.getInstId()); if ( (forgotType.equalsIgnoreCase("email") && mailOtpAuthn !=null diff --git a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/LoginEntryPoint.java b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/LoginEntryPoint.java index d5f740849af58f5c5ced170940bf542794abc510..c149e67412a80d40f597c1797c9c5c4ae3d78f53 100644 --- a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/LoginEntryPoint.java +++ b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/LoginEntryPoint.java @@ -38,7 +38,8 @@ import org.maxkey.entity.Institutions; import org.maxkey.entity.Message; import org.maxkey.entity.UserInfo; import org.maxkey.password.onetimepwd.AbstractOtpAuthn; -import org.maxkey.password.onetimepwd.OtpAuthnService; +import org.maxkey.password.onetimepwd.MailOtpAuthnService; +import org.maxkey.password.sms.SmsOtpAuthnService; import org.maxkey.persistence.service.UserInfoService; import org.maxkey.web.WebConstants; import org.maxkey.web.WebContext; @@ -91,7 +92,9 @@ public class LoginEntryPoint { AbstractOtpAuthn tfaOtpAuthn; @Autowired - OtpAuthnService otpAuthnService; + SmsOtpAuthnService smsAuthnService; + + @Autowired AbstractRemeberMeManager remeberMeManager; @@ -156,7 +159,7 @@ public class LoginEntryPoint { public ResponseEntity produceOtp(@PathVariable("mobile") String mobile) { UserInfo userInfo=userInfoService.findByEmailMobile(mobile); if(userInfo != null) { - otpAuthnService.getByInstId(WebContext.getInst().getId()).produce(userInfo); + smsAuthnService.getByInstId(WebContext.getInst().getId()).produce(userInfo); return new Message(Message.SUCCESS).buildResponse(); } diff --git a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/RegisterController.java b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/RegisterController.java index b221e83846bc07f912d0aea5956941ee670551d4..f929440281004207849c1d6e673a4e4700798511 100644 --- a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/RegisterController.java +++ b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/RegisterController.java @@ -29,14 +29,13 @@ import org.maxkey.crypto.password.PasswordReciprocal; import org.maxkey.entity.Message; import org.maxkey.entity.UserInfo; import org.maxkey.password.onetimepwd.AbstractOtpAuthn; -import org.maxkey.password.onetimepwd.OtpAuthnService; +import org.maxkey.password.sms.SmsOtpAuthnService; import org.maxkey.persistence.service.UserInfoService; import org.maxkey.util.StringUtils; import org.maxkey.web.WebContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.crypto.password.PasswordEncoder; @@ -64,8 +63,7 @@ public class RegisterController { private UserInfoService userInfoService; @Autowired - @Qualifier("otpAuthnService") - OtpAuthnService otpAuthnService; + SmsOtpAuthnService smsOtpAuthnService; @Autowired private PasswordEncoder passwordEncoder; @@ -81,7 +79,7 @@ public class RegisterController { UserInfo userInfo = new UserInfo(); userInfo.setUsername(mobile); userInfo.setMobile(mobile); - AbstractOtpAuthn smsOtpAuthn = otpAuthnService.getByInstId(WebContext.getInst().getId()); + AbstractOtpAuthn smsOtpAuthn = smsOtpAuthnService.getByInstId(WebContext.getInst().getId()); smsOtpAuthn.produce(userInfo); return new Message(userInfo).buildResponse(); } @@ -98,7 +96,7 @@ public class RegisterController { UserInfo validateUserInfo = new UserInfo(); validateUserInfo.setUsername(userInfo.getMobile()); validateUserInfo.setMobile(userInfo.getMobile()); - AbstractOtpAuthn smsOtpAuthn = otpAuthnService.getByInstId(WebContext.getInst().getId()); + AbstractOtpAuthn smsOtpAuthn = smsOtpAuthnService.getByInstId(WebContext.getInst().getId()); if (smsOtpAuthn !=null && smsOtpAuthn.validate(validateUserInfo, captcha)){ UserInfo temp = userInfoService.findByEmailMobile(userInfo.getEmail()); diff --git a/maxkey-webs/maxkey-web-maxkey/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/maxkey-webs/maxkey-web-maxkey/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 2755ed3d6323416082315b580b55370d3201973b..8d6505cae0aeddd402ae8d3f6893d9bac22d22eb 100644 --- a/maxkey-webs/maxkey-web-maxkey/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/maxkey-webs/maxkey-web-maxkey/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -5,6 +5,7 @@ org.maxkey.autoconfigure.RedisAutoConfiguration org.maxkey.autoconfigure.AuthnProviderAutoConfiguration org.maxkey.autoconfigure.JwtAuthnAutoConfiguration org.maxkey.autoconfigure.OneTimePasswordAutoConfiguration +org.maxkey.autoconfigure.SmsAutoConfiguration org.maxkey.autoconfigure.SessionAutoConfiguration org.maxkey.autoconfigure.TokenAutoConfiguration org.maxkey.autoconfigure.CasAutoConfiguration diff --git a/maxkey-webs/maxkey-web-mgt/build.gradle b/maxkey-webs/maxkey-web-mgt/build.gradle index fd30a4ad11b07e8daa5bafd1d879d747d32cccf0..e56e00e580d97f71dbacc3b24426808a95c39892 100644 --- a/maxkey-webs/maxkey-web-mgt/build.gradle +++ b/maxkey-webs/maxkey-web-mgt/build.gradle @@ -12,6 +12,7 @@ dependencies { implementation project(":maxkey-authentications:maxkey-authentication-captcha") implementation project(":maxkey-authentications:maxkey-authentication-otp") implementation project(":maxkey-authentications:maxkey-authentication-provider") + implementation project(":maxkey-authentications:maxkey-authentication-sms") implementation project(":maxkey-protocols:maxkey-protocol-oauth-2.0") implementation project(":maxkey-protocols:maxkey-protocol-saml-2.0") diff --git a/maxkey-webs/maxkey-web-mgt/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/maxkey-webs/maxkey-web-mgt/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 6259387255de51826e2c17e253f6aa4095ab1e24..9d75f0666bf45ede7fc501eafa2d34b377fe9bab 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/maxkey-webs/maxkey-web-mgt/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -5,6 +5,7 @@ org.maxkey.autoconfigure.JwtAuthnAutoConfiguration org.maxkey.autoconfigure.RedisAutoConfiguration org.maxkey.autoconfigure.AuthnProviderAutoConfiguration org.maxkey.autoconfigure.OneTimePasswordAutoConfiguration +org.maxkey.autoconfigure.SmsAutoConfiguration org.maxkey.autoconfigure.SessionAutoConfiguration org.maxkey.autoconfigure.TokenAutoConfiguration org.maxkey.autoconfigure.SynchronizerAutoConfiguration diff --git a/settings.gradle b/settings.gradle index 5fc48c056fd23e49b07d7fbbfe9fa1f2fca4fc33..a5fcd0455c066c3a1968afebef97fc0592cd7f37 100644 --- a/settings.gradle +++ b/settings.gradle @@ -31,6 +31,7 @@ include ( 'maxkey-authentications:maxkey-authentication-social', 'maxkey-authentications:maxkey-authentication-otp', 'maxkey-authentications:maxkey-authentication-provider', + 'maxkey-authentications:maxkey-authentication-sms', //identity 'maxkey-identitys:maxkey-identity-scim', 'maxkey-identitys:maxkey-identity-rest',