一、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地址或子網