package com.moral.security.auth.jwt; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.security.web.util.matcher.OrRequestMatcher; import org.springframework.security.web.util.matcher.RequestMatcher; import org.springframework.util.Assert; import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; /** * SkipPathRequestMatcher * * @author vladimir.stankovic * * Aug 19, 2016 */ public class SkipPathRequestMatcher implements RequestMatcher { private OrRequestMatcher matchers; private RequestMatcher processingMatcher; public SkipPathRequestMatcher(List pathsToSkip, String processingPath) { pathsToSkip = Optional.of(pathsToSkip) .orElseThrow(()-> new NullPointerException("In Method SkipPathRequestMatcher,Param pathsToSkip can't be null.")); List m = pathsToSkip.stream().map(path -> new AntPathRequestMatcher(path)).collect(Collectors.toList()); matchers = new OrRequestMatcher(m); processingMatcher = new AntPathRequestMatcher(processingPath); } @Override public boolean matches(HttpServletRequest request) { if (matchers.matches(request)) { return false; } return processingMatcher.matches(request) ? true : false; } }