Merge pull request #771 from andrewtobilko/master

Writing a Custom Filter in Spring Security
This commit is contained in:
Prashant Khanal 2016-10-29 09:46:55 -07:00 committed by GitHub
commit 80cd804802
3 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,18 @@
package org.baeldung.security.filter;
import org.springframework.web.filter.GenericFilterBean;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
public class CustomFilter extends GenericFilterBean {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
}
}

View File

@ -0,0 +1,17 @@
package org.baeldung.security.filter.configuration;
import org.baeldung.security.filter.CustomFilter;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
@Configuration
public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.addFilterAfter(new CustomFilter(), BasicAuthenticationFilter.class);
}
}

View File

@ -12,6 +12,7 @@
<http-basic entry-point-ref="myBasicAuthenticationEntryPoint"/>
<custom-filter after="BASIC_AUTH_FILTER" ref="myFilter" />
</http>
<authentication-manager>
@ -22,4 +23,6 @@
</authentication-provider>
</authentication-manager>
<beans:bean id="myFilter" class="org.baeldung.security.filter.CustomFilter"/>
</beans:beans>