網絡配置的核心類,至關於xml中的註解html
<sec:http></sec:http>
當使用WebSecurityConfigurationAdapter的時候,會從父類繼承一個默認的AuthenticationManager.web
@EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class MySecurityConfig extends WebSecurityConfigurerAdapter { @Bean @Override public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); } }
程序有的時候會報`No bean named 'org.springframework.security.authenticationManager' is defined
使用上面的方法有的時候能夠解決。spring
在WebSecurityConfigurerAdapter中會有經常使用的配置:json
在 configure(HttpSecurity)中進行配置的時候,必定要把要求比較寬鬆的放在前面,要求少的放在後面。網絡
http.authorizeRequests().antMatchers("/login").permitAll(); http.authorizeRequests().antMatchers("/", "/home").access("hasRole('USER')") .antMatchers("/admin/**").access("hasRole('ADMIN')") .antMatchers("/db/**").access("hasRole('ADMIN') and hasRole('DBA')") .and().formLogin().loginPage("/login").loginProcessingUrl("/login").successHandler(customSuccessHandler) .and().exceptionHandling().accessDeniedPage("/Access_Denied");
上面的配置還有一個隱藏的功能就是把默認的login的form表格換成了本身寫的login.jsp或者是login.html。具體看web中使用的框架。框架
NameSpace:sec:http</sec:http>等。ssh
當咱們在使用NameSpace時,Spring Security是會自動爲咱們創建對應的FilterChain以及其中的Filter。但有時咱們可能須要添加咱們本身的Filter到FilterChain,又或者是由於某些特性須要本身顯示的定義Spring Security已經爲咱們提供好的Filter,而後再把它們添加到FilterChain。使用NameSpace時添加Filter到FilterChain是經過http元素下的custom-filter元素來定義的。定義custom-filter時須要咱們經過ref屬性指定其對應關聯的是哪一個Filter,此外還須要經過position、before或者after指定該Filter放置的位置。誠如在上一節《Filter順序》中所提到的那樣,Spring Security對FilterChain中Filter順序是有嚴格的規定的。Spring Security對那些內置的Filter都指定了一個別名,同時指定了它們的位置。咱們在定義custom-filter的position、before和after時使用的值就是對應着這些別名所處的位置。如position=」CAS_FILTER」就表示將定義的Filter放在CAS_FILTER對應的那個位置,before=」CAS_FILTER」就表示將定義的Filter放在CAS_FILTER以前,after=」CAS_FILTER」就表示將定義的Filter放在CAS_FILTER以後。此外還有兩個特殊的位置能夠指定,FIRST和LAST,分別對應第一個和最後一個Filter,如你想把定義好的Filter放在最後,則可使用after=」LAST」。jsp