zoukankan      html  css  js  c++  java
  • springsecurity入门

    SpringSecurity

    https://docs.spring.io/spring-security/site/docs/current/reference/html5/#prerequisites

    概念

    Spring Security is a framework that provides authentication, authorization, and protection against common attacks. With first class support for both imperative and reactive applications, it is the de-facto standard for securing Spring-based applications.

    Spring Security 是一个提供身份验证、授权和针对常见攻击的保护的框架。凭借对命令式和反应式应用程序的一流支持,它是基于 保护Spring 的应用程序为标准。

    它的核心是一组过滤器链,不同的功能经由不同的过滤器

      org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter //异步方式
      org.springframework.security.web.context.SecurityContextPersistenceFilter //同步方式
      org.springframework.security.web.header.HeaderWriterFilter // 给http响应头(Header)对象添加一些属性,比如X-Frame-Options,X-XSS-Protection*,X-Content-Type-Options。
      org.springframework.security.web.csrf.CsrfFilter //默认开启,用于防止csrf攻击的过滤器
      org.springframework.security.web.authentication.logout.LogoutFilter //处理注销的过滤器
      org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter //对登录post请求中的用户名和密码的校验
     //如果没有配置/login及login page, 系统则会自动配置这两个Filter。
      org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter 
      org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter
      
      org.springframework.security.web.authentication.www.BasicAuthenticationFilter
      org.springframework.security.web.savedrequest.RequestCacheAwareFilter //内部维护了一个RequestCache,用于缓存request请求
      org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter //对ServletRequest进行了一次包装,使得request具有更加丰富的API
      org.springframework.security.web.authentication.AnonymousAuthenticationFilter //匿名身份过滤器
      org.springframework.security.web.session.SessionManagementFilter //和session相关的过滤器
      org.springframework.security.web.access.ExceptionTranslationFilter //异常转换过滤器
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor //决定访问特定路径应该具备的权限

    入门示例

    添加依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

    编写Controller

    @RestController
    public class TestController {
    
        @GetMapping("/test")
        public String test(){
    
            return "Hello Security";
        }
    }
    View Code

    访问地址:http://localhost:8080/test

     

    security有固定的用户名:User

    生成临时密码:

  • 相关阅读:
    关于android中两种service的编写简单总结
    To learn list
    android中如何在系统启动的时候启动自己的service
    service的生命周期以及两种service的差异
    Intent的简单概述
    关于startactivity初始化activity的过程以及activity和window以及view的关系
    android activity生命周期的一张经典图片
    关于Android进程的启动和消亡
    Java基础学习总结(73)——Java最新面试题汇总
    Beetl学习总结(4)——Web集成
  • 原文地址:https://www.cnblogs.com/WarBlog/p/15128700.html
Copyright © 2011-2022 走看看