View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  /**
18   * Autogenerated by Thrift Compiler (0.9.0)
19   *
20   * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
21   *  @generated
22   */
23  package org.apache.accumulo.core.security.thrift;
24  
25  import org.apache.thrift.scheme.IScheme;
26  import org.apache.thrift.scheme.SchemeFactory;
27  import org.apache.thrift.scheme.StandardScheme;
28  
29  import org.apache.thrift.scheme.TupleScheme;
30  import org.apache.thrift.protocol.TTupleProtocol;
31  import org.apache.thrift.protocol.TProtocolException;
32  import org.apache.thrift.EncodingUtils;
33  import org.apache.thrift.TException;
34  import java.util.List;
35  import java.util.ArrayList;
36  import java.util.Map;
37  import java.util.HashMap;
38  import java.util.EnumMap;
39  import java.util.Set;
40  import java.util.HashSet;
41  import java.util.EnumSet;
42  import java.util.Collections;
43  import java.util.BitSet;
44  import java.nio.ByteBuffer;
45  import java.util.Arrays;
46  import org.slf4j.Logger;
47  import org.slf4j.LoggerFactory;
48  
49  @SuppressWarnings("all") public class Credentials implements org.apache.thrift.TBase<Credentials, Credentials._Fields>, java.io.Serializable, Cloneable {
50    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Credentials");
51  
52    private static final org.apache.thrift.protocol.TField PRINCIPAL_FIELD_DESC = new org.apache.thrift.protocol.TField("principal", org.apache.thrift.protocol.TType.STRING, (short)1);
53    private static final org.apache.thrift.protocol.TField TOKEN_FIELD_DESC = new org.apache.thrift.protocol.TField("token", org.apache.thrift.protocol.TType.STRING, (short)2);
54    private static final org.apache.thrift.protocol.TField INSTANCE_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("instanceId", org.apache.thrift.protocol.TType.STRING, (short)3);
55  
56    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
57    static {
58      schemes.put(StandardScheme.class, new CredentialsStandardSchemeFactory());
59      schemes.put(TupleScheme.class, new CredentialsTupleSchemeFactory());
60    }
61  
62    public String principal; // required
63    public ByteBuffer token; // required
64    public String instanceId; // required
65  
66    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
67    @SuppressWarnings("all") public enum _Fields implements org.apache.thrift.TFieldIdEnum {
68      PRINCIPAL((short)1, "principal"),
69      TOKEN((short)2, "token"),
70      INSTANCE_ID((short)3, "instanceId");
71  
72      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
73  
74      static {
75        for (_Fields field : EnumSet.allOf(_Fields.class)) {
76          byName.put(field.getFieldName(), field);
77        }
78      }
79  
80      /**
81       * Find the _Fields constant that matches fieldId, or null if its not found.
82       */
83      public static _Fields findByThriftId(int fieldId) {
84        switch(fieldId) {
85          case 1: // PRINCIPAL
86            return PRINCIPAL;
87          case 2: // TOKEN
88            return TOKEN;
89          case 3: // INSTANCE_ID
90            return INSTANCE_ID;
91          default:
92            return null;
93        }
94      }
95  
96      /**
97       * Find the _Fields constant that matches fieldId, throwing an exception
98       * if it is not found.
99       */
100     public static _Fields findByThriftIdOrThrow(int fieldId) {
101       _Fields fields = findByThriftId(fieldId);
102       if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
103       return fields;
104     }
105 
106     /**
107      * Find the _Fields constant that matches name, or null if its not found.
108      */
109     public static _Fields findByName(String name) {
110       return byName.get(name);
111     }
112 
113     private final short _thriftId;
114     private final String _fieldName;
115 
116     _Fields(short thriftId, String fieldName) {
117       _thriftId = thriftId;
118       _fieldName = fieldName;
119     }
120 
121     public short getThriftFieldId() {
122       return _thriftId;
123     }
124 
125     public String getFieldName() {
126       return _fieldName;
127     }
128   }
129 
130   // isset id assignments
131   public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
132   static {
133     Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
134     tmpMap.put(_Fields.PRINCIPAL, new org.apache.thrift.meta_data.FieldMetaData("principal", org.apache.thrift.TFieldRequirementType.DEFAULT, 
135         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
136     tmpMap.put(_Fields.TOKEN, new org.apache.thrift.meta_data.FieldMetaData("token", org.apache.thrift.TFieldRequirementType.DEFAULT, 
137         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , true)));
138     tmpMap.put(_Fields.INSTANCE_ID, new org.apache.thrift.meta_data.FieldMetaData("instanceId", org.apache.thrift.TFieldRequirementType.DEFAULT, 
139         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
140     metaDataMap = Collections.unmodifiableMap(tmpMap);
141     org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Credentials.class, metaDataMap);
142   }
143 
144   public Credentials() {
145   }
146 
147   public Credentials(
148     String principal,
149     ByteBuffer token,
150     String instanceId)
151   {
152     this();
153     this.principal = principal;
154     this.token = token;
155     this.instanceId = instanceId;
156   }
157 
158   /**
159    * Performs a deep copy on <i>other</i>.
160    */
161   public Credentials(Credentials other) {
162     if (other.isSetPrincipal()) {
163       this.principal = other.principal;
164     }
165     if (other.isSetToken()) {
166       this.token = org.apache.thrift.TBaseHelper.copyBinary(other.token);
167 ;
168     }
169     if (other.isSetInstanceId()) {
170       this.instanceId = other.instanceId;
171     }
172   }
173 
174   public Credentials deepCopy() {
175     return new Credentials(this);
176   }
177 
178   @Override
179   public void clear() {
180     this.principal = null;
181     this.token = null;
182     this.instanceId = null;
183   }
184 
185   public String getPrincipal() {
186     return this.principal;
187   }
188 
189   public Credentials setPrincipal(String principal) {
190     this.principal = principal;
191     return this;
192   }
193 
194   public void unsetPrincipal() {
195     this.principal = null;
196   }
197 
198   /** Returns true if field principal is set (has been assigned a value) and false otherwise */
199   public boolean isSetPrincipal() {
200     return this.principal != null;
201   }
202 
203   public void setPrincipalIsSet(boolean value) {
204     if (!value) {
205       this.principal = null;
206     }
207   }
208 
209   public byte[] getToken() {
210     setToken(org.apache.thrift.TBaseHelper.rightSize(token));
211     return token == null ? null : token.array();
212   }
213 
214   public ByteBuffer bufferForToken() {
215     return token;
216   }
217 
218   public Credentials setToken(byte[] token) {
219     setToken(token == null ? (ByteBuffer)null : ByteBuffer.wrap(token));
220     return this;
221   }
222 
223   public Credentials setToken(ByteBuffer token) {
224     this.token = token;
225     return this;
226   }
227 
228   public void unsetToken() {
229     this.token = null;
230   }
231 
232   /** Returns true if field token is set (has been assigned a value) and false otherwise */
233   public boolean isSetToken() {
234     return this.token != null;
235   }
236 
237   public void setTokenIsSet(boolean value) {
238     if (!value) {
239       this.token = null;
240     }
241   }
242 
243   public String getInstanceId() {
244     return this.instanceId;
245   }
246 
247   public Credentials setInstanceId(String instanceId) {
248     this.instanceId = instanceId;
249     return this;
250   }
251 
252   public void unsetInstanceId() {
253     this.instanceId = null;
254   }
255 
256   /** Returns true if field instanceId is set (has been assigned a value) and false otherwise */
257   public boolean isSetInstanceId() {
258     return this.instanceId != null;
259   }
260 
261   public void setInstanceIdIsSet(boolean value) {
262     if (!value) {
263       this.instanceId = null;
264     }
265   }
266 
267   public void setFieldValue(_Fields field, Object value) {
268     switch (field) {
269     case PRINCIPAL:
270       if (value == null) {
271         unsetPrincipal();
272       } else {
273         setPrincipal((String)value);
274       }
275       break;
276 
277     case TOKEN:
278       if (value == null) {
279         unsetToken();
280       } else {
281         setToken((ByteBuffer)value);
282       }
283       break;
284 
285     case INSTANCE_ID:
286       if (value == null) {
287         unsetInstanceId();
288       } else {
289         setInstanceId((String)value);
290       }
291       break;
292 
293     }
294   }
295 
296   public Object getFieldValue(_Fields field) {
297     switch (field) {
298     case PRINCIPAL:
299       return getPrincipal();
300 
301     case TOKEN:
302       return getToken();
303 
304     case INSTANCE_ID:
305       return getInstanceId();
306 
307     }
308     throw new IllegalStateException();
309   }
310 
311   /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
312   public boolean isSet(_Fields field) {
313     if (field == null) {
314       throw new IllegalArgumentException();
315     }
316 
317     switch (field) {
318     case PRINCIPAL:
319       return isSetPrincipal();
320     case TOKEN:
321       return isSetToken();
322     case INSTANCE_ID:
323       return isSetInstanceId();
324     }
325     throw new IllegalStateException();
326   }
327 
328   @Override
329   public boolean equals(Object that) {
330     if (that == null)
331       return false;
332     if (that instanceof Credentials)
333       return this.equals((Credentials)that);
334     return false;
335   }
336 
337   public boolean equals(Credentials that) {
338     if (that == null)
339       return false;
340 
341     boolean this_present_principal = true && this.isSetPrincipal();
342     boolean that_present_principal = true && that.isSetPrincipal();
343     if (this_present_principal || that_present_principal) {
344       if (!(this_present_principal && that_present_principal))
345         return false;
346       if (!this.principal.equals(that.principal))
347         return false;
348     }
349 
350     boolean this_present_token = true && this.isSetToken();
351     boolean that_present_token = true && that.isSetToken();
352     if (this_present_token || that_present_token) {
353       if (!(this_present_token && that_present_token))
354         return false;
355       if (!this.token.equals(that.token))
356         return false;
357     }
358 
359     boolean this_present_instanceId = true && this.isSetInstanceId();
360     boolean that_present_instanceId = true && that.isSetInstanceId();
361     if (this_present_instanceId || that_present_instanceId) {
362       if (!(this_present_instanceId && that_present_instanceId))
363         return false;
364       if (!this.instanceId.equals(that.instanceId))
365         return false;
366     }
367 
368     return true;
369   }
370 
371   @Override
372   public int hashCode() {
373     return 0;
374   }
375 
376   public int compareTo(Credentials other) {
377     if (!getClass().equals(other.getClass())) {
378       return getClass().getName().compareTo(other.getClass().getName());
379     }
380 
381     int lastComparison = 0;
382     Credentials typedOther = (Credentials)other;
383 
384     lastComparison = Boolean.valueOf(isSetPrincipal()).compareTo(typedOther.isSetPrincipal());
385     if (lastComparison != 0) {
386       return lastComparison;
387     }
388     if (isSetPrincipal()) {
389       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.principal, typedOther.principal);
390       if (lastComparison != 0) {
391         return lastComparison;
392       }
393     }
394     lastComparison = Boolean.valueOf(isSetToken()).compareTo(typedOther.isSetToken());
395     if (lastComparison != 0) {
396       return lastComparison;
397     }
398     if (isSetToken()) {
399       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.token, typedOther.token);
400       if (lastComparison != 0) {
401         return lastComparison;
402       }
403     }
404     lastComparison = Boolean.valueOf(isSetInstanceId()).compareTo(typedOther.isSetInstanceId());
405     if (lastComparison != 0) {
406       return lastComparison;
407     }
408     if (isSetInstanceId()) {
409       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.instanceId, typedOther.instanceId);
410       if (lastComparison != 0) {
411         return lastComparison;
412       }
413     }
414     return 0;
415   }
416 
417   public _Fields fieldForId(int fieldId) {
418     return _Fields.findByThriftId(fieldId);
419   }
420 
421   public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
422     schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
423   }
424 
425   public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
426     schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
427   }
428 
429   @Override
430   public String toString() {
431     StringBuilder sb = new StringBuilder("Credentials(");
432     boolean first = true;
433 
434     sb.append("principal:");
435     if (this.principal == null) {
436       sb.append("null");
437     } else {
438       sb.append(this.principal);
439     }
440     first = false;
441     if (!first) sb.append(", ");
442     sb.append("token:");
443     if (this.token == null) {
444       sb.append("null");
445     } else {
446       org.apache.thrift.TBaseHelper.toString(this.token, sb);
447     }
448     first = false;
449     if (!first) sb.append(", ");
450     sb.append("instanceId:");
451     if (this.instanceId == null) {
452       sb.append("null");
453     } else {
454       sb.append(this.instanceId);
455     }
456     first = false;
457     sb.append(")");
458     return sb.toString();
459   }
460 
461   public void validate() throws org.apache.thrift.TException {
462     // check for required fields
463     // check for sub-struct validity
464   }
465 
466   private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
467     try {
468       write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
469     } catch (org.apache.thrift.TException te) {
470       throw new java.io.IOException(te);
471     }
472   }
473 
474   private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
475     try {
476       read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
477     } catch (org.apache.thrift.TException te) {
478       throw new java.io.IOException(te);
479     }
480   }
481 
482   private static class CredentialsStandardSchemeFactory implements SchemeFactory {
483     public CredentialsStandardScheme getScheme() {
484       return new CredentialsStandardScheme();
485     }
486   }
487 
488   private static class CredentialsStandardScheme extends StandardScheme<Credentials> {
489 
490     public void read(org.apache.thrift.protocol.TProtocol iprot, Credentials struct) throws org.apache.thrift.TException {
491       org.apache.thrift.protocol.TField schemeField;
492       iprot.readStructBegin();
493       while (true)
494       {
495         schemeField = iprot.readFieldBegin();
496         if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
497           break;
498         }
499         switch (schemeField.id) {
500           case 1: // PRINCIPAL
501             if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
502               struct.principal = iprot.readString();
503               struct.setPrincipalIsSet(true);
504             } else { 
505               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
506             }
507             break;
508           case 2: // TOKEN
509             if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
510               struct.token = iprot.readBinary();
511               struct.setTokenIsSet(true);
512             } else { 
513               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
514             }
515             break;
516           case 3: // INSTANCE_ID
517             if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
518               struct.instanceId = iprot.readString();
519               struct.setInstanceIdIsSet(true);
520             } else { 
521               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
522             }
523             break;
524           default:
525             org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
526         }
527         iprot.readFieldEnd();
528       }
529       iprot.readStructEnd();
530 
531       // check for required fields of primitive type, which can't be checked in the validate method
532       struct.validate();
533     }
534 
535     public void write(org.apache.thrift.protocol.TProtocol oprot, Credentials struct) throws org.apache.thrift.TException {
536       struct.validate();
537 
538       oprot.writeStructBegin(STRUCT_DESC);
539       if (struct.principal != null) {
540         oprot.writeFieldBegin(PRINCIPAL_FIELD_DESC);
541         oprot.writeString(struct.principal);
542         oprot.writeFieldEnd();
543       }
544       if (struct.token != null) {
545         oprot.writeFieldBegin(TOKEN_FIELD_DESC);
546         oprot.writeBinary(struct.token);
547         oprot.writeFieldEnd();
548       }
549       if (struct.instanceId != null) {
550         oprot.writeFieldBegin(INSTANCE_ID_FIELD_DESC);
551         oprot.writeString(struct.instanceId);
552         oprot.writeFieldEnd();
553       }
554       oprot.writeFieldStop();
555       oprot.writeStructEnd();
556     }
557 
558   }
559 
560   private static class CredentialsTupleSchemeFactory implements SchemeFactory {
561     public CredentialsTupleScheme getScheme() {
562       return new CredentialsTupleScheme();
563     }
564   }
565 
566   private static class CredentialsTupleScheme extends TupleScheme<Credentials> {
567 
568     @Override
569     public void write(org.apache.thrift.protocol.TProtocol prot, Credentials struct) throws org.apache.thrift.TException {
570       TTupleProtocol oprot = (TTupleProtocol) prot;
571       BitSet optionals = new BitSet();
572       if (struct.isSetPrincipal()) {
573         optionals.set(0);
574       }
575       if (struct.isSetToken()) {
576         optionals.set(1);
577       }
578       if (struct.isSetInstanceId()) {
579         optionals.set(2);
580       }
581       oprot.writeBitSet(optionals, 3);
582       if (struct.isSetPrincipal()) {
583         oprot.writeString(struct.principal);
584       }
585       if (struct.isSetToken()) {
586         oprot.writeBinary(struct.token);
587       }
588       if (struct.isSetInstanceId()) {
589         oprot.writeString(struct.instanceId);
590       }
591     }
592 
593     @Override
594     public void read(org.apache.thrift.protocol.TProtocol prot, Credentials struct) throws org.apache.thrift.TException {
595       TTupleProtocol iprot = (TTupleProtocol) prot;
596       BitSet incoming = iprot.readBitSet(3);
597       if (incoming.get(0)) {
598         struct.principal = iprot.readString();
599         struct.setPrincipalIsSet(true);
600       }
601       if (incoming.get(1)) {
602         struct.token = iprot.readBinary();
603         struct.setTokenIsSet(true);
604       }
605       if (incoming.get(2)) {
606         struct.instanceId = iprot.readString();
607         struct.setInstanceIdIsSet(true);
608       }
609     }
610   }
611 
612 }
613