登录过滤

beetlsql3-dev
Mlxa0324 2 years ago
parent 6497f4e72e
commit ad639dbd95

@ -1,4 +1,4 @@
package cn.jlw.cors; package cn.jlw.filter;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;

@ -0,0 +1,40 @@
package cn.jlw.filter;
import com.ibeetl.admin.core.service.CorePlatformService;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
@WebFilter(value = "/*", filterName = "loginFilter")
public class LoginFilter implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
//1.强制转换
HttpServletRequest request = (HttpServletRequest) req;
//2.获取请求资源路径
String requestURI = request.getRequestURI();
//3.判断是否包含登录相关资源路径,同时排除css,js图片等
if (requestURI.contains("/login.json") || requestURI.matches(".*(/css/|/js/|/fonts/|/plugins/).*")) {
//放行
chain.doFilter(req, resp);
} else {
//4.判断是否登录
Object user = request.getSession().getAttribute(CorePlatformService.ACCESS_CURRENT_USER);
if (user != null) {
//已登录,放行
chain.doFilter(req, resp);
}else {
//未登录,跳转登陆页面
request.getRequestDispatcher("/").forward(request,resp);
}
}
}
public void init(FilterConfig config) throws ServletException {
}
}

@ -1,4 +1,4 @@
package cn.jlw.cors; package cn.jlw.filter;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

@ -16,7 +16,7 @@ import org.springframework.web.WebApplicationInitializer;
@EnableCaching @EnableCaching
@EnableAsync @EnableAsync
@ComponentScan(basePackages= {"cn.jlw","com.ibeetl.admin","com.ibeetl.jlw"}) @ComponentScan(basePackages= {"cn.jlw","com.ibeetl.admin","com.ibeetl.jlw"})
@ServletComponentScan(basePackages = "cn.jlw.cors") @ServletComponentScan(basePackages = "cn.jlw.filter")
public class WebApplication extends SpringBootServletInitializer implements WebApplicationInitializer { public class WebApplication extends SpringBootServletInitializer implements WebApplicationInitializer {
public static void main(String[] args) { public static void main(String[] args) {

Loading…
Cancel
Save