示例#1
1
  @Test
  public void testToThrift() throws DestroyFailedException {
    // verify thrift serialization
    Credentials creds = new Credentials("test", new PasswordToken("testing"));
    TCredentials tCreds = creds.toThrift(new MockInstance());
    assertEquals("test", tCreds.getPrincipal());
    assertEquals(PasswordToken.class.getName(), tCreds.getTokenClassName());
    assertArrayEquals(
        AuthenticationTokenSerializer.serialize(new PasswordToken("testing")), tCreds.getToken());

    // verify that we can't serialize if it's destroyed
    creds.getToken().destroy();
    try {
      creds.toThrift(new MockInstance());
      fail();
    } catch (Exception e) {
      assertTrue(e instanceof RuntimeException);
      assertTrue(e.getCause() instanceof AccumuloSecurityException);
      assertTrue(
          AccumuloSecurityException.class
              .cast(e.getCause())
              .getSecurityErrorCode()
              .equals(SecurityErrorCode.TOKEN_EXPIRED));
    }
  }
示例#2
0
  public boolean equals(TCredentials that) {
    if (that == null) return false;

    boolean this_present_principal = true && this.isSetPrincipal();
    boolean that_present_principal = true && that.isSetPrincipal();
    if (this_present_principal || that_present_principal) {
      if (!(this_present_principal && that_present_principal)) return false;
      if (!this.principal.equals(that.principal)) return false;
    }

    boolean this_present_tokenClassName = true && this.isSetTokenClassName();
    boolean that_present_tokenClassName = true && that.isSetTokenClassName();
    if (this_present_tokenClassName || that_present_tokenClassName) {
      if (!(this_present_tokenClassName && that_present_tokenClassName)) return false;
      if (!this.tokenClassName.equals(that.tokenClassName)) return false;
    }

    boolean this_present_token = true && this.isSetToken();
    boolean that_present_token = true && that.isSetToken();
    if (this_present_token || that_present_token) {
      if (!(this_present_token && that_present_token)) return false;
      if (!this.token.equals(that.token)) return false;
    }

    boolean this_present_instanceId = true && this.isSetInstanceId();
    boolean that_present_instanceId = true && that.isSetInstanceId();
    if (this_present_instanceId || that_present_instanceId) {
      if (!(this_present_instanceId && that_present_instanceId)) return false;
      if (!this.instanceId.equals(that.instanceId)) return false;
    }

    return true;
  }
示例#3
0
 @Override
 public void write(org.apache.thrift.protocol.TProtocol prot, TCredentials struct)
     throws org.apache.thrift.TException {
   TTupleProtocol oprot = (TTupleProtocol) prot;
   BitSet optionals = new BitSet();
   if (struct.isSetPrincipal()) {
     optionals.set(0);
   }
   if (struct.isSetTokenClassName()) {
     optionals.set(1);
   }
   if (struct.isSetToken()) {
     optionals.set(2);
   }
   if (struct.isSetInstanceId()) {
     optionals.set(3);
   }
   oprot.writeBitSet(optionals, 4);
   if (struct.isSetPrincipal()) {
     oprot.writeString(struct.principal);
   }
   if (struct.isSetTokenClassName()) {
     oprot.writeString(struct.tokenClassName);
   }
   if (struct.isSetToken()) {
     oprot.writeBinary(struct.token);
   }
   if (struct.isSetInstanceId()) {
     oprot.writeString(struct.instanceId);
   }
 }
示例#4
0
 /** Performs a deep copy on <i>other</i>. */
 public TCredentials(TCredentials other) {
   if (other.isSetPrincipal()) {
     this.principal = other.principal;
   }
   if (other.isSetTokenClassName()) {
     this.tokenClassName = other.tokenClassName;
   }
   if (other.isSetToken()) {
     this.token = org.apache.thrift.TBaseHelper.copyBinary(other.token);
   }
   if (other.isSetInstanceId()) {
     this.instanceId = other.instanceId;
   }
 }
示例#5
0
    public void write(org.apache.thrift.protocol.TProtocol oprot, TCredentials struct)
        throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      if (struct.principal != null) {
        oprot.writeFieldBegin(PRINCIPAL_FIELD_DESC);
        oprot.writeString(struct.principal);
        oprot.writeFieldEnd();
      }
      if (struct.tokenClassName != null) {
        oprot.writeFieldBegin(TOKEN_CLASS_NAME_FIELD_DESC);
        oprot.writeString(struct.tokenClassName);
        oprot.writeFieldEnd();
      }
      if (struct.token != null) {
        oprot.writeFieldBegin(TOKEN_FIELD_DESC);
        oprot.writeBinary(struct.token);
        oprot.writeFieldEnd();
      }
      if (struct.instanceId != null) {
        oprot.writeFieldBegin(INSTANCE_ID_FIELD_DESC);
        oprot.writeString(struct.instanceId);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }
示例#6
0
    public void read(org.apache.thrift.protocol.TProtocol iprot, TCredentials struct)
        throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TField schemeField;
      iprot.readStructBegin();
      while (true) {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
          break;
        }
        switch (schemeField.id) {
          case 1: // PRINCIPAL
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.principal = iprot.readString();
              struct.setPrincipalIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // TOKEN_CLASS_NAME
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.tokenClassName = iprot.readString();
              struct.setTokenClassNameIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 3: // TOKEN
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.token = iprot.readBinary();
              struct.setTokenIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 4: // INSTANCE_ID
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.instanceId = iprot.readString();
              struct.setInstanceIdIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();

      // check for required fields of primitive type, which can't be checked in the validate method
      struct.validate();
    }
 @Override
 public TCredentials toThrift(Instance instance) {
   if (!AS_THRIFT.getInstanceId().equals(instance.getInstanceID()))
     throw new IllegalArgumentException(
         "Unexpected instance used for "
             + SystemCredentials.class.getSimpleName()
             + ": "
             + instance.getInstanceID());
   return AS_THRIFT;
 }
示例#8
0
  @Override
  public int compareTo(TCredentials other) {
    if (!getClass().equals(other.getClass())) {
      return getClass().getName().compareTo(other.getClass().getName());
    }

    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetPrincipal()).compareTo(other.isSetPrincipal());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetPrincipal()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.principal, other.principal);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetTokenClassName()).compareTo(other.isSetTokenClassName());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetTokenClassName()) {
      lastComparison =
          org.apache.thrift.TBaseHelper.compareTo(this.tokenClassName, other.tokenClassName);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetToken()).compareTo(other.isSetToken());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetToken()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.token, other.token);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetInstanceId()).compareTo(other.isSetInstanceId());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetInstanceId()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.instanceId, other.instanceId);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }
示例#9
0
 @Override
 public void read(org.apache.thrift.protocol.TProtocol prot, TCredentials struct)
     throws org.apache.thrift.TException {
   TTupleProtocol iprot = (TTupleProtocol) prot;
   BitSet incoming = iprot.readBitSet(4);
   if (incoming.get(0)) {
     struct.principal = iprot.readString();
     struct.setPrincipalIsSet(true);
   }
   if (incoming.get(1)) {
     struct.tokenClassName = iprot.readString();
     struct.setTokenClassNameIsSet(true);
   }
   if (incoming.get(2)) {
     struct.token = iprot.readBinary();
     struct.setTokenIsSet(true);
   }
   if (incoming.get(3)) {
     struct.instanceId = iprot.readString();
     struct.setInstanceIdIsSet(true);
   }
 }