首页>代码>spring boot+spring mvc+mybatis+thymeleaf整合开发学生成绩信息管理系统>/src/main/java/com/zhengyuan/liunao/config/WebSecurityConfig.java
package com.zhengyuan.liunao.config;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

@Configuration
public class WebSecurityConfig extends WebMvcConfigurerAdapter{
	public static final String SESSION_KEY="name";
	 @Bean
	    public SecurityInterceptor getSecurityInterceptor(){
	        return  new SecurityInterceptor();
	    }
	    @Override
	    public  void addInterceptors(InterceptorRegistry registry){
	        InterceptorRegistration addInterceptor = registry.addInterceptor(getSecurityInterceptor());
	 
	        //排除配置
	        addInterceptor.excludePathPatterns("/Sys/loginView","/Sys/dealLogin","/Sys/css/**","/Sys/fonts/**","/Sys/images/**","/Sys/js/**","/Sys/lau/**","/Sys/lib/**");
	        //拦截配置
	        addInterceptor.addPathPatterns("/**/**");
	    }
	 
	    private class SecurityInterceptor extends HandlerInterceptorAdapter {
	        @Override
	        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)throws IOException{
	            HttpSession session = request.getSession(true);
	            //判断是否已有该用户登录的session
	            if(session.getAttribute("name") !=null){
	                return  true;
	            }
	            //跳转到登录页
	            String url = "/Sys/loginView";
	            response.sendRedirect(url);
	            return false;
	        }
	    }


}
最近下载更多
都天星泪  LV2 3月24日
微信网友_6795583448387584  LV2 2023年12月28日
admin_z  LV22 2023年12月22日
pangzhihui  LV12 2023年12月20日
五折也挺好的  LV13 2023年9月22日
SumJFor  LV4 2023年7月30日
jlmarket  LV22 2023年6月18日
tianshi  LV7 2023年6月13日
若干个太热  LV1 2023年6月9日
sandihha  LV9 2023年4月24日
最近浏览更多
玖零定制问题修复  LV34 4月4日
qwe请问 3月31日
暂无贡献等级
都天星泪  LV2 3月24日
3320151533  LV1 1月7日
zzzzzzz09173 2023年12月27日
暂无贡献等级
微信网友_6795583448387584  LV2 2023年12月26日
WBelong  LV7 2023年12月25日
admin_z  LV22 2023年12月22日
XJH939  LV1 2023年12月21日
pangzhihui  LV12 2023年12月20日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友