SecurityMockMvcConfigurer$DelegateFilter is not null-safe
This commit adds null-check to getter method, so instead of NPE an IllegalStateException will be thrown with additional details. Fixes gh-7745
This commit is contained in:
parent
6ec5f777d1
commit
1f1ddeb025
|
@ -118,38 +118,44 @@ final class SecurityMockMvcConfigurer extends MockMvcConfigurerAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
Filter getDelegate() {
|
Filter getDelegate() {
|
||||||
return this.delegate;
|
Filter result = this.delegate;
|
||||||
|
if (result == null) {
|
||||||
|
throw new IllegalStateException("delegate cannot be null. Ensure a Bean with the name "
|
||||||
|
+ BeanIds.SPRING_SECURITY_FILTER_CHAIN
|
||||||
|
+ " implementing Filter is present or inject the Filter to be used.");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(FilterConfig filterConfig) throws ServletException {
|
public void init(FilterConfig filterConfig) throws ServletException {
|
||||||
this.delegate.init(filterConfig);
|
getDelegate().init(filterConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
this.delegate.doFilter(request, response, chain);
|
getDelegate().doFilter(request, response, chain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
this.delegate.destroy();
|
getDelegate().destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return this.delegate.hashCode();
|
return getDelegate().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return this.delegate.equals(obj);
|
return getDelegate().equals(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.delegate.toString();
|
return getDelegate().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue