1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 package org.apache.hadoop.oncrpc;
19 
20 import org.apache.hadoop.oncrpc.security.Verifier;
21 
22 /**
23  * Represents RPC message MSG_DENIED reply body. See RFC 1831 for details.
24  * This response is sent to a request to indicate failure of the request.
25  */
26 public class RpcDeniedReply extends RpcReply {
27   public enum RejectState {
28     // the order of the values below are significant.
29     RPC_MISMATCH,
30     AUTH_ERROR;
31 
getValue()32     int getValue() {
33       return ordinal();
34     }
35 
fromValue(int value)36     static RejectState fromValue(int value) {
37       return values()[value];
38     }
39   }
40 
41   private final RejectState rejectState;
42 
RpcDeniedReply(int xid, ReplyState replyState, RejectState rejectState, Verifier verifier)43   public RpcDeniedReply(int xid, ReplyState replyState,
44       RejectState rejectState, Verifier verifier) {
45     super(xid, replyState, verifier);
46     this.rejectState = rejectState;
47   }
48 
read(int xid, ReplyState replyState, XDR xdr)49   public static RpcDeniedReply read(int xid, ReplyState replyState, XDR xdr) {
50     Verifier verifier = Verifier.readFlavorAndVerifier(xdr);
51     RejectState rejectState = RejectState.fromValue(xdr.readInt());
52     return new RpcDeniedReply(xid, replyState, rejectState, verifier);
53   }
54 
getRejectState()55   public RejectState getRejectState() {
56     return rejectState;
57   }
58 
59   @Override
toString()60   public String toString() {
61     return new StringBuffer().append("xid:").append(xid)
62         .append(",messageType:").append(messageType).append("verifier_flavor:")
63         .append(verifier.getFlavor()).append("rejectState:")
64         .append(rejectState).toString();
65   }
66 
67   @Override
write(XDR xdr)68   public XDR write(XDR xdr) {
69     xdr.writeInt(xid);
70     xdr.writeInt(messageType.getValue());
71     xdr.writeInt(replyState.getValue());
72     Verifier.writeFlavorAndVerifier(verifier, xdr);
73     xdr.writeInt(rejectState.getValue());
74     return xdr;
75   }
76 }
77