首页 > 编程语言 > 详细

spring securtty 学习(一)spring boot 中开启spring securtty

时间:2019-03-10 12:42:07      阅读:164      评论:0      收藏:0      [点我收藏+]

简单来说,spring security提供Authentication认证和Authorization授权管理,其开发复杂度、学习难度都比shiro难,我们既然钟情与spring再难也要学习,搞一搞。

pom.xml 加入security maven 依赖

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)  //  启用方法级别的权限认证
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override 
    protected void configure(HttpSecurity http) throws Exception {
      http.formLogin() // 表单登录 // http.httpBasic() // HTTP Basic  
        .and() 
        .authorizeRequests() // 授权配置 
        .anyRequest() // 所有请求 
        .authenticated(); // 都需要认证  
   }
 }

 简单测试一下

@RestController
public class SecurityController {
    @GetMapping("hello")
    public String hello() {
        return "hello spring security";
    }
}

 

 

spring securtty 学习(一)spring boot 中开启spring securtty

原文:https://www.cnblogs.com/yuiqng/p/10504876.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!