add:添加免登
This commit is contained in:
@@ -177,6 +177,33 @@ public class StringUtils {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public static String getIp(HttpServletRequest request,Boolean need){
|
||||
String ip = request.getHeader("x-forwarded-for");
|
||||
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
String comma = ",";
|
||||
String localhost = "127.0.0.1";
|
||||
if (ip.contains(comma)) {
|
||||
ip = ip.split(",")[0];
|
||||
}
|
||||
if (localhost.equals(ip)) {
|
||||
// 获取本机真正的ip地址
|
||||
try {
|
||||
ip = InetAddress.getLocalHost().getHostAddress();
|
||||
} catch (UnknownHostException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ip获取详细地址
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.nl.sso.security.satoken;
|
||||
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.modules.common.utils.StringUtils;
|
||||
import org.nl.modules.wql.core.bean.WQLObject;
|
||||
import org.nl.sso.security.dto.CurrentUser;
|
||||
import org.nl.sso.system.domain.User;
|
||||
import org.nl.sso.system.service.RoleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2022/12/9 10:39 上午
|
||||
*/
|
||||
//@Component
|
||||
public class TokenFilter implements Filter {
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
String ip = StringUtils.getIp((HttpServletRequest)request, true);
|
||||
if (ip.equals("192.168.81.122")){
|
||||
Object login = StpUtil.getLoginId(null);
|
||||
if (login == null){
|
||||
JSONObject userInfo = WQLObject.getWQLObject("sys_user").query("user_id = '1'").uniqueResult(0);
|
||||
List<String> permissionList = roleService.getPermissionList(userInfo);
|
||||
CurrentUser user = new CurrentUser();
|
||||
user.setId(userInfo.getLong("user_id"));
|
||||
user.setUsername(userInfo.getString("username"));
|
||||
user.setPreson_name(userInfo.getString("person_name"));
|
||||
user.setUser(userInfo.toJavaObject(User.class));
|
||||
user.setPermissions(permissionList);
|
||||
// SaLoginModel 配置登录相关参数
|
||||
StpUtil.login(userInfo.getLong("user_id"), new SaLoginModel()
|
||||
.setDevice("PC") // 此次登录的客户端设备类型, 用于[同端互斥登录]时指定此次登录的设备类型
|
||||
.setExtra("loginInfo", user) // Token挂载的扩展参数 (此方法只有在集成jwt插件时才会生效)
|
||||
);
|
||||
}
|
||||
}
|
||||
chain.doFilter(request,response);
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ module.exports = {
|
||||
/**
|
||||
* @description token key
|
||||
*/
|
||||
TokenKey: 'NL-LMS-TOEKN',
|
||||
TokenKey: 'Authorization',
|
||||
/**
|
||||
* @description 请求超时时间,毫秒(默认2分钟)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user