split maxkey-authentication-sms
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<String, AbstractOtpAuthn> 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package org.maxkey.password.onetimepwd.impl;
|
||||
package org.maxkey.password.sms;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -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<String, AbstractOtpAuthn> otpAuthnStore =
|
||||
protected static final Cache<String, AbstractOtpAuthn> 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,38 +121,12 @@ 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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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")
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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<ChangePassword>(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<ChangePassword>(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
|
||||
|
||||
@@ -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<AuthJwt>(Message.SUCCESS).buildResponse();
|
||||
}
|
||||
|
||||
|
||||
@@ -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>(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());
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user