This commit is contained in:
shimingxy
2019-11-06 23:28:59 +08:00
parent 623d6551c8
commit 3ce501aa86
167 changed files with 2293 additions and 1946 deletions

View File

@@ -6,13 +6,13 @@ import org.maxkey.constants.OPERATEMESSAGE;
import org.maxkey.constants.PROTOCOLS;
import org.maxkey.crypto.ReciprocalUtils;
import org.maxkey.dao.service.AccountsService;
import org.maxkey.dao.service.ApplicationsService;
import org.maxkey.dao.service.AppsService;
import org.maxkey.dao.service.MyAppsListService;
import org.maxkey.dao.service.UserInfoService;
import org.maxkey.domain.Accounts;
import org.maxkey.domain.UserInfo;
import org.maxkey.domain.apps.Applications;
import org.maxkey.domain.apps.UserApplications;
import org.maxkey.domain.apps.Apps;
import org.maxkey.domain.apps.UserApps;
import org.maxkey.web.WebContext;
import org.maxkey.web.message.Message;
import org.maxkey.web.message.MessageType;
@@ -44,7 +44,7 @@ public class AppListController{
AccountsService appUsersService;
@Autowired
ApplicationsService applicationsService;
AppsService applicationsService;
@RequestMapping(value={"/appList"})
public ModelAndView appList(@RequestParam(value="gridList",required = false) String gridList) {
@@ -70,12 +70,12 @@ public class AppListController{
}
private List<UserApplications> queryAccessableApps(){
UserApplications userApplications=new UserApplications();
private List<UserApps> queryAccessableApps(){
UserApps userApplications=new UserApps();
userApplications.setUsername(WebContext.getUserInfo().getUsername());
List<UserApplications> appList=myAppsListService.queryMyApps(userApplications);
for (UserApplications app : appList){
List<UserApps> appList=myAppsListService.queryMyApps(userApplications);
for (UserApps app : appList){
WebContext.setAttribute(app.getId(), app.getIcon());
}
@@ -162,7 +162,7 @@ public class AppListController{
Accounts appUsers=new Accounts();
UserInfo userInfo=WebContext.getUserInfo();
if(credential==Applications.CREDENTIALS.USER_DEFINED){
if(credential==Apps.CREDENTIALS.USER_DEFINED){
appUsers=appUsersService.load(new Accounts(userInfo.getId(),appId));
if(protocol.equalsIgnoreCase(PROTOCOLS.DESKTOP)||
protocol.equalsIgnoreCase(PROTOCOLS.FORMBASED)||
@@ -172,8 +172,7 @@ public class AppListController{
modelAndView.addObject("username",true);
modelAndView.addObject("password",true);
}else if(protocol.equalsIgnoreCase(PROTOCOLS.SAML11)||
protocol.equalsIgnoreCase(PROTOCOLS.SAML20)
}else if(protocol.equalsIgnoreCase(PROTOCOLS.SAML20)
){
modelAndView.addObject("username",true);
modelAndView.addObject("password",false);
@@ -211,14 +210,14 @@ public class AppListController{
@RequestParam("identity_password") String identity_password
){
Applications app=applicationsService.get(appId);
Apps app=applicationsService.get(appId);
UserInfo userInfo=WebContext.getUserInfo();
Accounts appUsers=new Accounts();
appUsers.setAppId(appId);
appUsers.setUid(userInfo.getId());
if(identity_password!=null&&!identity_password.equals("")&&credential==Applications.CREDENTIALS.USER_DEFINED){
if(identity_password!=null&&!identity_password.equals("")&&credential==Apps.CREDENTIALS.USER_DEFINED){
appUsers=appUsersService.load(new Accounts(userInfo.getId(),appId));
if(appUsers==null){
appUsers=new Accounts();

View File

@@ -0,0 +1,112 @@
package org.maxkey.web.contorller;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.mybatis.jpa.persistence.JpaPageResults;
import org.maxkey.dao.service.HistoryLoginAppsService;
import org.maxkey.dao.service.HistoryLoginService;
import org.maxkey.dao.service.HistoryLogsService;
import org.maxkey.domain.HistoryLoginApps;
import org.maxkey.domain.HistoryLogin;
import org.maxkey.domain.HistoryLogs;
import org.maxkey.util.DateUtils;
import org.maxkey.web.WebContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* 登录日志和操作日志查询
*
* @author Crystal.sea
*
*/
@Controller
@RequestMapping(value={"/historys"})
public class HistorysController {
final static Logger _logger = LoggerFactory.getLogger(HistorysController.class);
@Autowired
HistoryLoginService historyLoginService;
@Autowired
protected HistoryLoginAppsService historyLoginAppsService;
@Autowired
HistoryLogsService historyLogsService;
@RequestMapping(value={"/logs"})
public String List(){
return "historys/logsList";
}
/**
* 查询操作日志
* @param logs
* @return
*/
@RequestMapping(value={"/logs/grid"})
@ResponseBody
public JpaPageResults<HistoryLogs> logsDataGrid(@ModelAttribute("historyLogs") HistoryLogs historyLogs){
_logger.debug("history/logs/grid/ logsGrid() "+historyLogs);
return historyLogsService.queryPageResults(historyLogs);
}
@RequestMapping(value={"/login"})
public String authList(){
return "historys/loginList";
}
/**
* 查询登录日志
* @param logsAuth
* @return
*/
@RequestMapping(value={"/login/grid"})
@ResponseBody
public JpaPageResults<HistoryLogin> logAuthsGrid(@ModelAttribute("historyLogin") HistoryLogin historyLogin){
_logger.debug("history/login/grid/ logsGrid() "+historyLogin);
historyLogin.setUid(WebContext.getUserInfo().getId());
return historyLoginService.queryPageResults(historyLogin);
}
@RequestMapping(value={"/loginApps"})
public String loginAppHistoryList(){
return "historys/loginAppsList";
}
/**
* 查询单点登录日志
* @param logsSso
* @return
*/
@RequestMapping(value={"/loginApps/grid"})
@ResponseBody
public JpaPageResults<HistoryLoginApps> logsSsoGrid(@ModelAttribute("historyLoginApps") HistoryLoginApps historyLoginApps){
_logger.debug("history/loginApps/grid/ logsGrid() "+historyLoginApps);
historyLoginApps.setId(null);
return historyLoginAppsService.queryPageResults(historyLoginApps);
}
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat(DateUtils.FORMAT_DATE_HH_MM_SS);
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
}

View File

@@ -1,114 +0,0 @@
package org.maxkey.web.contorller;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.mybatis.jpa.persistence.JpaPageResults;
import org.maxkey.dao.service.LoginAppsHistoryService;
import org.maxkey.dao.service.LoginHistoryService;
import org.maxkey.dao.service.LogsService;
import org.maxkey.domain.LoginAppsHistory;
import org.maxkey.domain.LoginHistory;
import org.maxkey.domain.Logs;
import org.maxkey.util.DateUtils;
import org.maxkey.web.WebContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* 登录日志和操作日志查询
*
* @author Crystal.sea
*
*/
@Controller
@RequestMapping(value={"/logs"})
public class LogsController {
final static Logger _logger = LoggerFactory.getLogger(LogsController.class);
@Autowired
LoginHistoryService loginHistoryService;
@Autowired
protected LoginAppsHistoryService loginAppsHistoryService;
@Autowired
LogsService logsService;
/**
* 查询操作日志
* @param logs
* @return
*/
@RequestMapping(value={"/grid"})
@ResponseBody
public JpaPageResults<Logs> logsDataGrid(@ModelAttribute("logs") Logs logs){
_logger.debug("logs/grid/ logsGrid() "+logs);
return logsService.queryPageResults(logs);
}
@RequestMapping(value={"/list"})
public String List(){
return "logs/logsList";
}
@RequestMapping(value={"/loginHistoryList"})
public String authList(){
return "logs/loginHistoryList";
}
/**
* 查询登录日志
* @param logsAuth
* @return
*/
@RequestMapping(value={"/loginHistory/grid"})
@ResponseBody
public JpaPageResults<LoginHistory> logAuthsGrid(@ModelAttribute("loginHistory") LoginHistory loginHistory){
_logger.debug("logs/loginHistory/grid/ logsGrid() "+loginHistory);
loginHistory.setUid(WebContext.getUserInfo().getId());
return loginHistoryService.queryPageResults(loginHistory);
}
@RequestMapping(value={"/loginAppHistoryList"})
public String loginAppHistoryList(){
return "logs/loginAppHistoryList";
}
/**
* 查询单点登录日志
* @param logsSso
* @return
*/
@RequestMapping(value={"/loginAppsHistory/grid"})
@ResponseBody
public JpaPageResults<LoginAppsHistory> logsSsoGrid(@ModelAttribute("loginAppsHistory") LoginAppsHistory loginAppsHistory){
_logger.debug("logs/loginAppsHistory/grid/ logsGrid() "+loginAppsHistory);
loginAppsHistory.setId(null);
return loginAppsHistoryService.queryPageResults(loginAppsHistory);
}
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat(DateUtils.FORMAT_DATE_HH_MM_SS);
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
}

View File

@@ -5,11 +5,11 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
import org.maxkey.dao.service.ApplicationsService;
import org.maxkey.dao.service.LoginAppsHistoryService;
import org.maxkey.domain.LoginAppsHistory;
import org.maxkey.dao.service.AppsService;
import org.maxkey.dao.service.HistoryLoginAppsService;
import org.maxkey.domain.HistoryLoginApps;
import org.maxkey.domain.UserInfo;
import org.maxkey.domain.apps.Applications;
import org.maxkey.domain.apps.Apps;
import org.maxkey.web.WebConstants;
import org.maxkey.web.WebContext;
import org.slf4j.Logger;
@@ -19,15 +19,15 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class LoginAppHistoryAdapter extends HandlerInterceptorAdapter {
private static final Logger _logger = LoggerFactory.getLogger(LoginAppHistoryAdapter.class);
public class HistoryLoginAppAdapter extends HandlerInterceptorAdapter {
private static final Logger _logger = LoggerFactory.getLogger(HistoryLoginAppAdapter.class);
@Autowired
LoginAppsHistoryService loginAppsHistoryService;
HistoryLoginAppsService historyLoginAppsService;
@Autowired
@Qualifier("applicationsService")
protected ApplicationsService applicationsService;
@Qualifier("appsService")
protected AppsService appsService;
/*
* (non-Javadoc)
* @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
@@ -42,19 +42,19 @@ public class LoginAppHistoryAdapter extends HandlerInterceptorAdapter {
PreLoginAppAdapter.getAppIdFromRequestURI(request);
}
//Applications app=applicationsService.get(appId);
Applications app=(Applications)WebContext.getAttribute(AuthorizeBaseEndpoint.class.getName());
Apps app=(Apps)WebContext.getAttribute(AuthorizeBaseEndpoint.class.getName());
String sessionId=(String)WebContext.getAttribute(WebConstants.CURRENT_USER_SESSION_ID);
UserInfo userInfo =WebContext.getUserInfo();
_logger.debug("sessionId : "+sessionId+" ,appId : "+appId);
LoginAppsHistory loginAppsHistory=new LoginAppsHistory();
loginAppsHistory.setId(loginAppsHistory.generateId());
loginAppsHistory.setAppId(appId);
loginAppsHistory.setSessionId(sessionId);
loginAppsHistory.setAppName(app.getName());
loginAppsHistory.setUid(userInfo.getId());
loginAppsHistory.setUsername(userInfo.getUsername());
loginAppsHistory.setDisplayName(userInfo.getDisplayName());
loginAppsHistoryService.insert(loginAppsHistory);
HistoryLoginApps historyLoginApps=new HistoryLoginApps();
historyLoginApps.setId(historyLoginApps.generateId());
historyLoginApps.setAppId(appId);
historyLoginApps.setSessionId(sessionId);
historyLoginApps.setAppName(app.getName());
historyLoginApps.setUid(userInfo.getId());
historyLoginApps.setUsername(userInfo.getUsername());
historyLoginApps.setDisplayName(userInfo.getDisplayName());
historyLoginAppsService.insert(historyLoginApps);
WebContext.removeAttribute(WebConstants.CURRENT_SINGLESIGNON_URI);
WebContext.removeAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID);
}

View File

@@ -3,8 +3,8 @@ package org.maxkey.web.interceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.maxkey.dao.service.LogsService;
import org.maxkey.domain.Logs;
import org.maxkey.dao.service.HistoryLogsService;
import org.maxkey.domain.HistoryLogs;
import org.maxkey.domain.UserInfo;
import org.maxkey.util.JsonUtils;
import org.maxkey.web.WebContext;
@@ -25,13 +25,13 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
* @author Crystal.Sea
*
*/
public class LogAdapter extends HandlerInterceptorAdapter {
public class HistoryLogsAdapter extends HandlerInterceptorAdapter {
private static final Logger _logger = LoggerFactory.getLogger(LogAdapter.class);
private static final Logger _logger = LoggerFactory.getLogger(HistoryLogsAdapter.class);
@Autowired
@Qualifier("logsService")
private LogsService logsService;
@Qualifier("historyLogsService")
private HistoryLogsService historyLogsService;
// after the handler is executed
public void postHandle(HttpServletRequest request,HttpServletResponse response, Object handler,ModelAndView modelAndView) throws Exception {
@@ -43,7 +43,7 @@ public class LogAdapter extends HandlerInterceptorAdapter {
UserInfo userInfo =WebContext.getUserInfo();//取得当前用户信息
//创建日志记录
Logs logs = new Logs(
HistoryLogs historyLogs = new HistoryLogs(
message.getServiceName(),
message.getCode(),
message.getMessage(),
@@ -54,8 +54,8 @@ public class LogAdapter extends HandlerInterceptorAdapter {
userInfo==null?null:userInfo.getUsername(),
""
);
_logger.debug("insert db logs content : "+logs);
logsService.insert(logs);//日志插入数据库
_logger.debug("insert db historyLogs content : "+historyLogs);
historyLogsService.insert(historyLogs);//日志插入数据库
if(message.getMessageScope() == MessageScope.DB) {//message类型仅插入数据库
WebContext.clearMessage();//清除message
}

View File

@@ -50,7 +50,7 @@
</div>
<div class="mainwrap" id="main">
<table data-url="<@base />/logs/loginAppsHistory/grid"
<table data-url="<@base />/historys/loginApps/grid"
id="datagrid"
data-toggle="table"
data-classes="table table-bordered table-hover table-striped"

View File

@@ -50,7 +50,7 @@
<div class="mainwrap" id="main">
<table data-url="<@base />/logs/loginHistory/grid"
<table data-url="<@base />/historys/login/grid"
id="datagrid"
data-toggle="table"
data-classes="table table-bordered table-hover table-striped"

View File

@@ -35,7 +35,7 @@
<div class="mainwrap" id="main">
<table data-url="<@base />/logs/grid"
<table data-url="<@base />/historys/logs/grid"
id="datagrid"
data-toggle="table"
data-classes="table table-bordered table-hover table-striped"