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 Credential implements org.apache.thrift.TBase<Credential, Credential._Fields>, java.io.Serializable, Cloneable {
50    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Credential");
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_CLASS_FIELD_DESC = new org.apache.thrift.protocol.TField("tokenClass", org.apache.thrift.protocol.TType.STRING, (short)2);
54    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)3);
55    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)4);
56  
57    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
58    static {
59      schemes.put(StandardScheme.class, new CredentialStandardSchemeFactory());
60      schemes.put(TupleScheme.class, new CredentialTupleSchemeFactory());
61    }
62  
63    public String principal; // required
64    public String tokenClass; // required
65    public ByteBuffer token; // required
66    public String instanceId; // required
67  
68    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
69    @SuppressWarnings("all") public enum _Fields implements org.apache.thrift.TFieldIdEnum {
70      PRINCIPAL((short)1, "principal"),
71      TOKEN_CLASS((short)2, "tokenClass"),
72      TOKEN((short)3, "token"),
73      INSTANCE_ID((short)4, "instanceId");
74  
75      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
76  
77      static {
78        for (_Fields field : EnumSet.allOf(_Fields.class)) {
79          byName.put(field.getFieldName(), field);
80        }
81      }
82  
83      /**
84       * Find the _Fields constant that matches fieldId, or null if its not found.
85       */
86      public static _Fields findByThriftId(int fieldId) {
87        switch(fieldId) {
88          case 1: // PRINCIPAL
89            return PRINCIPAL;
90          case 2: // TOKEN_CLASS
91            return TOKEN_CLASS;
92          case 3: // TOKEN
93            return TOKEN;
94          case 4: // INSTANCE_ID
95            return INSTANCE_ID;
96          default:
97            return null;
98        }
99      }
100 
101     /**
102      * Find the _Fields constant that matches fieldId, throwing an exception
103      * if it is not found.
104      */
105     public static _Fields findByThriftIdOrThrow(int fieldId) {
106       _Fields fields = findByThriftId(fieldId);
107       if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
108       return fields;
109     }
110 
111     /**
112      * Find the _Fields constant that matches name, or null if its not found.
113      */
114     public static _Fields findByName(String name) {
115       return byName.get(name);
116     }
117 
118     private final short _thriftId;
119     private final String _fieldName;
120 
121     _Fields(short thriftId, String fieldName) {
122       _thriftId = thriftId;
123       _fieldName = fieldName;
124     }
125 
126     public short getThriftFieldId() {
127       return _thriftId;
128     }
129 
130     public String getFieldName() {
131       return _fieldName;
132     }
133   }
134 
135   // isset id assignments
136   public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
137   static {
138     Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
139     tmpMap.put(_Fields.PRINCIPAL, new org.apache.thrift.meta_data.FieldMetaData("principal", org.apache.thrift.TFieldRequirementType.DEFAULT, 
140         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
141     tmpMap.put(_Fields.TOKEN_CLASS, new org.apache.thrift.meta_data.FieldMetaData("tokenClass", org.apache.thrift.TFieldRequirementType.DEFAULT, 
142         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
143     tmpMap.put(_Fields.TOKEN, new org.apache.thrift.meta_data.FieldMetaData("token", org.apache.thrift.TFieldRequirementType.DEFAULT, 
144         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , true)));
145     tmpMap.put(_Fields.INSTANCE_ID, new org.apache.thrift.meta_data.FieldMetaData("instanceId", org.apache.thrift.TFieldRequirementType.DEFAULT, 
146         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
147     metaDataMap = Collections.unmodifiableMap(tmpMap);
148     org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Credential.class, metaDataMap);
149   }
150 
151   public Credential() {
152   }
153 
154   public Credential(
155     String principal,
156     String tokenClass,
157     ByteBuffer token,
158     String instanceId)
159   {
160     this();
161     this.principal = principal;
162     this.tokenClass = tokenClass;
163     this.token = token;
164     this.instanceId = instanceId;
165   }
166 
167   /**
168    * Performs a deep copy on <i>other</i>.
169    */
170   public Credential(Credential other) {
171     if (other.isSetPrincipal()) {
172       this.principal = other.principal;
173     }
174     if (other.isSetTokenClass()) {
175       this.tokenClass = other.tokenClass;
176     }
177     if (other.isSetToken()) {
178       this.token = org.apache.thrift.TBaseHelper.copyBinary(other.token);
179 ;
180     }
181     if (other.isSetInstanceId()) {
182       this.instanceId = other.instanceId;
183     }
184   }
185 
186   public Credential deepCopy() {
187     return new Credential(this);
188   }
189 
190   @Override
191   public void clear() {
192     this.principal = null;
193     this.tokenClass = null;
194     this.token = null;
195     this.instanceId = null;
196   }
197 
198   public String getPrincipal() {
199     return this.principal;
200   }
201 
202   public Credential setPrincipal(String principal) {
203     this.principal = principal;
204     return this;
205   }
206 
207   public void unsetPrincipal() {
208     this.principal = null;
209   }
210 
211   /** Returns true if field principal is set (has been assigned a value) and false otherwise */
212   public boolean isSetPrincipal() {
213     return this.principal != null;
214   }
215 
216   public void setPrincipalIsSet(boolean value) {
217     if (!value) {
218       this.principal = null;
219     }
220   }
221 
222   public String getTokenClass() {
223     return this.tokenClass;
224   }
225 
226   public Credential setTokenClass(String tokenClass) {
227     this.tokenClass = tokenClass;
228     return this;
229   }
230 
231   public void unsetTokenClass() {
232     this.tokenClass = null;
233   }
234 
235   /** Returns true if field tokenClass is set (has been assigned a value) and false otherwise */
236   public boolean isSetTokenClass() {
237     return this.tokenClass != null;
238   }
239 
240   public void setTokenClassIsSet(boolean value) {
241     if (!value) {
242       this.tokenClass = null;
243     }
244   }
245 
246   public byte[] getToken() {
247     setToken(org.apache.thrift.TBaseHelper.rightSize(token));
248     return token == null ? null : token.array();
249   }
250 
251   public ByteBuffer bufferForToken() {
252     return token;
253   }
254 
255   public Credential setToken(byte[] token) {
256     setToken(token == null ? (ByteBuffer)null : ByteBuffer.wrap(token));
257     return this;
258   }
259 
260   public Credential setToken(ByteBuffer token) {
261     this.token = token;
262     return this;
263   }
264 
265   public void unsetToken() {
266     this.token = null;
267   }
268 
269   /** Returns true if field token is set (has been assigned a value) and false otherwise */
270   public boolean isSetToken() {
271     return this.token != null;
272   }
273 
274   public void setTokenIsSet(boolean value) {
275     if (!value) {
276       this.token = null;
277     }
278   }
279 
280   public String getInstanceId() {
281     return this.instanceId;
282   }
283 
284   public Credential setInstanceId(String instanceId) {
285     this.instanceId = instanceId;
286     return this;
287   }
288 
289   public void unsetInstanceId() {
290     this.instanceId = null;
291   }
292 
293   /** Returns true if field instanceId is set (has been assigned a value) and false otherwise */
294   public boolean isSetInstanceId() {
295     return this.instanceId != null;
296   }
297 
298   public void setInstanceIdIsSet(boolean value) {
299     if (!value) {
300       this.instanceId = null;
301     }
302   }
303 
304   public void setFieldValue(_Fields field, Object value) {
305     switch (field) {
306     case PRINCIPAL:
307       if (value == null) {
308         unsetPrincipal();
309       } else {
310         setPrincipal((String)value);
311       }
312       break;
313 
314     case TOKEN_CLASS:
315       if (value == null) {
316         unsetTokenClass();
317       } else {
318         setTokenClass((String)value);
319       }
320       break;
321 
322     case TOKEN:
323       if (value == null) {
324         unsetToken();
325       } else {
326         setToken((ByteBuffer)value);
327       }
328       break;
329 
330     case INSTANCE_ID:
331       if (value == null) {
332         unsetInstanceId();
333       } else {
334         setInstanceId((String)value);
335       }
336       break;
337 
338     }
339   }
340 
341   public Object getFieldValue(_Fields field) {
342     switch (field) {
343     case PRINCIPAL:
344       return getPrincipal();
345 
346     case TOKEN_CLASS:
347       return getTokenClass();
348 
349     case TOKEN:
350       return getToken();
351 
352     case INSTANCE_ID:
353       return getInstanceId();
354 
355     }
356     throw new IllegalStateException();
357   }
358 
359   /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
360   public boolean isSet(_Fields field) {
361     if (field == null) {
362       throw new IllegalArgumentException();
363     }
364 
365     switch (field) {
366     case PRINCIPAL:
367       return isSetPrincipal();
368     case TOKEN_CLASS:
369       return isSetTokenClass();
370     case TOKEN:
371       return isSetToken();
372     case INSTANCE_ID:
373       return isSetInstanceId();
374     }
375     throw new IllegalStateException();
376   }
377 
378   @Override
379   public boolean equals(Object that) {
380     if (that == null)
381       return false;
382     if (that instanceof Credential)
383       return this.equals((Credential)that);
384     return false;
385   }
386 
387   public boolean equals(Credential that) {
388     if (that == null)
389       return false;
390 
391     boolean this_present_principal = true && this.isSetPrincipal();
392     boolean that_present_principal = true && that.isSetPrincipal();
393     if (this_present_principal || that_present_principal) {
394       if (!(this_present_principal && that_present_principal))
395         return false;
396       if (!this.principal.equals(that.principal))
397         return false;
398     }
399 
400     boolean this_present_tokenClass = true && this.isSetTokenClass();
401     boolean that_present_tokenClass = true && that.isSetTokenClass();
402     if (this_present_tokenClass || that_present_tokenClass) {
403       if (!(this_present_tokenClass && that_present_tokenClass))
404         return false;
405       if (!this.tokenClass.equals(that.tokenClass))
406         return false;
407     }
408 
409     boolean this_present_token = true && this.isSetToken();
410     boolean that_present_token = true && that.isSetToken();
411     if (this_present_token || that_present_token) {
412       if (!(this_present_token && that_present_token))
413         return false;
414       if (!this.token.equals(that.token))
415         return false;
416     }
417 
418     boolean this_present_instanceId = true && this.isSetInstanceId();
419     boolean that_present_instanceId = true && that.isSetInstanceId();
420     if (this_present_instanceId || that_present_instanceId) {
421       if (!(this_present_instanceId && that_present_instanceId))
422         return false;
423       if (!this.instanceId.equals(that.instanceId))
424         return false;
425     }
426 
427     return true;
428   }
429 
430   @Override
431   public int hashCode() {
432     return 0;
433   }
434 
435   public int compareTo(Credential other) {
436     if (!getClass().equals(other.getClass())) {
437       return getClass().getName().compareTo(other.getClass().getName());
438     }
439 
440     int lastComparison = 0;
441     Credential typedOther = (Credential)other;
442 
443     lastComparison = Boolean.valueOf(isSetPrincipal()).compareTo(typedOther.isSetPrincipal());
444     if (lastComparison != 0) {
445       return lastComparison;
446     }
447     if (isSetPrincipal()) {
448       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.principal, typedOther.principal);
449       if (lastComparison != 0) {
450         return lastComparison;
451       }
452     }
453     lastComparison = Boolean.valueOf(isSetTokenClass()).compareTo(typedOther.isSetTokenClass());
454     if (lastComparison != 0) {
455       return lastComparison;
456     }
457     if (isSetTokenClass()) {
458       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.tokenClass, typedOther.tokenClass);
459       if (lastComparison != 0) {
460         return lastComparison;
461       }
462     }
463     lastComparison = Boolean.valueOf(isSetToken()).compareTo(typedOther.isSetToken());
464     if (lastComparison != 0) {
465       return lastComparison;
466     }
467     if (isSetToken()) {
468       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.token, typedOther.token);
469       if (lastComparison != 0) {
470         return lastComparison;
471       }
472     }
473     lastComparison = Boolean.valueOf(isSetInstanceId()).compareTo(typedOther.isSetInstanceId());
474     if (lastComparison != 0) {
475       return lastComparison;
476     }
477     if (isSetInstanceId()) {
478       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.instanceId, typedOther.instanceId);
479       if (lastComparison != 0) {
480         return lastComparison;
481       }
482     }
483     return 0;
484   }
485 
486   public _Fields fieldForId(int fieldId) {
487     return _Fields.findByThriftId(fieldId);
488   }
489 
490   public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
491     schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
492   }
493 
494   public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
495     schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
496   }
497 
498   @Override
499   public String toString() {
500     StringBuilder sb = new StringBuilder("Credential(");
501     boolean first = true;
502 
503     sb.append("principal:");
504     if (this.principal == null) {
505       sb.append("null");
506     } else {
507       sb.append(this.principal);
508     }
509     first = false;
510     if (!first) sb.append(", ");
511     sb.append("tokenClass:");
512     if (this.tokenClass == null) {
513       sb.append("null");
514     } else {
515       sb.append(this.tokenClass);
516     }
517     first = false;
518     if (!first) sb.append(", ");
519     sb.append("token:");
520     if (this.token == null) {
521       sb.append("null");
522     } else {
523       org.apache.thrift.TBaseHelper.toString(this.token, sb);
524     }
525     first = false;
526     if (!first) sb.append(", ");
527     sb.append("instanceId:");
528     if (this.instanceId == null) {
529       sb.append("null");
530     } else {
531       sb.append(this.instanceId);
532     }
533     first = false;
534     sb.append(")");
535     return sb.toString();
536   }
537 
538   public void validate() throws org.apache.thrift.TException {
539     // check for required fields
540     // check for sub-struct validity
541   }
542 
543   private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
544     try {
545       write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
546     } catch (org.apache.thrift.TException te) {
547       throw new java.io.IOException(te);
548     }
549   }
550 
551   private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
552     try {
553       read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
554     } catch (org.apache.thrift.TException te) {
555       throw new java.io.IOException(te);
556     }
557   }
558 
559   private static class CredentialStandardSchemeFactory implements SchemeFactory {
560     public CredentialStandardScheme getScheme() {
561       return new CredentialStandardScheme();
562     }
563   }
564 
565   private static class CredentialStandardScheme extends StandardScheme<Credential> {
566 
567     public void read(org.apache.thrift.protocol.TProtocol iprot, Credential struct) throws org.apache.thrift.TException {
568       org.apache.thrift.protocol.TField schemeField;
569       iprot.readStructBegin();
570       while (true)
571       {
572         schemeField = iprot.readFieldBegin();
573         if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
574           break;
575         }
576         switch (schemeField.id) {
577           case 1: // PRINCIPAL
578             if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
579               struct.principal = iprot.readString();
580               struct.setPrincipalIsSet(true);
581             } else { 
582               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
583             }
584             break;
585           case 2: // TOKEN_CLASS
586             if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
587               struct.tokenClass = iprot.readString();
588               struct.setTokenClassIsSet(true);
589             } else { 
590               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
591             }
592             break;
593           case 3: // TOKEN
594             if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
595               struct.token = iprot.readBinary();
596               struct.setTokenIsSet(true);
597             } else { 
598               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
599             }
600             break;
601           case 4: // INSTANCE_ID
602             if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
603               struct.instanceId = iprot.readString();
604               struct.setInstanceIdIsSet(true);
605             } else { 
606               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
607             }
608             break;
609           default:
610             org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
611         }
612         iprot.readFieldEnd();
613       }
614       iprot.readStructEnd();
615 
616       // check for required fields of primitive type, which can't be checked in the validate method
617       struct.validate();
618     }
619 
620     public void write(org.apache.thrift.protocol.TProtocol oprot, Credential struct) throws org.apache.thrift.TException {
621       struct.validate();
622 
623       oprot.writeStructBegin(STRUCT_DESC);
624       if (struct.principal != null) {
625         oprot.writeFieldBegin(PRINCIPAL_FIELD_DESC);
626         oprot.writeString(struct.principal);
627         oprot.writeFieldEnd();
628       }
629       if (struct.tokenClass != null) {
630         oprot.writeFieldBegin(TOKEN_CLASS_FIELD_DESC);
631         oprot.writeString(struct.tokenClass);
632         oprot.writeFieldEnd();
633       }
634       if (struct.token != null) {
635         oprot.writeFieldBegin(TOKEN_FIELD_DESC);
636         oprot.writeBinary(struct.token);
637         oprot.writeFieldEnd();
638       }
639       if (struct.instanceId != null) {
640         oprot.writeFieldBegin(INSTANCE_ID_FIELD_DESC);
641         oprot.writeString(struct.instanceId);
642         oprot.writeFieldEnd();
643       }
644       oprot.writeFieldStop();
645       oprot.writeStructEnd();
646     }
647 
648   }
649 
650   private static class CredentialTupleSchemeFactory implements SchemeFactory {
651     public CredentialTupleScheme getScheme() {
652       return new CredentialTupleScheme();
653     }
654   }
655 
656   private static class CredentialTupleScheme extends TupleScheme<Credential> {
657 
658     @Override
659     public void write(org.apache.thrift.protocol.TProtocol prot, Credential struct) throws org.apache.thrift.TException {
660       TTupleProtocol oprot = (TTupleProtocol) prot;
661       BitSet optionals = new BitSet();
662       if (struct.isSetPrincipal()) {
663         optionals.set(0);
664       }
665       if (struct.isSetTokenClass()) {
666         optionals.set(1);
667       }
668       if (struct.isSetToken()) {
669         optionals.set(2);
670       }
671       if (struct.isSetInstanceId()) {
672         optionals.set(3);
673       }
674       oprot.writeBitSet(optionals, 4);
675       if (struct.isSetPrincipal()) {
676         oprot.writeString(struct.principal);
677       }
678       if (struct.isSetTokenClass()) {
679         oprot.writeString(struct.tokenClass);
680       }
681       if (struct.isSetToken()) {
682         oprot.writeBinary(struct.token);
683       }
684       if (struct.isSetInstanceId()) {
685         oprot.writeString(struct.instanceId);
686       }
687     }
688 
689     @Override
690     public void read(org.apache.thrift.protocol.TProtocol prot, Credential struct) throws org.apache.thrift.TException {
691       TTupleProtocol iprot = (TTupleProtocol) prot;
692       BitSet incoming = iprot.readBitSet(4);
693       if (incoming.get(0)) {
694         struct.principal = iprot.readString();
695         struct.setPrincipalIsSet(true);
696       }
697       if (incoming.get(1)) {
698         struct.tokenClass = iprot.readString();
699         struct.setTokenClassIsSet(true);
700       }
701       if (incoming.get(2)) {
702         struct.token = iprot.readBinary();
703         struct.setTokenIsSet(true);
704       }
705       if (incoming.get(3)) {
706         struct.instanceId = iprot.readString();
707         struct.setInstanceIdIsSet(true);
708       }
709     }
710   }
711 
712 }
713