使用SpringSecurity定义的登录认证

 

太久没有发过博客,总结一波SpringSecurity登录认证,记录每次的学习体验。。。。。。。。。。

 实现WebSecurityConfigurerAdapter 配置安全框架

//@EnableWebSecurity JavaConfig 配置类到 IoC 容器

@EnableWebSecurity

//  启用方法级别的权限认证
@EnableGlobalMethodSecurity(prePostEnabled = true)

 public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
  

1配置静态资源放行名单,可以省略。
configure(httpSecurity http)配置静态资源放行路径

    @Override

    public void configure(WebSecurity web) throws Exception {

        super.configure(web);

    }
2】配置Security安全认证请求
@Override

    protected void configure(HttpSecurity http) throws Exception {

        super.configure(http);

    }

 

     3身份认证接口

     可以实现多种认证,如web登录认证,微信登录认证,APP认证。。。。。

    @Override

    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

        super.configure(auth);

    }

}
 

1】配置静态资源放行名单,可以省略。

也可以在在configure(httpSecurity http)配置静态资源放行路径

//放行静态资源

        web.ignoring().antMatchers(HttpMethod.GET,

                        "/static/**",

                        "/PearAdmin/**",

                        "/**/*.html",

                        "/**/*.css",

                        "/**/*.js");
 

2】配置Security安全认证请求

(1)配置通用

//禁用页面镶嵌frame劫持安全协议  // 防止iframe 造成跨域

http.headers().frameOptions().disable();

//关闭csrf 跨站请求防护

http.csrf().disable();

// 禁用缓存

http.headers().cacheControl();

//开启自动配置的注销功能注销成功以后来到首页

http.logout().logoutSuccessUrl("/admin/login");

//无权访问 JSON 格式的数据

http.exceptionHandling()
//当访问接口没有权限触发响应事件
.accessDeniedHandler(accessDeniedHandler
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值