mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-06 17:08:29 +08:00
整合LoginHistoryRepository 到 HistoryLoginService
This commit is contained in:
parent
9e20e02ead
commit
f19e92e2dc
@ -28,9 +28,9 @@ import org.dromara.maxkey.entity.idm.Groups;
|
|||||||
import org.dromara.maxkey.entity.idm.UserInfo;
|
import org.dromara.maxkey.entity.idm.UserInfo;
|
||||||
import org.dromara.maxkey.ip2location.IpLocationParser;
|
import org.dromara.maxkey.ip2location.IpLocationParser;
|
||||||
import org.dromara.maxkey.ip2location.Region;
|
import org.dromara.maxkey.ip2location.Region;
|
||||||
import org.dromara.maxkey.persistence.repository.LoginHistoryRepository;
|
|
||||||
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
||||||
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
||||||
|
import org.dromara.maxkey.persistence.service.HistoryLoginService;
|
||||||
import org.dromara.maxkey.persistence.service.UserInfoService;
|
import org.dromara.maxkey.persistence.service.UserInfoService;
|
||||||
import org.dromara.maxkey.web.WebConstants;
|
import org.dromara.maxkey.web.WebConstants;
|
||||||
import org.dromara.maxkey.web.WebContext;
|
import org.dromara.maxkey.web.WebContext;
|
||||||
@ -54,7 +54,7 @@ public abstract class AbstractAuthenticationRealm {
|
|||||||
|
|
||||||
protected LoginRepository loginRepository;
|
protected LoginRepository loginRepository;
|
||||||
|
|
||||||
protected LoginHistoryRepository loginHistoryRepository;
|
protected HistoryLoginService historyLoginService;
|
||||||
|
|
||||||
protected UserInfoService userInfoService;
|
protected UserInfoService userInfoService;
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ public abstract class AbstractAuthenticationRealm {
|
|||||||
historyLogin.setCity(ipRegion.getCity());
|
historyLogin.setCity(ipRegion.getCity());
|
||||||
historyLogin.setLocation(ipRegion.getAddr());
|
historyLogin.setLocation(ipRegion.getAddr());
|
||||||
}
|
}
|
||||||
loginHistoryRepository.login(historyLogin);
|
historyLoginService.login(historyLogin);
|
||||||
|
|
||||||
loginRepository.updateLastLogin(userInfo);
|
loginRepository.updateLastLogin(userInfo);
|
||||||
|
|
||||||
|
|||||||
@ -26,9 +26,9 @@ import org.dromara.maxkey.entity.ChangePassword;
|
|||||||
import org.dromara.maxkey.entity.cnf.CnfPasswordPolicy;
|
import org.dromara.maxkey.entity.cnf.CnfPasswordPolicy;
|
||||||
import org.dromara.maxkey.entity.idm.UserInfo;
|
import org.dromara.maxkey.entity.idm.UserInfo;
|
||||||
import org.dromara.maxkey.ip2location.IpLocationParser;
|
import org.dromara.maxkey.ip2location.IpLocationParser;
|
||||||
import org.dromara.maxkey.persistence.repository.LoginHistoryRepository;
|
|
||||||
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
||||||
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
||||||
|
import org.dromara.maxkey.persistence.service.HistoryLoginService;
|
||||||
import org.dromara.maxkey.persistence.service.UserInfoService;
|
import org.dromara.maxkey.persistence.service.UserInfoService;
|
||||||
import org.dromara.maxkey.web.WebConstants;
|
import org.dromara.maxkey.web.WebConstants;
|
||||||
import org.dromara.maxkey.web.WebContext;
|
import org.dromara.maxkey.web.WebContext;
|
||||||
@ -60,7 +60,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
|
|||||||
PasswordEncoder passwordEncoder,
|
PasswordEncoder passwordEncoder,
|
||||||
PasswordPolicyValidator passwordPolicyValidator,
|
PasswordPolicyValidator passwordPolicyValidator,
|
||||||
LoginRepository loginRepository,
|
LoginRepository loginRepository,
|
||||||
LoginHistoryRepository loginHistoryRepository,
|
HistoryLoginService historyLoginService,
|
||||||
UserInfoService userInfoService,
|
UserInfoService userInfoService,
|
||||||
IpLocationParser ipLocationParser,
|
IpLocationParser ipLocationParser,
|
||||||
JdbcTemplate jdbcTemplate) {
|
JdbcTemplate jdbcTemplate) {
|
||||||
@ -68,7 +68,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
|
|||||||
this.passwordEncoder =passwordEncoder;
|
this.passwordEncoder =passwordEncoder;
|
||||||
this.passwordPolicyValidator=passwordPolicyValidator;
|
this.passwordPolicyValidator=passwordPolicyValidator;
|
||||||
this.loginRepository = loginRepository;
|
this.loginRepository = loginRepository;
|
||||||
this.loginHistoryRepository = loginHistoryRepository;
|
this.historyLoginService = historyLoginService;
|
||||||
this.userInfoService = userInfoService;
|
this.userInfoService = userInfoService;
|
||||||
this.ipLocationParser = ipLocationParser;
|
this.ipLocationParser = ipLocationParser;
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
@ -78,7 +78,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
|
|||||||
PasswordEncoder passwordEncoder,
|
PasswordEncoder passwordEncoder,
|
||||||
PasswordPolicyValidator passwordPolicyValidator,
|
PasswordPolicyValidator passwordPolicyValidator,
|
||||||
LoginRepository loginRepository,
|
LoginRepository loginRepository,
|
||||||
LoginHistoryRepository loginHistoryRepository,
|
HistoryLoginService historyLoginService,
|
||||||
UserInfoService userInfoService,
|
UserInfoService userInfoService,
|
||||||
IpLocationParser ipLocationParser,
|
IpLocationParser ipLocationParser,
|
||||||
JdbcTemplate jdbcTemplate,
|
JdbcTemplate jdbcTemplate,
|
||||||
@ -86,7 +86,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
|
|||||||
this.passwordEncoder = passwordEncoder;
|
this.passwordEncoder = passwordEncoder;
|
||||||
this.passwordPolicyValidator = passwordPolicyValidator;
|
this.passwordPolicyValidator = passwordPolicyValidator;
|
||||||
this.loginRepository = loginRepository;
|
this.loginRepository = loginRepository;
|
||||||
this.loginHistoryRepository = loginHistoryRepository;
|
this.historyLoginService = historyLoginService;
|
||||||
this.userInfoService = userInfoService;
|
this.userInfoService = userInfoService;
|
||||||
this.ipLocationParser = ipLocationParser;
|
this.ipLocationParser = ipLocationParser;
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
|||||||
@ -25,7 +25,6 @@ import org.dromara.maxkey.authn.realm.AbstractAuthenticationRealm;
|
|||||||
import org.dromara.maxkey.authn.session.SessionManager;
|
import org.dromara.maxkey.authn.session.SessionManager;
|
||||||
import org.dromara.maxkey.configuration.ApplicationConfig;
|
import org.dromara.maxkey.configuration.ApplicationConfig;
|
||||||
import org.dromara.maxkey.password.sms.SmsOtpAuthnService;
|
import org.dromara.maxkey.password.sms.SmsOtpAuthnService;
|
||||||
import org.dromara.maxkey.persistence.repository.LoginHistoryRepository;
|
|
||||||
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
||||||
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -109,9 +108,4 @@ public class AuthnProviderAutoConfiguration {
|
|||||||
return new LoginRepository(jdbcTemplate);
|
return new LoginRepository(jdbcTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
LoginHistoryRepository loginHistoryRepository(JdbcTemplate jdbcTemplate) {
|
|
||||||
return new LoginHistoryRepository(jdbcTemplate);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,9 +28,9 @@ import org.dromara.maxkey.entity.idm.Groups;
|
|||||||
import org.dromara.maxkey.entity.idm.UserInfo;
|
import org.dromara.maxkey.entity.idm.UserInfo;
|
||||||
import org.dromara.maxkey.ip2location.IpLocationParser;
|
import org.dromara.maxkey.ip2location.IpLocationParser;
|
||||||
import org.dromara.maxkey.ip2location.Region;
|
import org.dromara.maxkey.ip2location.Region;
|
||||||
import org.dromara.maxkey.persistence.repository.LoginHistoryRepository;
|
|
||||||
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
||||||
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
||||||
|
import org.dromara.maxkey.persistence.service.HistoryLoginService;
|
||||||
import org.dromara.maxkey.persistence.service.UserInfoService;
|
import org.dromara.maxkey.persistence.service.UserInfoService;
|
||||||
import org.dromara.maxkey.web.WebConstants;
|
import org.dromara.maxkey.web.WebConstants;
|
||||||
import org.dromara.maxkey.web.WebContext;
|
import org.dromara.maxkey.web.WebContext;
|
||||||
@ -54,7 +54,7 @@ public abstract class AbstractAuthenticationRealm {
|
|||||||
|
|
||||||
protected LoginRepository loginRepository;
|
protected LoginRepository loginRepository;
|
||||||
|
|
||||||
protected LoginHistoryRepository loginHistoryRepository;
|
protected HistoryLoginService historyLoginService;
|
||||||
|
|
||||||
protected UserInfoService userInfoService;
|
protected UserInfoService userInfoService;
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ public abstract class AbstractAuthenticationRealm {
|
|||||||
historyLogin.setCity(ipRegion.getCity());
|
historyLogin.setCity(ipRegion.getCity());
|
||||||
historyLogin.setLocation(ipRegion.getAddr());
|
historyLogin.setLocation(ipRegion.getAddr());
|
||||||
}
|
}
|
||||||
loginHistoryRepository.login(historyLogin);
|
historyLoginService.login(historyLogin);
|
||||||
|
|
||||||
loginRepository.updateLastLogin(userInfo);
|
loginRepository.updateLastLogin(userInfo);
|
||||||
|
|
||||||
|
|||||||
@ -26,9 +26,9 @@ import org.dromara.maxkey.entity.ChangePassword;
|
|||||||
import org.dromara.maxkey.entity.cnf.CnfPasswordPolicy;
|
import org.dromara.maxkey.entity.cnf.CnfPasswordPolicy;
|
||||||
import org.dromara.maxkey.entity.idm.UserInfo;
|
import org.dromara.maxkey.entity.idm.UserInfo;
|
||||||
import org.dromara.maxkey.ip2location.IpLocationParser;
|
import org.dromara.maxkey.ip2location.IpLocationParser;
|
||||||
import org.dromara.maxkey.persistence.repository.LoginHistoryRepository;
|
|
||||||
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
||||||
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
||||||
|
import org.dromara.maxkey.persistence.service.HistoryLoginService;
|
||||||
import org.dromara.maxkey.persistence.service.UserInfoService;
|
import org.dromara.maxkey.persistence.service.UserInfoService;
|
||||||
import org.dromara.maxkey.web.WebConstants;
|
import org.dromara.maxkey.web.WebConstants;
|
||||||
import org.dromara.maxkey.web.WebContext;
|
import org.dromara.maxkey.web.WebContext;
|
||||||
@ -60,7 +60,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
|
|||||||
PasswordEncoder passwordEncoder,
|
PasswordEncoder passwordEncoder,
|
||||||
PasswordPolicyValidator passwordPolicyValidator,
|
PasswordPolicyValidator passwordPolicyValidator,
|
||||||
LoginRepository loginRepository,
|
LoginRepository loginRepository,
|
||||||
LoginHistoryRepository loginHistoryRepository,
|
HistoryLoginService historyLoginService,
|
||||||
UserInfoService userInfoService,
|
UserInfoService userInfoService,
|
||||||
IpLocationParser ipLocationParser,
|
IpLocationParser ipLocationParser,
|
||||||
JdbcTemplate jdbcTemplate) {
|
JdbcTemplate jdbcTemplate) {
|
||||||
@ -68,7 +68,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
|
|||||||
this.passwordEncoder =passwordEncoder;
|
this.passwordEncoder =passwordEncoder;
|
||||||
this.passwordPolicyValidator=passwordPolicyValidator;
|
this.passwordPolicyValidator=passwordPolicyValidator;
|
||||||
this.loginRepository = loginRepository;
|
this.loginRepository = loginRepository;
|
||||||
this.loginHistoryRepository = loginHistoryRepository;
|
this.historyLoginService = historyLoginService;
|
||||||
this.userInfoService = userInfoService;
|
this.userInfoService = userInfoService;
|
||||||
this.ipLocationParser = ipLocationParser;
|
this.ipLocationParser = ipLocationParser;
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
@ -78,7 +78,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
|
|||||||
PasswordEncoder passwordEncoder,
|
PasswordEncoder passwordEncoder,
|
||||||
PasswordPolicyValidator passwordPolicyValidator,
|
PasswordPolicyValidator passwordPolicyValidator,
|
||||||
LoginRepository loginRepository,
|
LoginRepository loginRepository,
|
||||||
LoginHistoryRepository loginHistoryRepository,
|
HistoryLoginService historyLoginService,
|
||||||
UserInfoService userInfoService,
|
UserInfoService userInfoService,
|
||||||
IpLocationParser ipLocationParser,
|
IpLocationParser ipLocationParser,
|
||||||
JdbcTemplate jdbcTemplate,
|
JdbcTemplate jdbcTemplate,
|
||||||
@ -86,7 +86,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
|
|||||||
this.passwordEncoder = passwordEncoder;
|
this.passwordEncoder = passwordEncoder;
|
||||||
this.passwordPolicyValidator = passwordPolicyValidator;
|
this.passwordPolicyValidator = passwordPolicyValidator;
|
||||||
this.loginRepository = loginRepository;
|
this.loginRepository = loginRepository;
|
||||||
this.loginHistoryRepository = loginHistoryRepository;
|
this.historyLoginService = historyLoginService;
|
||||||
this.userInfoService = userInfoService;
|
this.userInfoService = userInfoService;
|
||||||
this.ipLocationParser = ipLocationParser;
|
this.ipLocationParser = ipLocationParser;
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
|||||||
@ -27,7 +27,6 @@ import org.dromara.maxkey.authn.support.rememberme.AbstractRemeberMeManager;
|
|||||||
import org.dromara.maxkey.authn.support.rememberme.JdbcRemeberMeManager;
|
import org.dromara.maxkey.authn.support.rememberme.JdbcRemeberMeManager;
|
||||||
import org.dromara.maxkey.configuration.ApplicationConfig;
|
import org.dromara.maxkey.configuration.ApplicationConfig;
|
||||||
import org.dromara.maxkey.password.sms.SmsOtpAuthnService;
|
import org.dromara.maxkey.password.sms.SmsOtpAuthnService;
|
||||||
import org.dromara.maxkey.persistence.repository.LoginHistoryRepository;
|
|
||||||
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
||||||
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -143,11 +142,6 @@ public class AuthnProviderAutoConfiguration {
|
|||||||
return new LoginRepository(jdbcTemplate);
|
return new LoginRepository(jdbcTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
LoginHistoryRepository loginHistoryRepository(JdbcTemplate jdbcTemplate) {
|
|
||||||
return new LoginHistoryRepository(jdbcTemplate);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remeberMeService .
|
* remeberMeService .
|
||||||
* @return
|
* @return
|
||||||
|
|||||||
@ -1,136 +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.persistence.repository;
|
|
||||||
|
|
||||||
import java.sql.Types;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.dromara.maxkey.entity.history.HistoryLogin;
|
|
||||||
import org.dromara.maxkey.web.WebContext;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
|
|
||||||
public class LoginHistoryRepository {
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(LoginHistoryRepository.class);
|
|
||||||
|
|
||||||
private static final String HISTORY_LOGIN_INSERT_STATEMENT = """
|
|
||||||
insert into mxk_history_login
|
|
||||||
( id ,
|
|
||||||
sessionid ,
|
|
||||||
category ,
|
|
||||||
userid ,
|
|
||||||
username ,
|
|
||||||
displayname ,
|
|
||||||
logintype ,
|
|
||||||
message ,
|
|
||||||
code ,
|
|
||||||
provider ,
|
|
||||||
sourceip ,
|
|
||||||
country ,
|
|
||||||
province ,
|
|
||||||
city ,
|
|
||||||
location ,
|
|
||||||
browser ,
|
|
||||||
platform ,
|
|
||||||
application ,
|
|
||||||
sessionstatus ,
|
|
||||||
instid)
|
|
||||||
values( ? , ? , ? , ? , ? , ? , ? , ?, ? , ? , ? , ?, ?, ? , ? , ?, ? , ? , ? , ?)
|
|
||||||
""";
|
|
||||||
|
|
||||||
protected JdbcTemplate jdbcTemplate;
|
|
||||||
|
|
||||||
public LoginHistoryRepository(JdbcTemplate jdbcTemplate) {
|
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void login(HistoryLogin historyLogin) {
|
|
||||||
historyLogin.setId(WebContext.genId());
|
|
||||||
if(StringUtils.isBlank(historyLogin.getInstId())) {
|
|
||||||
historyLogin.setInstId("1");
|
|
||||||
}
|
|
||||||
//Thread insert
|
|
||||||
new Thread(new HistoryLoginRunnable(jdbcTemplate,historyLogin)).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class HistoryLoginRunnable implements Runnable{
|
|
||||||
|
|
||||||
JdbcTemplate jdbcTemplate;
|
|
||||||
|
|
||||||
HistoryLogin historyLogin;
|
|
||||||
|
|
||||||
public HistoryLoginRunnable(JdbcTemplate jdbcTemplate, HistoryLogin historyLogin) {
|
|
||||||
super();
|
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
|
||||||
this.historyLogin = historyLogin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
logger.debug("History Login {}" , historyLogin);
|
|
||||||
|
|
||||||
jdbcTemplate.update(HISTORY_LOGIN_INSERT_STATEMENT,
|
|
||||||
new Object[] {
|
|
||||||
historyLogin.getId(),
|
|
||||||
historyLogin.getSessionId(),
|
|
||||||
historyLogin.getCategory(),
|
|
||||||
historyLogin.getUserId(),
|
|
||||||
historyLogin.getUsername(),
|
|
||||||
historyLogin.getDisplayName(),
|
|
||||||
historyLogin.getLoginType(),
|
|
||||||
historyLogin.getMessage(),
|
|
||||||
historyLogin.getCode(),
|
|
||||||
historyLogin.getProvider(),
|
|
||||||
historyLogin.getSourceIp(),
|
|
||||||
historyLogin.getCountry(),
|
|
||||||
historyLogin.getProvince(),
|
|
||||||
historyLogin.getCity(),
|
|
||||||
historyLogin.getLocation(),
|
|
||||||
historyLogin.getBrowser(),
|
|
||||||
historyLogin.getPlatform(),
|
|
||||||
"Browser",
|
|
||||||
historyLogin.getSessionStatus(),
|
|
||||||
historyLogin.getInstId()
|
|
||||||
},
|
|
||||||
new int[] {
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.INTEGER,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.VARCHAR,
|
|
||||||
Types.INTEGER,
|
|
||||||
Types.VARCHAR
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -24,4 +24,6 @@ import org.dromara.mybatis.jpa.entity.JpaPageResults;
|
|||||||
public interface HistoryLoginService extends IJpaService<HistoryLogin>{
|
public interface HistoryLoginService extends IJpaService<HistoryLogin>{
|
||||||
|
|
||||||
public JpaPageResults<HistoryLogin> queryOnlineSession(HistoryLogin historyLogin);
|
public JpaPageResults<HistoryLogin> queryOnlineSession(HistoryLogin historyLogin);
|
||||||
|
|
||||||
|
public void login(HistoryLogin historyLogin);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,17 +17,50 @@
|
|||||||
|
|
||||||
package org.dromara.maxkey.persistence.service.impl;
|
package org.dromara.maxkey.persistence.service.impl;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.dromara.maxkey.entity.history.HistoryLogin;
|
import org.dromara.maxkey.entity.history.HistoryLogin;
|
||||||
import org.dromara.maxkey.persistence.mapper.HistoryLoginMapper;
|
import org.dromara.maxkey.persistence.mapper.HistoryLoginMapper;
|
||||||
import org.dromara.maxkey.persistence.service.HistoryLoginService;
|
import org.dromara.maxkey.persistence.service.HistoryLoginService;
|
||||||
|
import org.dromara.maxkey.web.WebContext;
|
||||||
import org.dromara.mybatis.jpa.entity.JpaPageResults;
|
import org.dromara.mybatis.jpa.entity.JpaPageResults;
|
||||||
import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl;
|
import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public class HistoryLoginServiceImpl extends JpaServiceImpl<HistoryLoginMapper,HistoryLogin> implements HistoryLoginService{
|
public class HistoryLoginServiceImpl extends JpaServiceImpl<HistoryLoginMapper,HistoryLogin> implements HistoryLoginService{
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(HistoryLoginServiceImpl.class);
|
||||||
|
|
||||||
public JpaPageResults<HistoryLogin> queryOnlineSession(HistoryLogin historyLogin) {
|
public JpaPageResults<HistoryLogin> queryOnlineSession(HistoryLogin historyLogin) {
|
||||||
return this.fetchPageResults("queryOnlineSession",historyLogin);
|
return this.fetchPageResults("queryOnlineSession",historyLogin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void login(HistoryLogin historyLogin) {
|
||||||
|
historyLogin.setId(WebContext.genId());
|
||||||
|
if(StringUtils.isBlank(historyLogin.getInstId())) {
|
||||||
|
historyLogin.setInstId("1");
|
||||||
|
}
|
||||||
|
//Thread insert
|
||||||
|
new Thread(new HistoryLoginRunnable(this,historyLogin)).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HistoryLoginRunnable implements Runnable{
|
||||||
|
|
||||||
|
HistoryLoginService historyLoginService;
|
||||||
|
|
||||||
|
HistoryLogin historyLogin;
|
||||||
|
|
||||||
|
public HistoryLoginRunnable(HistoryLoginService historyLoginService, HistoryLogin historyLogin) {
|
||||||
|
super();
|
||||||
|
this.historyLoginService = historyLoginService;
|
||||||
|
this.historyLogin = historyLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
logger.debug("History Login {}" , historyLogin);
|
||||||
|
this.historyLoginService.insert(historyLogin);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,10 +42,10 @@ import org.dromara.maxkey.password.onetimepwd.impl.MailOtpAuthn;
|
|||||||
import org.dromara.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
|
import org.dromara.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
|
||||||
import org.dromara.maxkey.password.onetimepwd.token.RedisOtpTokenStore;
|
import org.dromara.maxkey.password.onetimepwd.token.RedisOtpTokenStore;
|
||||||
import org.dromara.maxkey.persistence.redis.RedisConnectionFactory;
|
import org.dromara.maxkey.persistence.redis.RedisConnectionFactory;
|
||||||
import org.dromara.maxkey.persistence.repository.LoginHistoryRepository;
|
|
||||||
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
||||||
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
||||||
import org.dromara.maxkey.persistence.service.CnfLdapContextService;
|
import org.dromara.maxkey.persistence.service.CnfLdapContextService;
|
||||||
|
import org.dromara.maxkey.persistence.service.HistoryLoginService;
|
||||||
import org.dromara.maxkey.persistence.service.UserInfoService;
|
import org.dromara.maxkey.persistence.service.UserInfoService;
|
||||||
import org.dromara.maxkey.schedule.ScheduleAdapterBuilder;
|
import org.dromara.maxkey.schedule.ScheduleAdapterBuilder;
|
||||||
import org.quartz.Scheduler;
|
import org.quartz.Scheduler;
|
||||||
@ -90,7 +90,7 @@ public class MaxKeyConfig {
|
|||||||
@Qualifier("passwordEncoder") PasswordEncoder passwordEncoder,
|
@Qualifier("passwordEncoder") PasswordEncoder passwordEncoder,
|
||||||
PasswordPolicyValidator passwordPolicyValidator,
|
PasswordPolicyValidator passwordPolicyValidator,
|
||||||
LoginRepository loginService,
|
LoginRepository loginService,
|
||||||
LoginHistoryRepository loginHistoryService,
|
HistoryLoginService historyLoginService,
|
||||||
UserInfoService userInfoService,
|
UserInfoService userInfoService,
|
||||||
IpLocationParser ipLocationParser,
|
IpLocationParser ipLocationParser,
|
||||||
JdbcTemplate jdbcTemplate,
|
JdbcTemplate jdbcTemplate,
|
||||||
@ -101,7 +101,7 @@ public class MaxKeyConfig {
|
|||||||
passwordEncoder,
|
passwordEncoder,
|
||||||
passwordPolicyValidator,
|
passwordPolicyValidator,
|
||||||
loginService,
|
loginService,
|
||||||
loginHistoryService,
|
historyLoginService,
|
||||||
userInfoService,
|
userInfoService,
|
||||||
ipLocationParser,
|
ipLocationParser,
|
||||||
jdbcTemplate,
|
jdbcTemplate,
|
||||||
|
|||||||
@ -21,9 +21,9 @@ import org.dromara.maxkey.authn.realm.jdbc.JdbcAuthenticationRealm;
|
|||||||
import org.dromara.maxkey.ip2location.IpLocationParser;
|
import org.dromara.maxkey.ip2location.IpLocationParser;
|
||||||
import org.dromara.maxkey.password.onetimepwd.AbstractOtpAuthn;
|
import org.dromara.maxkey.password.onetimepwd.AbstractOtpAuthn;
|
||||||
import org.dromara.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
|
import org.dromara.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
|
||||||
import org.dromara.maxkey.persistence.repository.LoginHistoryRepository;
|
|
||||||
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
||||||
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
||||||
|
import org.dromara.maxkey.persistence.service.HistoryLoginService;
|
||||||
import org.dromara.maxkey.persistence.service.UserInfoService;
|
import org.dromara.maxkey.persistence.service.UserInfoService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -44,7 +44,7 @@ public class MaxKeyMgtConfig {
|
|||||||
PasswordEncoder passwordEncoder,
|
PasswordEncoder passwordEncoder,
|
||||||
PasswordPolicyValidator passwordPolicyValidator,
|
PasswordPolicyValidator passwordPolicyValidator,
|
||||||
LoginRepository loginRepository,
|
LoginRepository loginRepository,
|
||||||
LoginHistoryRepository loginHistoryRepository,
|
HistoryLoginService historyLoginService,
|
||||||
UserInfoService userInfoService,
|
UserInfoService userInfoService,
|
||||||
IpLocationParser ipLocationParser,
|
IpLocationParser ipLocationParser,
|
||||||
JdbcTemplate jdbcTemplate) {
|
JdbcTemplate jdbcTemplate) {
|
||||||
@ -53,7 +53,7 @@ public class MaxKeyMgtConfig {
|
|||||||
passwordEncoder,
|
passwordEncoder,
|
||||||
passwordPolicyValidator,
|
passwordPolicyValidator,
|
||||||
loginRepository,
|
loginRepository,
|
||||||
loginHistoryRepository,
|
historyLoginService,
|
||||||
userInfoService,
|
userInfoService,
|
||||||
ipLocationParser,
|
ipLocationParser,
|
||||||
jdbcTemplate);
|
jdbcTemplate);
|
||||||
|
|||||||
@ -21,9 +21,9 @@ import org.dromara.maxkey.authn.realm.jdbc.JdbcAuthenticationRealm;
|
|||||||
import org.dromara.maxkey.ip2location.IpLocationParser;
|
import org.dromara.maxkey.ip2location.IpLocationParser;
|
||||||
import org.dromara.maxkey.password.onetimepwd.AbstractOtpAuthn;
|
import org.dromara.maxkey.password.onetimepwd.AbstractOtpAuthn;
|
||||||
import org.dromara.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
|
import org.dromara.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
|
||||||
import org.dromara.maxkey.persistence.repository.LoginHistoryRepository;
|
|
||||||
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
import org.dromara.maxkey.persistence.repository.LoginRepository;
|
||||||
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator;
|
||||||
|
import org.dromara.maxkey.persistence.service.HistoryLoginService;
|
||||||
import org.dromara.maxkey.persistence.service.UserInfoService;
|
import org.dromara.maxkey.persistence.service.UserInfoService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -44,7 +44,7 @@ public class MaxKeyOpenApiConfig{
|
|||||||
PasswordEncoder passwordEncoder,
|
PasswordEncoder passwordEncoder,
|
||||||
PasswordPolicyValidator passwordPolicyValidator,
|
PasswordPolicyValidator passwordPolicyValidator,
|
||||||
LoginRepository loginRepository,
|
LoginRepository loginRepository,
|
||||||
LoginHistoryRepository loginHistoryRepository,
|
HistoryLoginService historyLoginService,
|
||||||
UserInfoService userInfoService,
|
UserInfoService userInfoService,
|
||||||
IpLocationParser ipLocationParser,
|
IpLocationParser ipLocationParser,
|
||||||
JdbcTemplate jdbcTemplate) {
|
JdbcTemplate jdbcTemplate) {
|
||||||
@ -53,7 +53,7 @@ public class MaxKeyOpenApiConfig{
|
|||||||
passwordEncoder,
|
passwordEncoder,
|
||||||
passwordPolicyValidator,
|
passwordPolicyValidator,
|
||||||
loginRepository,
|
loginRepository,
|
||||||
loginHistoryRepository,
|
historyLoginService,
|
||||||
userInfoService,
|
userInfoService,
|
||||||
ipLocationParser,
|
ipLocationParser,
|
||||||
jdbcTemplate);
|
jdbcTemplate);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user