Line data Source code
1 : // Copyright (C) 2012 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.auth; 16 : 17 : import com.google.common.base.Strings; 18 : import com.google.gerrit.common.Nullable; 19 : import java.util.Optional; 20 : 21 : /** Defines an abstract request for user authentication to Gerrit. */ 22 : public abstract class AuthRequest { 23 : private final Optional<String> username; 24 : private final Optional<String> password; 25 : 26 0 : protected AuthRequest(@Nullable String username, @Nullable String password) { 27 0 : this.username = Optional.ofNullable(Strings.emptyToNull(username)); 28 0 : this.password = Optional.ofNullable(Strings.emptyToNull(password)); 29 0 : } 30 : 31 : /** 32 : * Returns the username to be authenticated. 33 : * 34 : * @return username for authentication or {@code empty} for anonymous access. 35 : */ 36 : public final Optional<String> getUsername() { 37 0 : return username; 38 : } 39 : 40 : /** 41 : * Returns the user's credentials 42 : * 43 : * @return user's credentials or {@code empty}. 44 : */ 45 : public final Optional<String> getPassword() { 46 0 : return password; 47 : } 48 : }