提交最新源码

master
baogq 2 years ago
parent ca37f5e3c1
commit 5767d8225d

@ -2,6 +2,7 @@ package com.ruoyi.web.controller.api;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.OnlineStatus;
import com.ruoyi.common.utils.CookieUtils;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.ShiroUtils;
@ -9,11 +10,16 @@ import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.framework.shiro.session.OnlineSession;
import com.ruoyi.framework.shiro.session.OnlineSessionDAO;
import com.ruoyi.framework.shiro.web.filter.LogoutFilter;
import com.ruoyi.system.domain.SysUserOnline;
import com.ruoyi.system.service.ISysUserOnlineService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.servlet.SimpleCookie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -23,6 +29,8 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.stream.Collectors;
/**
* 退
@ -32,15 +40,42 @@ import javax.servlet.http.HttpServletResponse;
@Controller
@RequestMapping("/api/logout")
public class LogoutApi {
@Autowired
private ISysUserOnlineService userOnlineService;
@Autowired
private OnlineSessionDAO onlineSessionDAO;
@GetMapping()
public void logout(HttpServletRequest request, HttpServletResponse response,String userName){
//CookieUtil.remove(request, response, "JSESSIONID");
//START
System.out.println("》》》获取接口用户名:"+ userName);
SysUserOnline userOnline = new SysUserOnline();
userOnline.setStatus(OnlineStatus.on_line);
List<SysUserOnline> list = userOnlineService.selectUserOnlineList(userOnline);
List<SysUserOnline> result = null;
result = list.stream()
.filter((SysUserOnline b) -> b.getLoginName().contains(userName))
.collect(Collectors.toList());
for (SysUserOnline SysUserOnline:result
) {
SysUserOnline online = userOnlineService.selectOnlineById(SysUserOnline.getSessionId());
OnlineSession onlineSession = (OnlineSession) onlineSessionDAO.readSession(online.getSessionId());
onlineSessionDAO.delete(onlineSession);
online.setStatus(OnlineStatus.off_line);
userOnlineService.saveOnline(online);
userOnlineService.removeUserCache(online.getLoginName(), SysUserOnline.getSessionId());
}
//END
Subject subject = SecurityUtils.getSubject();
SysUser user = new SysUser();
user.setUserName(userName);
if (StringUtils.isNotNull(user))
{
String loginName = user.getLoginName();
String loginName = ShiroUtils.getLoginName();
// 记录用户退出日志
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success")));
// 清理缓存

@ -7,6 +7,14 @@ import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.framework.shiro.service.SysPasswordService;
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.ISysUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
@ -53,6 +61,12 @@ public class SysLoginController extends BaseController
@Autowired
private ConfigService configService;
@Autowired
private ISysUserService userService;
@Autowired
private SysPasswordService passwordService;
@Autowired
private ISysRoleService roleService;
@GetMapping("/login")
public String login(HttpServletRequest request, HttpServletResponse response, ModelMap mmap)
@ -83,11 +97,31 @@ public class SysLoginController extends BaseController
if(StringUtils.isNotNull(result)){
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(result);
String username = jsonObject.get("username").toString();
String password = jsonObject.get("password").toString();
//判断数据库里是否存在该用户,如果不存在则添加,如果存在则跳过;
if (!UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(username)))
{
SysUser user = new SysUser();
user.setDeptId(100L);
user.setLoginName(username);
user.setUserName(username);
user.setRoleIds(new Long[]{2L});
user.setRoleId(2L);
user.setSalt(ShiroUtils.randomSalt());
user.setPassword(passwordService.encryptPassword(user.getLoginName(), "123456", user.getSalt()));
user.setCreateBy(username);
user.setStatus("0");
userService.insertUser(user);
}
mmap.put("requestURL", requestURL);
mmap.put("username", username);
mmap.put("password", password);
// mmap.put("password", password);
if (StringUtils.isNotNull(jsonObject.get("password"))) {
mmap.put("password", jsonObject.get("password").toString());
} else {
mmap.put("password", "123456");
}
return "ssologin";
}
}

@ -89,7 +89,9 @@ pagehelper:
shiro:
user:
# 登录地址
# loginUrl: http://localhost:5050/login
loginUrl: http://10.100.71.111/sso/login?redirect_url=http://10.100.71.119:5050/login
# loginUrl: http://10.100.71.111/sso/login?redirect_url=http://localhost:5050/login
# 权限认证失败地址
unauthorizedUrl: /unauth
# 首页地址

@ -86,6 +86,17 @@
</a>
</div>
<ul class="nav navbar-top-links navbar-right welcome-message">
<li>
<div style= "padding-top: 6px;
border: 1px dashed white;
width: 60px;height: 40px;
text-align: center;">
<a style="color: white;
font-weight: 900;
font-size: 18px;" href="http://10.100.71.111/">门户
</a>
</div>
</li>
<!--<li><a data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="开发文档" href="http://doc.ruoyi.vip/ruoyi" target="_blank"><i class="fa fa-question-circle"></i> 文档</a></li>
<li><a data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="锁定屏幕" href="#" id="lockScreen"><i class="fa fa-lock"></i> 锁屏</a></li>
<li><a data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="全屏显示" href="#" id="fullScreen"><i class="fa fa-arrows-alt"></i> 全屏</a></li>-->

@ -7,6 +7,8 @@ package com.ruoyi.common.utils.uuid;
*/
public class IdUtils
{
/**
* UUID
*
@ -16,7 +18,17 @@ public class IdUtils
{
return UUID.randomUUID().toString();
}
public static String LongUUID(){
int hashCode = java.util.UUID.randomUUID().toString().hashCode();
if (hashCode <0){
hashCode=-hashCode;
}
// 0 代表前面补充0
// 10 代表长度为10
// d 代表参数为正数型
String format = String.format("%010d", hashCode).substring(0,10);
return format;
}
/**
* UUID线
*

@ -84,11 +84,11 @@
</dependency>
<!-- 单点 SSO -->
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-sso-core</artifactId>
<version>1.1.1</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.xuxueli</groupId>-->
<!-- <artifactId>xxl-sso-core</artifactId>-->
<!-- <version>1.1.1</version>-->
<!-- </dependency>-->
<dependency>
<groupId>cn.hutool</groupId>

@ -65,11 +65,7 @@ public class LogoutFilter extends org.apache.shiro.web.filter.authc.LogoutFilter
String iot_sessionId = CookieUtils.getCookie((HttpServletRequest) request, "iot_sessionid");
Map<String,Object> params = new HashMap<>();
params.put("sessionid",iot_sessionId);
JSONObject parseFromMap = JSONUtil.parseFromMap(params);
String result = HttpRequest.post("http://10.100.71.111/sso/doFilter/scada/logout")
.body(parseFromMap)
.execute()
.body();
Subject subject = getSubject(request, response);
String redirectUrl = getRedirectUrl(request, response, subject);
@ -79,6 +75,20 @@ public class LogoutFilter extends org.apache.shiro.web.filter.authc.LogoutFilter
if (StringUtils.isNotNull(user))
{
String loginName = user.getLoginName();
System.out.println("======================================");
System.out.println("退出-userName:" + loginName);
System.out.println("======================================");
params.put("userName",loginName);
JSONObject parseFromMap = JSONUtil.parseFromMap(params);
try {
String result = HttpRequest.post("http://10.100.71.111/sso/doFilter/scada/logout")
.body(parseFromMap)
.execute()
.body();
}catch (Exception e){
log.error("logout fail.",e);
}
// 记录用户退出日志
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success")));
// 清理缓存

@ -4,10 +4,19 @@ import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.ruoyi.common.utils.CookieUtils;
import com.ruoyi.common.utils.StringUtils;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.session.Session;

@ -2,6 +2,8 @@ package com.ruoyi.system.mapper;
import java.util.List;
import com.ruoyi.system.domain.SysUserOnline;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
/**
* 线
@ -49,4 +51,19 @@ public interface SysUserOnlineMapper
* @return
*/
public List<SysUserOnline> selectOnlineByExpired(String lastAccessTime);
/**
* IP
*
* @param sessionId ID
* @return 线
* @Param("os")String os,@Param("browser")String browser
*/
@Select("select sessionId, login_name as loginName, dept_name as deptName, ipaddr, "
+ "login_location as loginLocation, browser, os, status, start_timestamp as startTimestamp"
+ ", last_access_time as lastAccessTime, expire_time as expireTime" +
" from sys_user_online where login_name=#{loginName} and ipaddr=#{ipaddr}")
public List<SysUserOnline> SysUserOnlineList(@Param("loginName")String loginName, @Param("ipaddr")String ipaddr);
}

Loading…
Cancel
Save