001/* 002 * Copyright 2016 The AppAuth for Android Authors. All Rights Reserved. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the 010 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 011 * express or implied. See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014 015package net.openid.appauth.browser; 016 017import androidx.annotation.NonNull; 018 019import java.util.Arrays; 020import java.util.List; 021 022/** 023 * A denyList of browsers. This will reject a match for any browser on the list, and permit 024 * all others. Examples: 025 * 026 * ```java 027 * // denyList Chrome, whether using a custom tab or not 028 * new BrowserDenyList( 029 * VersionedBrowserMatcher.CHROME_BROWSER, 030 * VersionedBrowserMatcher.CHROME_CUSTOM_TAB); 031 * 032 * // denyList Firefox 033 * new BrowserDenyList( 034 * VersionedBrowserMatcher.FIREFOX_BROWSER, 035 * VersionedBrowserMatcher.FIREFOX_CUSTOM_TAB); 036 * 037 * // denyList Dolphin Browser 038 * new BrowserDenyList( 039 * new VersionedBrowserMatcher( 040 * "mobi.mgeek.TunnyBrowser", 041 * "<DOLPHIN_SIGNATURE>", 042 * false, 043 * VersionRange.ANY_VERSION)); 044 * } 045 * ``` 046 */ 047public class BrowserDenyList implements BrowserMatcher { 048 049 private List<BrowserMatcher> mBrowserMatchers; 050 051 /** 052 * Creates a denyList from the provided set of matchers. 053 */ 054 public BrowserDenyList(BrowserMatcher... matchers) { 055 mBrowserMatchers = Arrays.asList(matchers); 056 } 057 058 @Override 059 public boolean matches(@NonNull BrowserDescriptor descriptor) { 060 for (BrowserMatcher matcher : mBrowserMatchers) { 061 if (matcher.matches(descriptor)) { 062 return false; 063 } 064 } 065 066 return true; 067 } 068}