栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

HttpSecurity,WebSecurity和AuthenticationManagerBuilder

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

HttpSecurity,WebSecurity和AuthenticationManagerBuilder

configure(AuthenticationManagerBuilder)用于通过允许轻松添加AuthenticationProviders来建立身份验证机制:例如,以下内容定义了具有内置“用户”和“管理员”登录名的内存中身份验证。

public void configure(AuthenticationManagerBuilder auth) {    auth        .inMemoryAuthentication()        .withUser("user")        .password("password")        .roles("USER")    .and()        .withUser("admin")        .password("password")        .roles("ADMIN","USER");}

configure(HttpSecurity)允许基于选择匹配在资源级别配置基于Web的安全性-例如,以下示例将以/ admin /开头的URL限制为具有ADMIN角色的用户,并声明需要使用其他任何URL成功认证。

protected void configure(HttpSecurity http) throws Exception {    http        .authorizeRequests()        .antMatchers("/admin/**").hasRole("ADMIN")        .anyRequest().authenticated()}

configure(WebSecurity)用于影响全局安全性的配置设置(忽略资源,设置调试模式,通过实现自定义防火墙定义拒绝请求)。例如,以下方法将导致以/ resources /开头的任何请求都被忽略,以进行身份​​验证。

public void configure(WebSecurity web) throws Exception {    web        .ignoring()        .antMatchers("/resources/**");}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/415087.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号