zoukankan      html  css  js  c++  java
  • springboot学习总结(八)Spring security配置

    (一)配置类

    Spring security的配置和Spring MVC的配置类似,只需在一个配置类上注解@EnableWebSecurity(Springboot项目可以不用),并让这个类继承WebSecurityConfigurerAdapter。

    @Configuration
    @EnableWebSecurity
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    
        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            super.configure(auth);
        }
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            super.configure(http);
        }
    
        @Override
        public void configure(WebSecurity web) throws Exception {
            super.configure(web);
        }
    }
    

      (二)用户认证

    通过实现UserDetailsService来实现

    @Service
    public class CustomUserService implements UserDetailsService {
    
        @Autowired
        SysUserRepository sysUserRepository;
    
        @Override
        public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
            SysUser user = sysUserRepository.findByUsername(s);
            if (user == null) {
                throw new UsernameNotFoundException("用户名不存在");
            }
            return user;
        }
    }
    

      (三)请求&授权

    Spring security通过重写

    protected void configure(HttpSecurity http) 
    

      这个方法来实现请求拦截的。

    (四)定制登录行为

    通过重写

    protected void configure(HttpSecurity http) 
    

      这个方法(和上面是同一个方法)来定制登录行为

  • 相关阅读:
    [netty4][netty-buffer]netty之池化buffer
    [netty4][netty-transport]netty之nio传输层
    JMX基本概念
    《JVM G1源码分析和调优》读书笔记
    clients-producer-网络处理与请求响应对接部分
    clients-producer-组包发送消息
    kafka-clients 1.0 高阶API消费消息(未完)
    MetadataCache更新
    副本同步
    将.py文件装成这执行文件.exe
  • 原文地址:https://www.cnblogs.com/vincentren/p/10739569.html
Copyright © 2011-2022 走看看