Spring Security filter --samples [xml and java configurations]
This commit is contained in:
parent
31d72d7cfa
commit
05ba4f173e
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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>
|
Loading…
Reference in New Issue