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)

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

原文地址:https://www.cnblogs.com/vincentren/p/10739569.html

时间: 2024-08-30 06:35:26

springboot学习总结(八)Spring security配置的相关文章

Spring Security 配置实例

这几天学习了一下Spring Security3.1,从官网下载了Spring Security3.1版别进行操练,通过屡次测验才摸清了其间的一些原理.自己不才,希望能协助大家.还有,这次我第2次写博客啊,文体不是很行.希望能让观看者不发生疲乏的感受,我现已心满意足了.一.数据库构造     先来看一下数据库构造,选用的是根据人物-资本-用户的权限办理规划.(MySql数据库)    为了节约华章,只对对比重要的字段进行注释.    1.用户表Users    CREATE TABLE `use

SpringBoot学习(二)—— springboot快速整合使用spring security组

Spring Security 简介 spring security的核心功能为认证(Authentication),授权(Authorization),即认证用户是否能访问该系统,和授权用户可以在系统中进行哪些操作. 引入spring security组件 在 pom.xml 中加入 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starte

spring mvc 和spring security配置 web.xml设置

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"          xsi:schemaLocation="http://xmlns.jcp.o

SpringBoot学习--04SpringBoot整合Mybatis(上)(配置mybatis generator,PageHelper)

陆陆续续又忙了几天,继续写. 本篇仿照着优秀的文章的书写,加上自己的理解和踩过的坑,原文地址:https://www.jianshu.com/p/5cd772c07041?utm_campaign=haruki&utm_content=note&utm_medium=reader_share&utm_source=weixin 环境/版本一览: 开发工具:eclipse springboot: 2.0.1.RELEASE jdk:1.8.0_40 maven:3.3.9 额外功能:

Springboot学习~7:SpringMVC自动配置

Spring MVC auto-configuration Spring Boot 自动配置好了SpringMVC 以下是SpringBoot对SpringMVC的默认配置:==(WebMvcAutoConfiguration)== Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans. 自动配置了ViewResolver(视图解析器:根据方法的返回值得到视图对象(View),视图对象决定如何渲染(转

spring mvc 和spring security配置 spring-servlet.xml和spring-security.xml设置

spring-servlet.xml配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xmlns:mvc="htt

spring mvc ,spring security配置 spring-servlet.xml和spring-security.xml设置

spring-servlet.xml配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xmlns:mvc="htt

spring security配置详解

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"    xmlns:sec="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchem

WebFlux Spring Security配置

最小化可运行配置 package com.terwergreen.bugucms.config; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; i