This commit is contained in:
MaxKey
2022-04-26 17:41:04 +08:00
parent 946b346282
commit e51a3a25ba
37 changed files with 236 additions and 218 deletions

View File

@@ -21,7 +21,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.mybatis.jpa.persistence.JpaPageResults;
import org.maxkey.authn.annotation.CurrentUser;
import org.maxkey.authn.online.OnlineTicketService;
import org.maxkey.authn.session.SessionService;
import org.maxkey.entity.HistoryLogin;
import org.maxkey.entity.Message;
import org.maxkey.entity.UserInfo;
@@ -57,7 +57,7 @@ public class LoginSessionController {
HistoryLoginService historyLoginService;
@Autowired
OnlineTicketService onlineTicketService;
SessionService sessionService;
/**
* 查询登录日志.
@@ -90,7 +90,7 @@ public class LoginSessionController {
continue;//skip current session
}
onlineTicketService.terminate(
sessionService.terminate(
sessionId,
currentUser.getId(),
currentUser.getUsername());

View File

@@ -22,8 +22,8 @@ import java.util.Set;
import java.util.Map.Entry;
import org.maxkey.authn.annotation.CurrentUser;
import org.maxkey.authn.online.OnlineTicket;
import org.maxkey.authn.online.OnlineTicketService;
import org.maxkey.authn.session.Session;
import org.maxkey.authn.session.SessionService;
import org.maxkey.authz.singlelogout.SamlSingleLogout;
import org.maxkey.authz.singlelogout.DefaultSingleLogout;
import org.maxkey.authz.singlelogout.LogoutType;
@@ -48,14 +48,14 @@ public class LogoutEndpoint {
private static Logger _logger = LoggerFactory.getLogger(LogoutEndpoint.class);
@Autowired
protected OnlineTicketService onlineTicketService;
protected SessionService sessionService;
@Operation(summary = "单点注销接口", description = "reLoginUrl跳转地址",method="GET")
@RequestMapping(value={"/logout"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> logout(@CurrentUser UserInfo currentUser){
//if logined in have onlineTicket ,need remove or logout back
String onlineTicketId = currentUser.getOnlineTicket();
OnlineTicket onlineTicket = onlineTicketService.get(onlineTicketId);
Session onlineTicket = sessionService.get(onlineTicketId);
if(onlineTicket != null) {
Set<Entry<String, Apps>> entrySet = onlineTicket.getAuthorizedApps().entrySet();
@@ -74,7 +74,7 @@ public class LogoutEndpoint {
}
}
onlineTicketService.terminate(
sessionService.terminate(
onlineTicketId,
currentUser.getId(),
currentUser.getUsername());

View File

@@ -84,7 +84,7 @@ public class HistorySignOnAppInterceptor implements AsyncHandlerInterceptor {
SigninPrincipal principal = AuthorizationUtils.getPrincipal();
if(principal != null && app !=null) {
final UserInfo userInfo = principal.getUserInfo();
String sessionId = principal.getOnlineTicket().getTicketId();
String sessionId = principal.getSession().getId();
_logger.debug("sessionId : " + sessionId + " ,appId : " + app.getId());
HistoryLoginApps historyLoginApps = new HistoryLoginApps();
historyLoginApps.setAppId(app.getId());

View File

@@ -20,7 +20,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.maxkey.authn.jwt.AuthJwtService;
import org.maxkey.authn.online.OnlineTicketService;
import org.maxkey.authn.session.SessionService;
import org.maxkey.authn.web.AuthorizationUtils;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.crypto.Base64Utils;
@@ -39,7 +39,7 @@ public class SingleSignOnInterceptor implements AsyncHandlerInterceptor {
ApplicationConfig applicationConfig;
@Autowired
OnlineTicketService onlineTicketService;
SessionService sessionService;
@Autowired
AuthJwtService authJwtService ;
@@ -51,7 +51,7 @@ public class SingleSignOnInterceptor implements AsyncHandlerInterceptor {
_logger.trace("Single Sign On Interceptor");
AuthorizationUtils.authenticateWithCookie(
request,authJwtService,onlineTicketService);
request,authJwtService,sessionService);
if(AuthorizationUtils.isNotAuthenticated()){
String loginUrl = applicationConfig.getFrontendUri() + "/#/passport/login?redirect_uri=%s";

View File

@@ -17,10 +17,10 @@
package org.maxkey;
import org.maxkey.authn.online.OnlineTicketService;
import org.maxkey.authn.session.SessionService;
import org.maxkey.jobs.AccountsStrategyJob;
import org.maxkey.jobs.DynamicGroupsJob;
import org.maxkey.jobs.TicketListenerJob;
import org.maxkey.jobs.SessionListenerJob;
import org.maxkey.persistence.service.AccountsService;
import org.maxkey.persistence.service.GroupsService;
import org.quartz.CronScheduleBuilder;
@@ -44,22 +44,22 @@ import org.springframework.scheduling.quartz.SchedulerFactoryBean;
public class MaxKeyMgtJobs implements InitializingBean {
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyMgtJobs.class);
@Bean(name = "schedulerTicketListenerJobs")
@Bean(name = "schedulerSessionListenerJobs")
public String ticketListenerJob(
SchedulerFactoryBean schedulerFactoryBean,
OnlineTicketService onlineTicketService) throws SchedulerException {
SessionService sessionService) throws SchedulerException {
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("service", onlineTicketService);
jobDataMap.put("service", sessionService);
addJobScheduler(
TicketListenerJob.class,
SessionListenerJob.class,
schedulerFactoryBean,
jobDataMap,
"0 0/10 * * * ?",//10 minutes
"TicketListener"
"SessionListener"
);
return "schedulerTicketListenerJobs";
return "schedulerSessionListenerJobs";
}
@Bean(name = "schedulerDynamicGroupsJobs")

View File

@@ -17,7 +17,7 @@ package org.maxkey.jobs;
import java.io.Serializable;
import org.maxkey.authn.online.OnlineTicketService;
import org.maxkey.authn.session.SessionService;
import org.maxkey.entity.HistoryLogin;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
@@ -25,12 +25,12 @@ import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TicketListenerJob extends AbstractScheduleJob implements Job , Serializable {
final static Logger _logger = LoggerFactory.getLogger(TicketListenerJob.class);
public class SessionListenerJob extends AbstractScheduleJob implements Job , Serializable {
final static Logger _logger = LoggerFactory.getLogger(SessionListenerJob.class);
private static final long serialVersionUID = 4782358765969474833L;
OnlineTicketService onlineTicketService;
SessionService sessionService;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
@@ -40,13 +40,13 @@ public class TicketListenerJob extends AbstractScheduleJob implements Job , Se
_logger.debug("TicketListener Job is running ... " );
jobStatus = JOBSTATUS.RUNNING;
try {
if(onlineTicketService != null) {
for (HistoryLogin onlineTicket : onlineTicketService.queryOnlineTicket()) {
if(onlineTicketService.get(onlineTicket.getSessionId()) == null) {
onlineTicketService.terminate(
onlineTicket.getSessionId(),
onlineTicket.getUserId(),
onlineTicket.getUsername());
if(sessionService != null) {
for (HistoryLogin onlineSession : sessionService.queryOnlineTicket()) {
if(sessionService.get(onlineSession.getSessionId()) == null) {
sessionService.terminate(
onlineSession.getSessionId(),
onlineSession.getUserId(),
onlineSession.getUsername());
}
}
}
@@ -61,9 +61,9 @@ public class TicketListenerJob extends AbstractScheduleJob implements Job , Se
@Override
void init(JobExecutionContext context){
if(onlineTicketService == null) {
onlineTicketService =
(OnlineTicketService) context.getMergedJobDataMap().get("service");
if(sessionService == null) {
sessionService =
(SessionService) context.getMergedJobDataMap().get("service");
}
}
}

View File

@@ -21,7 +21,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.mybatis.jpa.persistence.JpaPageResults;
import org.maxkey.authn.annotation.CurrentUser;
import org.maxkey.authn.online.OnlineTicketService;
import org.maxkey.authn.session.SessionService;
import org.maxkey.entity.HistoryLogin;
import org.maxkey.entity.Message;
import org.maxkey.entity.UserInfo;
@@ -57,7 +57,7 @@ public class LoginSessionController {
HistoryLoginService historyLoginService;
@Autowired
OnlineTicketService onlineTicketService;
SessionService sessionService;
/**
* 查询登录日志.
@@ -90,7 +90,7 @@ public class LoginSessionController {
if(currentUser.getOnlineTicket().contains(sessionId)) {
continue;//skip current session
}
onlineTicketService.terminate(sessionId,currentUser.getId(),currentUser.getUsername());
sessionService.terminate(sessionId,currentUser.getId(),currentUser.getUsername());
}
isTerminated = true;
}catch(Exception e) {

View File

@@ -18,7 +18,7 @@
package org.maxkey.web.contorller;
import org.maxkey.authn.annotation.CurrentUser;
import org.maxkey.authn.online.OnlineTicketService;
import org.maxkey.authn.session.SessionService;
import org.maxkey.entity.Message;
import org.maxkey.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,11 +31,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
public class LogoutEndpoint {
@Autowired
protected OnlineTicketService onlineTicketService;
protected SessionService sessionService;
@RequestMapping(value={"/logout"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> logout(@CurrentUser UserInfo currentUser){
onlineTicketService.terminate(
sessionService.terminate(
currentUser.getOnlineTicket(),
currentUser.getId(),
currentUser.getUsername());