Line data Source code
1 : // Copyright (C) 2021 Open Infrastructure Foundation 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.auth.openid; 16 : 17 : import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_HTTP; 18 : import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_HTTPS; 19 : import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_XRI; 20 : 21 : import com.google.common.annotations.VisibleForTesting; 22 : import com.google.gerrit.server.account.DefaultRealm; 23 : import com.google.gerrit.server.account.EmailExpander; 24 : import com.google.gerrit.server.account.Emails; 25 : import com.google.gerrit.server.account.externalids.ExternalId; 26 : import com.google.gerrit.server.config.AuthConfig; 27 : import com.google.inject.Inject; 28 : import com.google.inject.Provider; 29 : import com.google.inject.Singleton; 30 : import java.util.Collection; 31 : 32 : @Singleton 33 : public class OpenIdRealm extends DefaultRealm { 34 : @Inject 35 : @VisibleForTesting 36 : public OpenIdRealm(EmailExpander emailExpander, Provider<Emails> emails, AuthConfig authConfig) { 37 139 : super(emailExpander, emails, authConfig); 38 139 : } 39 : 40 : @Override 41 : public boolean accountBelongsToRealm(Collection<ExternalId> externalIds) { 42 4 : for (ExternalId id : externalIds) { 43 4 : if (id.isScheme(SCHEME_HTTP) || id.isScheme(SCHEME_HTTPS) || id.isScheme(SCHEME_XRI)) { 44 1 : return true; 45 : } 46 4 : } 47 4 : return false; 48 : } 49 : }