Spring Security filter --samples [xml and java configurations]

This commit is contained in:
Andrew Tobilko 2016-10-25 02:06:22 +03:00
parent 31d72d7cfa
commit 05ba4f173e
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>