Move custom filter examples (#1465)
* Move custom filter examples * Remove unused README entry
This commit is contained in:
parent
faea5eb510
commit
eab4a5f8ca
|
@ -7,7 +7,6 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
|
|||
|
||||
### Relevant Article:
|
||||
- [Spring Security Basic Authentication](http://www.baeldung.com/spring-security-basic-authentication)
|
||||
- [Writing a Custom Filter in Spring Security](http://www.baeldung.com/spring-security-custom-filter)
|
||||
|
||||
|
||||
### Notes
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
<intercept-url pattern="/**" access="isAuthenticated()"/>
|
||||
|
||||
<http-basic entry-point-ref="myBasicAuthenticationEntryPoint"/>
|
||||
|
||||
<custom-filter after="BASIC_AUTH_FILTER" ref="myFilter" />
|
||||
</http>
|
||||
|
||||
<authentication-manager>
|
||||
|
@ -22,7 +20,4 @@
|
|||
</user-service>
|
||||
</authentication-provider>
|
||||
</authentication-manager>
|
||||
|
||||
<beans:bean id="myFilter" class="org.baeldung.security.filter.CustomFilter"/>
|
||||
|
||||
</beans:beans>
|
|
@ -9,3 +9,4 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
|
|||
- [RestTemplate with Basic Authentication in Spring](http://www.baeldung.com/2012/04/16/how-to-use-resttemplate-with-basic-authentication-in-spring-3-1)
|
||||
- [HttpClient Timeout](http://www.baeldung.com/httpclient-timeout)
|
||||
- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl)
|
||||
- [Writing a Custom Filter in Spring Security](http://www.baeldung.com/spring-security-custom-filter)
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.security.filter;
|
||||
package org.baeldung.filter;
|
||||
|
||||
import org.springframework.web.filter.GenericFilterBean;
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package org.baeldung.security.filter.configuration;
|
||||
package org.baeldung.filter;
|
||||
|
||||
import org.baeldung.security.basic.MyBasicAuthenticationEntryPoint;
|
||||
import org.baeldung.security.filter.CustomFilter;
|
||||
import org.baeldung.security.RestAuthenticationEntryPoint;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
|
@ -14,17 +13,28 @@ import org.springframework.security.web.authentication.www.BasicAuthenticationFi
|
|||
@EnableWebSecurity
|
||||
public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
private MyBasicAuthenticationEntryPoint authenticationEntryPoint;
|
||||
@Autowired private RestAuthenticationEntryPoint authenticationEntryPoint;
|
||||
|
||||
@Autowired
|
||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.inMemoryAuthentication().withUser("user1").password("user1Pass").authorities("ROLE_USER");
|
||||
auth
|
||||
.inMemoryAuthentication()
|
||||
.withUser("user1")
|
||||
.password("user1Pass")
|
||||
.authorities("ROLE_USER");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.authorizeRequests().antMatchers("/securityNone").permitAll().anyRequest().authenticated().and().httpBasic().authenticationEntryPoint(authenticationEntryPoint);
|
||||
http
|
||||
.authorizeRequests()
|
||||
.antMatchers("/securityNone")
|
||||
.permitAll()
|
||||
.anyRequest()
|
||||
.authenticated()
|
||||
.and()
|
||||
.httpBasic()
|
||||
.authenticationEntryPoint(authenticationEntryPoint);
|
||||
|
||||
http.addFilterAfter(new CustomFilter(), BasicAuthenticationFilter.class);
|
||||
}
|
Loading…
Reference in New Issue