@Override public Collection<String> getWhitelistUrls() { ImmutableList.Builder<String> builder = ImmutableList.builder(); for (Pattern pattern : whitelist.get().getPatterns()) { builder.add(pattern.pattern()); } return builder.build(); }
/** * Returns true if the specified URL matches a whitelisted URL regular expression. If the whitelist is disabled, this * method always returns false. * * @param url URL to match against the whitelist * @return true if the whitelist is enabled and the URL matched an entry in the whitelist, otherwise false */ public boolean matches(String url) { if (!enabled) { return false; } for (Pattern pattern : getPatterns()) { Matcher matcher = pattern.matcher(url); if (matcher.matches()) { return true; } } return false; } }
@Override public void addWhitelistPattern(String urlPattern) { // to make sure this method is threadsafe, we need to guarantee that the "snapshot" of the whitelist taken at the beginning // of the method has not been replaced by the time we have constructed a new whitelist at the end of the method boolean whitelistUpdated = false; while (!whitelistUpdated) { Whitelist currentWhitelist = this.whitelist.get(); if (!currentWhitelist.isEnabled()) { throw new IllegalStateException("Whitelist is disabled. Cannot add patterns to a disabled whitelist."); } // retrieve the response code and list of patterns from the current whitelist, the construct a new list of patterns that contains // all of the old whitelist's patterns + this new pattern int statusCode = currentWhitelist.getStatusCode(); List<String> newPatterns = new ArrayList<>(currentWhitelist.getPatterns().size() + 1); for (Pattern pattern : currentWhitelist.getPatterns()) { newPatterns.add(pattern.pattern()); } newPatterns.add(urlPattern); // create a new (immutable) Whitelist object with the new pattern list and status code Whitelist newWhitelist = new Whitelist(newPatterns, statusCode); // replace the current whitelist with the new whitelist only if the current whitelist has not changed since we started whitelistUpdated = this.whitelist.compareAndSet(currentWhitelist, newWhitelist); } }
@Override public HttpFilters filterRequest(HttpRequest originalRequest, ChannelHandlerContext ctx) { Whitelist currentWhitelist = whitelist.get(); return new WhitelistFilter(originalRequest, ctx, isWhitelistEnabled(), currentWhitelist.getStatusCode(), currentWhitelist.getPatterns()); } });
/** * @deprecated use {@link #getWhitelistUrls()} */ @Deprecated public List<Pattern> getWhitelistRequests() { return ImmutableList.copyOf(whitelist.get().getPatterns()); }
@Override public Collection<String> getWhitelistUrls() { ImmutableList.Builder<String> builder = ImmutableList.builder(); for (Pattern pattern : whitelist.get().getPatterns()) { builder.add(pattern.pattern()); } return builder.build(); }
@Override public Collection<String> getWhitelistUrls() { ImmutableList.Builder<String> builder = ImmutableList.builder(); for (Pattern pattern : whitelist.get().getPatterns()) { builder.add(pattern.pattern()); } return builder.build(); }
@Override public Collection<String> getWhitelistUrls() { ImmutableList.Builder<String> builder = ImmutableList.builder(); for (Pattern pattern : whitelist.get().getPatterns()) { builder.add(pattern.pattern()); } return builder.build(); }
/** * Returns true if the specified URL matches a whitelisted URL regular expression. If the whitelist is disabled, this * method always returns false. * * @param url URL to match against the whitelist * @return true if the whitelist is enabled and the URL matched an entry in the whitelist, otherwise false */ public boolean matches(String url) { if (!enabled) { return false; } for (Pattern pattern : getPatterns()) { Matcher matcher = pattern.matcher(url); if (matcher.matches()) { return true; } } return false; } }
/** * Returns true if the specified URL matches a whitelisted URL regular expression. If the whitelist is disabled, this * method always returns false. * * @param url URL to match against the whitelist * @return true if the whitelist is enabled and the URL matched an entry in the whitelist, otherwise false */ public boolean matches(String url) { if (!enabled) { return false; } for (Pattern pattern : getPatterns()) { Matcher matcher = pattern.matcher(url); if (matcher.matches()) { return true; } } return false; } }
@Override public void addWhitelistPattern(String urlPattern) { // to make sure this method is threadsafe, we need to guarantee that the "snapshot" of the whitelist taken at the beginning // of the method has not been replaced by the time we have constructed a new whitelist at the end of the method boolean whitelistUpdated = false; while (!whitelistUpdated) { Whitelist currentWhitelist = this.whitelist.get(); if (!currentWhitelist.isEnabled()) { throw new IllegalStateException("Whitelist is disabled. Cannot add patterns to a disabled whitelist."); } // retrieve the response code and list of patterns from the current whitelist, the construct a new list of patterns that contains // all of the old whitelist's patterns + this new pattern int statusCode = currentWhitelist.getStatusCode(); List<String> newPatterns = new ArrayList<>(currentWhitelist.getPatterns().size() + 1); for (Pattern pattern : currentWhitelist.getPatterns()) { newPatterns.add(pattern.pattern()); } newPatterns.add(urlPattern); // create a new (immutable) Whitelist object with the new pattern list and status code Whitelist newWhitelist = new Whitelist(newPatterns, statusCode); // replace the current whitelist with the new whitelist only if the current whitelist has not changed since we started whitelistUpdated = this.whitelist.compareAndSet(currentWhitelist, newWhitelist); } }
@Override public void addWhitelistPattern(String urlPattern) { // to make sure this method is threadsafe, we need to guarantee that the "snapshot" of the whitelist taken at the beginning // of the method has not been replaced by the time we have constructed a new whitelist at the end of the method boolean whitelistUpdated = false; while (!whitelistUpdated) { Whitelist currentWhitelist = this.whitelist.get(); if (!currentWhitelist.isEnabled()) { throw new IllegalStateException("Whitelist is disabled. Cannot add patterns to a disabled whitelist."); } // retrieve the response code and list of patterns from the current whitelist, the construct a new list of patterns that contains // all of the old whitelist's patterns + this new pattern int statusCode = currentWhitelist.getStatusCode(); List<String> newPatterns = new ArrayList<>(currentWhitelist.getPatterns().size() + 1); for (Pattern pattern : currentWhitelist.getPatterns()) { newPatterns.add(pattern.pattern()); } newPatterns.add(urlPattern); // create a new (immutable) Whitelist object with the new pattern list and status code Whitelist newWhitelist = new Whitelist(newPatterns, statusCode); // replace the current whitelist with the new whitelist only if the current whitelist has not changed since we started whitelistUpdated = this.whitelist.compareAndSet(currentWhitelist, newWhitelist); } }
@Override public void addWhitelistPattern(String urlPattern) { // to make sure this method is threadsafe, we need to guarantee that the "snapshot" of the whitelist taken at the beginning // of the method has not been replaced by the time we have constructed a new whitelist at the end of the method boolean whitelistUpdated = false; while (!whitelistUpdated) { Whitelist currentWhitelist = this.whitelist.get(); if (!currentWhitelist.isEnabled()) { throw new IllegalStateException("Whitelist is disabled. Cannot add patterns to a disabled whitelist."); } // retrieve the response code and list of patterns from the current whitelist, the construct a new list of patterns that contains // all of the old whitelist's patterns + this new pattern int statusCode = currentWhitelist.getStatusCode(); List<String> newPatterns = new ArrayList<>(currentWhitelist.getPatterns().size() + 1); for (Pattern pattern : currentWhitelist.getPatterns()) { newPatterns.add(pattern.pattern()); } newPatterns.add(urlPattern); // create a new (immutable) Whitelist object with the new pattern list and status code Whitelist newWhitelist = new Whitelist(newPatterns, statusCode); // replace the current whitelist with the new whitelist only if the current whitelist has not changed since we started whitelistUpdated = this.whitelist.compareAndSet(currentWhitelist, newWhitelist); } }
@Override public HttpFilters filterRequest(HttpRequest originalRequest, ChannelHandlerContext ctx) { Whitelist currentWhitelist = whitelist.get(); return new WhitelistFilter(originalRequest, ctx, isWhitelistEnabled(), currentWhitelist.getStatusCode(), currentWhitelist.getPatterns()); } });
@Override public HttpFilters filterRequest(HttpRequest originalRequest, ChannelHandlerContext ctx) { Whitelist currentWhitelist = whitelist.get(); return new WhitelistFilter(originalRequest, ctx, isWhitelistEnabled(), currentWhitelist.getStatusCode(), currentWhitelist.getPatterns()); } });
@Override public HttpFilters filterRequest(HttpRequest originalRequest, ChannelHandlerContext ctx) { Whitelist currentWhitelist = whitelist.get(); return new WhitelistFilter(originalRequest, ctx, isWhitelistEnabled(), currentWhitelist.getStatusCode(), currentWhitelist.getPatterns()); } });