Skip to content

Commit 1f1ddeb

Browse files
dadikovirwinch
authored andcommitted
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
1 parent 6ec5f77 commit 1f1ddeb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

test/src/main/java/org/springframework/security/test/web/servlet/setup/SecurityMockMvcConfigurer.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,38 +118,44 @@ void setDelegate(Filter delegate) {
118118
}
119119

120120
Filter getDelegate() {
121-
return this.delegate;
121+
Filter result = this.delegate;
122+
if (result == null) {
123+
throw new IllegalStateException("delegate cannot be null. Ensure a Bean with the name "
124+
+ BeanIds.SPRING_SECURITY_FILTER_CHAIN
125+
+ " implementing Filter is present or inject the Filter to be used.");
126+
}
127+
return result;
122128
}
123129

124130
@Override
125131
public void init(FilterConfig filterConfig) throws ServletException {
126-
this.delegate.init(filterConfig);
132+
getDelegate().init(filterConfig);
127133
}
128134

129135
@Override
130136
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
131137
throws IOException, ServletException {
132-
this.delegate.doFilter(request, response, chain);
138+
getDelegate().doFilter(request, response, chain);
133139
}
134140

135141
@Override
136142
public void destroy() {
137-
this.delegate.destroy();
143+
getDelegate().destroy();
138144
}
139145

140146
@Override
141147
public int hashCode() {
142-
return this.delegate.hashCode();
148+
return getDelegate().hashCode();
143149
}
144150

145151
@Override
146152
public boolean equals(Object obj) {
147-
return this.delegate.equals(obj);
153+
return getDelegate().equals(obj);
148154
}
149155

150156
@Override
151157
public String toString() {
152-
return this.delegate.toString();
158+
return getDelegate().toString();
153159
}
154160
}
155161
}

0 commit comments

Comments
 (0)