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.extensions.restapi; 16 : 17 : import static com.google.common.base.Preconditions.checkArgument; 18 : 19 : import com.google.common.base.Strings; 20 : import java.util.Optional; 21 : 22 : /** Caller cannot perform the request operation (HTTP 403 Forbidden). */ 23 : public class AuthException extends RestApiException { 24 : private static final long serialVersionUID = 1L; 25 : 26 73 : private Optional<String> advice = Optional.empty(); 27 : 28 : /** @param msg message to return to the client. */ 29 : public AuthException(String msg) { 30 69 : super(msg); 31 69 : } 32 : 33 : /** 34 : * @param msg message to return to the client. 35 : * @param cause cause of this exception. 36 : */ 37 : public AuthException(String msg, Throwable cause) { 38 11 : super(msg, cause); 39 11 : } 40 : 41 : public void setAdvice(String advice) { 42 25 : checkArgument(!Strings.isNullOrEmpty(advice)); 43 25 : this.advice = Optional.of(advice); 44 25 : } 45 : 46 : /** 47 : * Advice that the user can follow to acquire authorization to perform the action. 48 : * 49 : * <p>This may be long-form text with newlines, and may be printed to a terminal, for example in 50 : * the message stream in response to a push. 51 : */ 52 : public Optional<String> getAdvice() { 53 12 : return advice; 54 : } 55 : }