GithubHelp home page GithubHelp logo

springboot_security's Introduction

SpringSecurity做了2件事 用户认证和用户授权

#基于注解的:

 @Secured("ROLE_VIP1")
 需要在主启动类上添加@EnableGlobalMethodSecurity(securedEnabled=true).
 
 @RolesAllowed("ROLE_VIP1")
 需要在主启动类上添加@EnableGlobalMethodSecurity(jsr250Enabled=true).
 
 
 @PreAuthorize("hasRole('ROLE_VIP1')") 用来在方法的调用前进行权限检查或者参数校验
 @PreAuthorize("#request.getParameter('str').length() > 2")
 需要在主启动类上添加@EnableGlobalMethodSecurity(prePostEnabled=true).
 
 @PostAuthorize("returnObject.length() > 2")
 
 @PostFilter("filterObject>2") 对集合类型的参数或返回值进行过滤,spring security将移除对应表达式的结果为false的元素
       filterObject 是使用@PreFilter, @PostFilter时的一个内置表达式,表示集合中的当前对象
 需要在主启动类上添加@EnableGlobalMethodSecurity(prePostEnabled=true).
 
 @PreFilter(filterTarget="ids", value="filterObject%2 == 0") 
      当PreFilter标注的方法拥有多个集合类型的参数时,需要通过filterTarget属性制定当前@PreFilter是针对哪个参数过滤的
      
 上面所有注解一起用,@EnableGlobalMethodSecurity(jsr250Enabled=true, securedEnabled=true, prePostEnabled=true)

#基于资源的应用保护

  1. 自己定义一个config类, 继承WebSecurityConfigurerAdapter
  2. 自定义的config类添加@EnableWebSecurity
  3. 重写用户授权的方法configure(HttpSecurity http)
  4. 重写用户认证的方法configure(AuthenticationManagerBuilder auth)

#JWT 先mark下,有机会了, 再来完成吧~~~

springboot_security's People

Contributors

lyxshike avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.