接口 HttpSecurityAware
-
public interface HttpSecurityAware对 WebSecurityConfigurerAdapter 的扩展,使其能跨模块的灵活的添加HttpSecurity配置,WebSecurity配置,AuthenticationManagerBuilder配置.
注意:
1. 需要要在 WebSecurityConfigurerAdapter#configure(http) 方法中放在最后处理的配置。实现postConfigure(HttpSecurity http)方法。
2. 需要要在 WebSecurityConfigurerAdapter#configure(http) 方法中放在前面处理的配置。实现preConfigure(HttpSecurity http)方法。
3. WebSecurityConfigurerAdapter 多个配置类继承此类是会报错,且 authorizeRequests 配置时候要 authorizeRequests().anyRequest().authenticate 放到最后,不然在之后配置的都不会生效。实现getAuthorizeRequestMap()方法。
最终在:SecurityCoreAutoConfigurer中配置.- 版本:
- V1.0 Created by 2020/5/12 12:22
- 作者:
- YongWu zheng
-
-
字段概要
字段 修饰符和类型 字段 说明 static StringACCESSstatic StringANONYMOUSstatic StringAUTHENTICATEDstatic StringDENY_ALLstatic StringFULLY_AUTHENTICATEDstatic StringHAS_ANY_AUTHORITYstatic StringHAS_ANY_ROLEstatic StringHAS_AUTHORITYstatic StringHAS_IP_ADDRESSstatic StringHAS_ROLEstatic StringPERMIT_ALLstatic StringREMEMBER_ME
-
方法概要
所有方法 实例方法 抽象方法 默认方法 修饰符和类型 方法 说明 voidconfigure(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder auth)Used by the default implementation ofWebSecurityConfigurerAdapter#authenticationManager()to attempt to obtain anAuthenticationManager.voidconfigure(org.springframework.security.config.annotation.web.builders.WebSecurity web)Override this method to configureWebSecurity.Map<String,Map<UriHttpMethodTuple,Set<String>>>getAuthorizeRequestMap()因为 authorizeRequests 配置时候要 authorizeRequests().anyRequest().authenticate 放到最后,
所以这里临时把 权限与 uri 放入 map 给主配置器处理.
最终在SecurityCoreAutoConfigurer中configure(HttpSecurity)方法中配置, return 可以为 null 值.default voidpermitUrlFillingPermitAllMap(String permitUrl, Map<UriHttpMethodTuple,Set<String>> permitAllMap)permitUrl 注入到 permitAllMapdefault voidpermitUrlsFillingPermitAllMap(Set<String> permitUrls, Map<UriHttpMethodTuple,Set<String>> permitAllMap)permitUrls 注入到 permitAllMapvoidpostConfigure(org.springframework.security.config.annotation.web.builders.HttpSecurity http)需要要在 WebSecurityConfigurerAdapter#configure(http) 方法中放在最后处理的配置。voidpreConfigure(org.springframework.security.config.annotation.web.builders.HttpSecurity http)需要要在 WebSecurityConfigurerAdapter#configure(http) 方法中放在前面处理的配置。
-
-
-
方法详细资料
-
configure
void configure(org.springframework.security.config.annotation.web.builders.WebSecurity web)
Override this method to configureWebSecurity. For example, if you wish to ignore certain requests. Endpoints specified in this method will be ignored by Spring Security, meaning it will not protect them from CSRF, XSS, Clickjacking, and so on. Instead, if you want to protect endpoints against common vulnerabilities, then seeWebSecurityConfigurerAdapter#configure(HttpSecurity)and theHttpSecurity.authorizeRequests()configuration method.- 参数:
web- theWebSecurityto use
-
configure
void configure(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder auth) throws ExceptionUsed by the default implementation ofWebSecurityConfigurerAdapter#authenticationManager()to attempt to obtain anAuthenticationManager. If overridden, theAuthenticationManagerBuildershould be used to specify theAuthenticationManager.The
WebSecurityConfigurerAdapter#authenticationManagerBean()method can be used to expose the resultingAuthenticationManageras a Bean. TheWebSecurityConfigurerAdapter#userDetailsServiceBean()can be used to expose the last populatedUserDetailsServicethat is created with theAuthenticationManagerBuilderas a Bean. TheUserDetailsServicewill also automatically be populated onAbstractConfiguredSecurityBuilder.getSharedObject(Class)for use with otherSecurityContextConfigurer(i.e. RememberMeConfigurer )For example, the following configuration could be used to register in memory authentication that exposes an in memory
UserDetailsService:@Override protected void configure(AuthenticationManagerBuilder auth) { auth // enable in memory based authentication with a user named // "user" and "admin" .inMemoryAuthentication().withUser("user").password("password").roles("USER").and() .withUser("admin").password("password").roles("USER", "ADMIN"); } // Expose the UserDetailsService as a Bean @Bean @Override public UserDetailsService userDetailsServiceBean() throws Exception { return super.userDetailsServiceBean(); }- 参数:
auth- theAuthenticationManagerBuilderto use- 抛出:
Exception- Exception
-
preConfigure
void preConfigure(org.springframework.security.config.annotation.web.builders.HttpSecurity http) throws Exception- 参数:
http- HttpSecurity- 抛出:
Exception- exception
-
postConfigure
void postConfigure(org.springframework.security.config.annotation.web.builders.HttpSecurity http) throws Exception- 参数:
http- HttpSecurity- 抛出:
Exception- exception
-
getAuthorizeRequestMap
Map<String,Map<UriHttpMethodTuple,Set<String>>> getAuthorizeRequestMap()
因为 authorizeRequests 配置时候要 authorizeRequests().anyRequest().authenticate 放到最后,
所以这里临时把 权限与 uri 放入 map 给主配置器处理.
最终在SecurityCoreAutoConfigurer中configure(HttpSecurity)方法中配置, return 可以为 null 值.- 返回:
- authorizeRequestMap
==key== 为权限类型(PERMIT_ALL,DENY_ALL,ANONYMOUS,AUTHENTICATED,FULLY_AUTHENTICATED,REMEMBER_ME,ACCESS,HAS_ROLE,HAS_ANY_ROLE,HAS_AUTHORITY,HAS_ANY_AUTHORITY,HAS_IP_ADDRESS);
==value== 为Map(Map<String, Set<String>>)的
=key= 为 UriHttpMethodTuple,
=value= 为 role/authority/ip 的 Set; 当 authorizeRequestMap 的 ==key== 为HAS_ROLE,HAS_ANY_ROLE/HAS_AUTHORITY/HAS_ANY_AUTHORITY/HAS_IP_ADDRESS时, set 不为 null,
当 authorizeRequestMap 的 ==key== 为PERMIT_ALL/DENY_ALL/ANONYMOUS/AUTHENTICATED/FULLY_AUTHENTICATED/@link #REMEMBER_ME}/ACCESS时, set 可以为 null).
-
permitUrlsFillingPermitAllMap
default void permitUrlsFillingPermitAllMap(@NonNull Set<String> permitUrls, @NonNull Map<UriHttpMethodTuple,Set<String>> permitAllMap)permitUrls 注入到 permitAllMap- 参数:
permitUrls- permitUrls 在 application.yml 配置文件上的 url(带 HttpMethod 后缀; 用 : 分隔)permitAllMap- permitAllMap
-
permitUrlFillingPermitAllMap
default void permitUrlFillingPermitAllMap(@NonNull String permitUrl, @NonNull Map<UriHttpMethodTuple,Set<String>> permitAllMap)permitUrl 注入到 permitAllMap- 参数:
permitUrl- permitUrl 在 application.yml 配置文件上的 url(带 HttpMethod 后缀; 用 : 分隔)permitAllMap- permitAllMap
-
-