@ -32,13 +32,15 @@ import org.springframework.util.ReflectionUtils;
@@ -32,13 +32,15 @@ import org.springframework.util.ReflectionUtils;
/ * *
* A < code > Filter < / code > which populates the < code > ServletRequest < / code > with a new request wrapper . < p > Several
* request wrappers are included with the framework . The simplest version is { @link
* SecurityContextHolderAwareRequestWrapper } . A more complex and powerful request wrapper is { @link
* org . springframework . security . wrapper . SavedRequestAwareWrapper } . The latter is also the default . < / p >
* < p > To modify the wrapper used , call { @link # setWrapperClass ( Class ) } . < / p >
* < p > Any request wrapper configured for instantiation by this class must provide a public constructor that
* accepts two arguments , being a < code > HttpServletRequest < / code > and a < code > PortResolver < / code > . < / p >
* A < code > Filter < / code > which populates the < code > ServletRequest < / code > with a new request wrapper .
* Several request wrappers are included with the framework . The simplest version is { @link
* SecurityContextHolderAwareRequestWrapper } . A more complex and powerful request wrapper is
* { @link SavedRequestAwareWrapper } . The latter is also the default .
* < p >
* To modify the wrapper used , call { @link # setWrapperClass ( Class ) } .
* < p >
* Any request wrapper configured for instantiation by this class must provide a public constructor that
* accepts two arguments , being a < code > HttpServletRequest < / code > and a < code > PortResolver < / code > .
*
* @author Orlando Garcia Carmona
* @author Ben Alex
@ -47,8 +49,8 @@ import org.springframework.util.ReflectionUtils;
@@ -47,8 +49,8 @@ import org.springframework.util.ReflectionUtils;
public class SecurityContextHolderAwareRequestFilter extends SpringSecurityFilter {
//~ Instance fields ================================================================================================
private Class wrapperClass = SavedRequestAwareWrapper . class ;
private Constructor constructor ;
private Class < ? extends HttpServletRequest > wrapperClass = SavedRequestAwareWrapper . class ;
private Constructor < ? extends HttpServletRequest > constructor ;
private PortResolver portResolver = new PortResolverImpl ( ) ;
private String rolePrefix ;
@ -59,6 +61,7 @@ public class SecurityContextHolderAwareRequestFilter extends SpringSecurityFilte
@@ -59,6 +61,7 @@ public class SecurityContextHolderAwareRequestFilter extends SpringSecurityFilte
this . portResolver = portResolver ;
}
@SuppressWarnings ( "unchecked" )
public void setWrapperClass ( Class wrapperClass ) {
Assert . notNull ( wrapperClass , "WrapperClass required" ) ;
Assert . isTrue ( HttpServletRequest . class . isAssignableFrom ( wrapperClass ) , "Wrapper must be a HttpServletRequest" ) ;
@ -70,28 +73,23 @@ public class SecurityContextHolderAwareRequestFilter extends SpringSecurityFilte
@@ -70,28 +73,23 @@ public class SecurityContextHolderAwareRequestFilter extends SpringSecurityFilte
this . rolePrefix = rolePrefix . trim ( ) ;
}
protected void doFilterHttp ( HttpServletRequest request , HttpServletResponse response , FilterChain chain ) throws IOException , ServletException {
protected void doFilterHttp ( HttpServletRequest request , HttpServletResponse response , FilterChain chain ) throws IOException , ServletException {
if ( ! wrapperClass . isAssignableFrom ( request . getClass ( ) ) ) {
if ( constructor = = null ) {
try {
constructor = wrapperClass . getConstructor (
new Class [ ] { HttpServletRequest . class , PortResolver . class , String . class } ) ;
} catch ( Exception ex ) {
ReflectionUtils . handleReflectionException ( ex ) ;
try {
if ( constructor = = null ) {
constructor = wrapperClass . getConstructor ( HttpServletRequest . class , PortResolver . class , String . class ) ;
}
}
try {
request = ( HttpServletRequest ) constructor . newInstance ( new Object [ ] { request , portResolver , rolePrefix } ) ;
request = constructor . newInstance ( request , portResolver , rolePrefix ) ;
} catch ( Exception ex ) {
ReflectionUtils . handleReflectionException ( ex ) ;
}
}
chain . doFilter ( request , response ) ;
}
}
public int getOrder ( ) {
return FilterChainOrder . SERVLET_API_SUPPORT_FILTER ;
}
public int getOrder ( ) {
return FilterChainOrder . SERVLET_API_SUPPORT_FILTER ;
}
}