Line data Source code
1 : // Copyright (C) 2009 The Android Open Source Project 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.server.account; 16 : 17 : import com.google.gerrit.entities.Account; 18 : import com.google.gerrit.extensions.client.AccountFieldName; 19 : import com.google.gerrit.server.IdentifiedUser; 20 : import com.google.gerrit.server.account.externalids.ExternalId; 21 : import java.io.IOException; 22 : import java.util.Collection; 23 : import java.util.Set; 24 : import javax.naming.NamingException; 25 : import javax.security.auth.login.LoginException; 26 : 27 : /** 28 : * Interface between Gerrit and an account system. 29 : * 30 : * <p>This interface provides the glue layer between the Gerrit and external account/authentication 31 : * systems (eg. LDAP, OpenID). 32 : */ 33 : public interface Realm { 34 : /** Can the end-user modify this field of their own account? */ 35 : boolean allowsEdit(AccountFieldName field); 36 : 37 : /** Returns the account fields that the end-user can modify. */ 38 : Set<AccountFieldName> getEditableFields(); 39 : 40 : AuthRequest authenticate(AuthRequest who) throws AccountException; 41 : 42 : void onCreateAccount(AuthRequest who, Account account); 43 : 44 : /** Returns true if the user has the given email address. */ 45 : boolean hasEmailAddress(IdentifiedUser who, String email); 46 : 47 : /** Returns all known email addresses for the identified user. */ 48 : Set<String> getEmailAddresses(IdentifiedUser who); 49 : 50 : /** 51 : * Locate an account whose local username is the given account name. 52 : * 53 : * <p>Generally this only works for local realms, such as one backed by an LDAP directory, or 54 : * where there is an {@link EmailExpander} configured that knows how to convert the accountName 55 : * into an email address, and then locate the user by that email address. 56 : */ 57 : Account.Id lookup(String accountName) throws IOException; 58 : 59 : /** 60 : * Returns true if the account is active. 61 : * 62 : * @throws LoginException thrown if login is required and fails 63 : * @throws NamingException may be thrown if the name is invalid 64 : * @throws AccountException may be thrown in case the username is ambiguous 65 : * @throws IOException thrown in case of IO errors 66 : */ 67 : default boolean isActive(@SuppressWarnings("unused") String username) 68 : throws LoginException, NamingException, AccountException, IOException { 69 0 : return true; 70 : } 71 : 72 : /** Returns true if the account is backed by the realm, false otherwise. */ 73 : default boolean accountBelongsToRealm( 74 : @SuppressWarnings("unused") Collection<ExternalId> externalIds) { 75 0 : return false; 76 : } 77 : }