首页 > 技术文章 > HttpSecurity配置列表

donleo123 2021-03-12 10:33 原文

一、HttpSecurity配置列表

1、openldLogin()  用于基于Openld的脸证
2、headers()  将安全标头添加到响应
3、cors()  配置跨域资源共享( CORS )
4、sessionManagement()  允许配置会话管理
5、portMapper()  允许配置一个PortMapper(HttpSecurity#(getSharedObject(class))),其他提供SecurityConfigurer的对象使用 PortMapper 从 HTTP 重定向到 HTTPS 或者从 HTTPS 重定向到 HTTP。默认情况下,Spring Security使用一个PortMapperImpl映射 HTTP 端口8080到 HTTPS 端口8443,HTTP 端口80到 HTTPS 端口443
6、jee() 配置基于容器的预认证。 在这种情况下,认证由Servlet容器管理
7、x509() 配置基于x509的认证
8、rememberMe 允许配置“记住我”的验证
9、authorizeRequests() 允许基于使用HttpServletRequest限制访问
10、requestCache() 允许配置请求缓存
11、exceptionHandling() 允许配置错误处理
12、securityContext() 在HttpServletRequests之间的SecurityContextHolder上设置SecurityContext的管理。 当使用WebSecurityConfigurerAdapter时,这将自动应用
13、servletApi() 将HttpServletRequest方法与在其上找到的值集成到SecurityContext中。 当使用WebSecurityConfigurerAdapter时,这将自动应用
14、csrf()  添加 CSRF 支持,使用WebSecurityConfigurerAdapter时,默认启用
15、logout() 添加退出登录支持。当使用WebSecurityConfigurerAdapter时,这将自动应用。默认情况是,访问URL”/ logout”,使HTTP Session无效来清除用户,清除已配置的任何#rememberMe()身份验证,清除SecurityContextHolder,然后重定向到”/login?success”
16、anonymous() 允许配置匿名用户的表示方法。 当与WebSecurityConfigurerAdapter结合使用时,这将自动应用。 默认情况下,匿名用户将使用org.springframework.security.authentication.AnonymousAuthenticationToken表示,并包含角色 “ROLE_ANONYMOUS”
17、formLogin() 指定支持基于表单的身份验证。如果未指定FormLoginConfigurer#loginPage(String),则将生成默认登录页面
18、oauth2Login() 根据外部OAuth 2.0或OpenID Connect 1.0提供程序配置身份验证
19、requiresChannel() 配置通道安全。为了使该配置有用,必须提供至少一个到所需信道的映射
20、httpBasic() 配置 Http Basic 验证
21、addFilterAt() 在指定的Filter类的位置添加过滤器

二、保护URL常用的方法有(authorizeRequests()):

1、authenticated()  保护URL,需要用户登录
2、permitAll() 指定URL无需保护,一般应用与静态资源文件
3、hasRole(String role) 限制单个角色访问,角色将被增加 “ROLE_” .所以”ADMIN” 将和 “ROLE_ADMIN”进行比较.
4、hasAuthority(String authority) 限制单个权限访问
5、hasAnyRole(String… roles)允许多个角色访问.
6、hasAnyAuthority(String… authorities) 允许多个权限访问.
7、access(String attribute) 该方法使用 SpEL表达式, 所以可以创建复杂的限制.
8、hasIpAddress(String ipaddressExpression) 限制IP地址或子网

 

推荐阅读