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 allowList of browsers which can be used as part of an authorization flows. Examples: 024 * 025 * ```java 026 * // only allow Chrome, and only as a standalone browser 027 * new BrowserAllowList(VersionedBrowserMatcher.CHROME_BROWSER); 028 * 029 * // allow Chrome custom tabs only, but exclude a version range 030 * new BrowserAllowList( 031 * new VersionedBrowserMatcher( 032 * Browsers.Chrome.PACKAGE_NAME, 033 * Browsers.Chrome.SIGNATURE_SET, 034 * true, 035 * VersionRange.atMost("45.1")), 036 * new VersionedBrowserMatcher( 037 * Browsers.Chrome.PACKAGE_NAME, 038 * Browsers.Chrome.SIGNATURE_SET, 039 * true, 040 * VersionRange.atLeast("45.3")); 041 * ``` 042 */ 043public class BrowserAllowList implements BrowserMatcher { 044 045 private List<BrowserMatcher> mBrowserMatchers; 046 047 /** 048 * Creates a browser allowList, which will match if any of the provided matchers do. 049 */ 050 public BrowserAllowList(BrowserMatcher... matchers) { 051 mBrowserMatchers = Arrays.asList(matchers); 052 } 053 054 @Override 055 public boolean matches(@NonNull BrowserDescriptor descriptor) { 056 for (BrowserMatcher matcher : mBrowserMatchers) { 057 if (matcher.matches(descriptor)) { 058 return true; 059 } 060 } 061 062 return false; 063 } 064}