首页>代码>基于SpringBoot+Vue实现的小区物业管理系统>/em_server/src/main/java/com/kum/config/SecurityConfig.java
package com.kum.config;

import com.kum.filter.AuthenticationLoginFilter;
import com.kum.handler.AuthenticationEntryPointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.filter.CorsFilter;

import javax.annotation.Resource;

/**
 * @version V1.0
 * @Package com.kum.config
 * @auhter SunGuangJie
 * @date 2021/2/9-12:15 PM
 */
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {


    /**
     * 认证失败处理类
     */
    @Autowired
    private AuthenticationEntryPointImpl unauthorizedHandler;


    @Resource
    private UserDetailsService userDetailsService;

    @Bean
    public BCryptPasswordEncoder bCryptPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());

    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
        http
                .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                .authorizeRequests()
                .anyRequest().permitAll();
        http.addFilterAfter(new AuthenticationLoginFilter(authenticationManagerBean()), UsernamePasswordAuthenticationFilter.class);
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers(
                "/system/**/list",
                "/login/**", "/system/user/admin/list/",
                "/system/user/isAdmin");
    }

    @Bean
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

}
最近下载更多
luhong  LV4 6月11日
萌萌哒的泰迪熊  LV4 5月8日
陈小灏  LV18 2月25日
102404426  LV8 2月24日
qq970040477  LV24 2024年12月5日
citybird  LV4 2024年11月18日
sodkj123  LV16 2024年10月8日
ma406805131  LV19 2024年5月7日
jsjsjsjsbdbshns  LV1 2024年4月27日
860421  LV3 2024年4月18日
最近浏览更多
短巷拥猫  LV12 6月18日
ES大兵  LV11 6月12日
luhong  LV4 6月11日
yifeng868  LV9 6月10日
Dominick  LV14 6月3日
lkke23047  LV1 5月26日
koteilbs  LV6 5月16日
lilimyeclipse  LV6 5月11日
萌萌哒的泰迪熊  LV4 5月8日
tongguan00  LV2 4月1日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友