|
@@ -22,21 +22,18 @@ import org.springframework.security.web.authentication.www.BasicAuthenticationFi
|
|
|
import org.springframework.security.web.context.SecurityContextPersistenceFilter;
|
|
|
import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter;
|
|
|
import org.springframework.security.web.session.SessionManagementFilter;
|
|
|
-import org.springframework.security.web.util.AnyRequestMatcher;
|
|
|
|
|
|
public class DefaultFilterChainValidator implements FilterChainProxy.FilterChainValidator {
|
|
|
private Log logger = LogFactory.getLog(getClass());
|
|
|
|
|
|
public void validate(FilterChainProxy fcp) {
|
|
|
for(List<Filter> filters : fcp.getFilterChainMap().values()) {
|
|
|
+ checkLoginPageIsntProtected(fcp, filters);
|
|
|
checkFilterStack(filters);
|
|
|
}
|
|
|
-
|
|
|
- checkLoginPageIsntProtected(fcp);
|
|
|
}
|
|
|
|
|
|
private Object getFilter(Class<?> type, List<Filter> filters) {
|
|
|
-
|
|
|
for (Filter f : filters) {
|
|
|
if (type.isAssignableFrom(f.getClass())) {
|
|
|
return f;
|
|
@@ -77,59 +74,60 @@ public class DefaultFilterChainValidator implements FilterChainProxy.FilterChain
|
|
|
}
|
|
|
|
|
|
/* Checks for the common error of having a login page URL protected by the security interceptor */
|
|
|
- private void checkLoginPageIsntProtected(FilterChainProxy fcp) {
|
|
|
- List<Filter> defaultFilters = fcp.getFilterChainMap().get(new AnyRequestMatcher());
|
|
|
- ExceptionTranslationFilter etf = (ExceptionTranslationFilter)getFilter(ExceptionTranslationFilter.class, defaultFilters);
|
|
|
-
|
|
|
- if (etf.getAuthenticationEntryPoint() instanceof LoginUrlAuthenticationEntryPoint) {
|
|
|
- String loginPage =
|
|
|
- ((LoginUrlAuthenticationEntryPoint)etf.getAuthenticationEntryPoint()).getLoginFormUrl();
|
|
|
- FilterInvocation loginRequest = new FilterInvocation(loginPage, "POST");
|
|
|
- List<Filter> filters = fcp.getFilters(loginPage);
|
|
|
- logger.info("Checking whether login URL '" + loginPage + "' is accessible with your configuration");
|
|
|
-
|
|
|
- if (filters == null || filters.isEmpty()) {
|
|
|
- logger.debug("Filter chain is empty for the login page");
|
|
|
- return;
|
|
|
- }
|
|
|
+ private void checkLoginPageIsntProtected(FilterChainProxy fcp, List<Filter> filterStack) {
|
|
|
+ ExceptionTranslationFilter etf = (ExceptionTranslationFilter)getFilter(ExceptionTranslationFilter.class, filterStack);
|
|
|
|
|
|
- if (getFilter(DefaultLoginPageGeneratingFilter.class, filters) != null) {
|
|
|
- logger.debug("Default generated login page is in use");
|
|
|
- return;
|
|
|
- }
|
|
|
+ if(etf == null || !(etf.getAuthenticationEntryPoint() instanceof LoginUrlAuthenticationEntryPoint)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- FilterSecurityInterceptor fsi = (FilterSecurityInterceptor) getFilter(FilterSecurityInterceptor.class, filters);
|
|
|
- DefaultFilterInvocationSecurityMetadataSource fids =
|
|
|
- (DefaultFilterInvocationSecurityMetadataSource) fsi.getSecurityMetadataSource();
|
|
|
+ String loginPage = ((LoginUrlAuthenticationEntryPoint)etf.getAuthenticationEntryPoint()).getLoginFormUrl();
|
|
|
+ FilterInvocation loginRequest = new FilterInvocation(loginPage, "POST");
|
|
|
+ List<Filter> filters = fcp.getFilters(loginPage);
|
|
|
+ logger.info("Checking whether login URL '" + loginPage + "' is accessible with your configuration");
|
|
|
|
|
|
- Collection<ConfigAttribute> attributes = fids.getAttributes(loginRequest);
|
|
|
+ if (filters == null || filters.isEmpty()) {
|
|
|
+ logger.debug("Filter chain is empty for the login page");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (attributes == null) {
|
|
|
- logger.debug("No access attributes defined for login page URL");
|
|
|
- if (fsi.isRejectPublicInvocations()) {
|
|
|
- logger.warn("FilterSecurityInterceptor is configured to reject public invocations." +
|
|
|
- " Your login page may not be accessible.");
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (getFilter(DefaultLoginPageGeneratingFilter.class, filters) != null) {
|
|
|
+ logger.debug("Default generated login page is in use");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- AnonymousAuthenticationFilter anonPF = (AnonymousAuthenticationFilter) getFilter(AnonymousAuthenticationFilter.class, filters);
|
|
|
- if (anonPF == null) {
|
|
|
- logger.warn("The login page is being protected by the filter chain, but you don't appear to have" +
|
|
|
- " anonymous authentication enabled. This is almost certainly an error.");
|
|
|
- return;
|
|
|
- }
|
|
|
+ FilterSecurityInterceptor fsi = (FilterSecurityInterceptor) getFilter(FilterSecurityInterceptor.class, filters);
|
|
|
+ DefaultFilterInvocationSecurityMetadataSource fids =
|
|
|
+ (DefaultFilterInvocationSecurityMetadataSource) fsi.getSecurityMetadataSource();
|
|
|
|
|
|
- // Simulate an anonymous access with the supplied attributes.
|
|
|
- AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("key", anonPF.getUserAttribute().getPassword(),
|
|
|
- anonPF.getUserAttribute().getAuthorities());
|
|
|
- try {
|
|
|
- fsi.getAccessDecisionManager().decide(token, new Object(), attributes);
|
|
|
- } catch (Exception e) {
|
|
|
- logger.warn("Anonymous access to the login page doesn't appear to be enabled. This is almost certainly " +
|
|
|
- "an error. Please check your configuration allows unauthenticated access to the configured " +
|
|
|
- "login page. (Simulated access was rejected: " + e + ")");
|
|
|
+ Collection<ConfigAttribute> attributes = fids.getAttributes(loginRequest);
|
|
|
+
|
|
|
+ if (attributes == null) {
|
|
|
+ logger.debug("No access attributes defined for login page URL");
|
|
|
+ if (fsi.isRejectPublicInvocations()) {
|
|
|
+ logger.warn("FilterSecurityInterceptor is configured to reject public invocations." +
|
|
|
+ " Your login page may not be accessible.");
|
|
|
}
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ AnonymousAuthenticationFilter anonPF = (AnonymousAuthenticationFilter) getFilter(AnonymousAuthenticationFilter.class, filters);
|
|
|
+ if (anonPF == null) {
|
|
|
+ logger.warn("The login page is being protected by the filter chain, but you don't appear to have" +
|
|
|
+ " anonymous authentication enabled. This is almost certainly an error.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Simulate an anonymous access with the supplied attributes.
|
|
|
+ AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("key", anonPF.getUserAttribute().getPassword(),
|
|
|
+ anonPF.getUserAttribute().getAuthorities());
|
|
|
+ try {
|
|
|
+ fsi.getAccessDecisionManager().decide(token, new Object(), attributes);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.warn("Anonymous access to the login page doesn't appear to be enabled. This is almost certainly " +
|
|
|
+ "an error. Please check your configuration allows unauthenticated access to the configured " +
|
|
|
+ "login page. (Simulated access was rejected: " + e + ")");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|