ShiroFilterFactoryBean public class ShiroFilterFactoryBean extends org.apache.shiro.spring.web.ShiroFilterFactoryBean { private String resourcePatterns; @Override protected AbstractShiroFilter createInstance() throws Exception { AbstractShi
public class ShiroFilterFactoryBean extends org.apache.shiro.spring.web.ShiroFilterFactoryBean { private String resourcePatterns; @Override protected AbstractShiroFilter createInstance() throws Exception { AbstractShiroFilter instance = super.createInstance(); SetpatternSet = null; if (StringUtils.hasText(resourcePatterns)) { patternSet = Stream.of(resourcePatterns.split(",")) .filter(StringUtils::hasLength) .map(String::trim) .collect(Collectors.toSet()); } return new SpringShiroFilter(instance.getSecurityManager(), instance.getFilterChainResolver(), patternSet); } private static final class SpringShiroFilter extends AbstractShiroFilter { private Set patternSet; private AntPathMatcher matcher; protected SpringShiroFilter(WebSecurityManager webSecurityManager, FilterChainResolver resolver, Set patternSet) { super(); if (isNull(webSecurityManager)) { throw new IllegalArgumentException("WebSecurityManager property cannot be null."); } setSecurityManager(webSecurityManager); if (nonNull(resolver)) { setFilterChainResolver(resolver); } if (nonNull(patternSet)) { this.patternSet = patternSet; matcher = new AntPathMatcher(); } } @Override protected void updateSessionLastAccessTime(ServletRequest request, ServletResponse response) { if(!isHttpSessions()&&!isResource(request)) super.updateSessionLastAccessTime(request, response); } private boolean isResource(ServletRequest servletRequest) { if (isNull(patternSet)||patternSet.isEmpty()) { return false; } HttpServletRequest request = (HttpServletRequest) servletRequest; int contextPathLen=request.getContextPath().length(); String requestURI=request.getRequestURI(); final String requestPath =requestURI.substring(contextPathLen); return patternSet.stream().anyMatch(pattern -> matcher.match(pattern, requestPath)); } } public void setResourcesPatterns(String patterns) { this.resourcePatterns = patterns; } }