/** call this when the distributed system ID has been modified */
 @edu.umd.cs.findbugs.annotations.SuppressWarnings(
     value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD",
     justification =
         "Only applicable in client DS and in that case too multiple instances do not modify it at the same time.")
 public void updateID(DistributedMember idm) {
   //    this.transientPort = ((InternalDistributedMember)this.memberId).getPort();
   //    if (this.transientPort == 0) {
   //      InternalDistributedSystem.getLoggerI18n().warning(
   //          LocalizedStrings.DEBUG,
   //          "updating client ID when member port is zero: " + this.memberId,
   //          new Exception("stack trace")
   //          );
   //    }
   HeapDataOutputStream hdos = new HeapDataOutputStream(256, Version.CURRENT);
   try {
     DataSerializer.writeObject(idm, hdos);
   } catch (IOException e) {
     throw new InternalGemFireException("Unable to serialize member: " + this.memberId, e);
   }
   this.identity = hdos.toByteArray();
   if (this.memberId != null && this.memberId == systemMemberId) {
     systemMemberId = idm;
     // client_side_identity = this.identity;
   }
   this.memberId = idm;
   this._toString = null; // make sure we don't retain the old ID representation in toString
 }
    public AuthenticateUserOpImpl(Connection con, ExecutablePool pool) {
      super(MessageType.USER_CREDENTIAL_MESSAGE, 1);
      byte[] credentialBytes = null;
      // TODO this is not a valid way to create a member ID
      DistributedMember server =
          new InternalDistributedMember(
              con.getSocket().getInetAddress(), con.getSocket().getPort(), false);
      DistributedSystem sys = InternalDistributedSystem.getConnectedInstance();
      String authInitMethod =
          sys.getProperties().getProperty(DistributionConfig.SECURITY_CLIENT_AUTH_INIT_NAME);
      Properties tmpSecurityProperties = sys.getSecurityProperties();

      // LOG: following passes the DS API LogWriters into the security API
      Properties credentials =
          HandShake.getCredentials(
              authInitMethod,
              tmpSecurityProperties,
              server,
              false,
              (InternalLogWriter) sys.getLogWriter(),
              (InternalLogWriter) sys.getSecurityLogWriter());

      getMessage().setEarlyAck(Message.MESSAGE_HAS_SECURE_PART);
      HeapDataOutputStream heapdos = new HeapDataOutputStream(Version.CURRENT);
      try {
        DataSerializer.writeProperties(credentials, heapdos);
        credentialBytes = ((ConnectionImpl) con).getHandShake().encryptBytes(heapdos.toByteArray());
      } catch (Exception e) {
        throw new ServerOperationException(e);
      } finally {
        heapdos.close();
      }
      getMessage().addBytesPart(credentialBytes);
    }
  public static byte[] initializeAndGetDSIdentity(DistributedSystem sys) {
    byte[] client_side_identity = null;
    if (sys == null) {
      // DistributedSystem is required now before handshaking -Kirk
      throw new IllegalStateException(
          LocalizedStrings
              .ClientProxyMembershipID_ATTEMPTING_TO_HANDSHAKE_WITH_CACHESERVER_BEFORE_CREATING_DISTRIBUTEDSYSTEM_AND_CACHE
              .toLocalizedString());
    }
    // if (system != sys)
    {
      // DS already exists... make sure it's for current DS connection
      systemMemberId = sys.getDistributedMember();
      try {
        HeapDataOutputStream hdos = new HeapDataOutputStream(256, Version.CURRENT);
        DataSerializer.writeObject(systemMemberId, hdos);
        client_side_identity = hdos.toByteArray();
      } catch (IOException ioe) {
        throw new InternalGemFireException(
            LocalizedStrings.ClientProxyMembershipID_UNABLE_TO_SERIALIZE_IDENTITY
                .toLocalizedString(),
            ioe);
      }

      system = sys;
    }
    return client_side_identity;
  }
  public void testRVVSerialization() throws IOException, ClassNotFoundException {
    DiskStoreID ownerId = new DiskStoreID(0, 0);
    DiskStoreID id1 = new DiskStoreID(0, 1);
    DiskStoreID id2 = new DiskStoreID(1, 0);

    DiskRegionVersionVector rvv = new DiskRegionVersionVector(ownerId);
    rvv.recordVersion(id1, 5);
    rvv.recordVersion(id1, 6);
    rvv.recordVersion(id1, 7);
    rvv.recordVersion(id1, 9);
    rvv.recordVersion(id1, 20);
    rvv.recordVersion(id1, 11);
    rvv.recordVersion(id1, 12);
    rvv.recordGCVersion(id2, 5);
    rvv.recordGCVersion(id1, 3);

    assertTrue(rvv.sameAs(rvv.getCloneForTransmission()));

    HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
    InternalDataSerializer.writeObject(rvv.getCloneForTransmission(), out);
    byte[] bytes = out.toByteArray();

    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes));
    DiskRegionVersionVector rvv2 = InternalDataSerializer.readObject(dis);

    assertTrue(rvv.sameAs(rvv2));
  }
    @Override
    protected void sendMessage(Connection cnx) throws Exception {
      HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
      byte[] secureBytes = null;
      hdos.writeLong(cnx.getConnectionID());
      if (this.securityProperties != null) {
        byte[] credentialBytes = null;
        // TODO this is not a valid way to create a member ID
        DistributedMember server =
            new InternalDistributedMember(
                cnx.getSocket().getInetAddress(), cnx.getSocket().getPort(), false);
        DistributedSystem sys = InternalDistributedSystem.getConnectedInstance();
        String authInitMethod =
            sys.getProperties().getProperty(DistributionConfig.SECURITY_CLIENT_AUTH_INIT_NAME);

        Properties credentials =
            HandShake.getCredentials(
                authInitMethod,
                this.securityProperties,
                server,
                false,
                (InternalLogWriter) sys.getLogWriter(),
                (InternalLogWriter) sys.getSecurityLogWriter());
        HeapDataOutputStream heapdos = new HeapDataOutputStream(Version.CURRENT);
        try {
          DataSerializer.writeProperties(credentials, heapdos);
          credentialBytes =
              ((ConnectionImpl) cnx).getHandShake().encryptBytes(heapdos.toByteArray());
        } finally {
          heapdos.close();
        }
        getMessage().addBytesPart(credentialBytes);
      }
      try {
        secureBytes = ((ConnectionImpl) cnx).getHandShake().encryptBytes(hdos.toByteArray());
      } finally {
        hdos.close();
      }
      getMessage().setSecurePart(secureBytes);
      getMessage().send(false);
    }
Esempio n. 6
0
 public static String formulateJsonForListQueriesCall(Region<String, String> queryRegion) {
   HeapDataOutputStream outputStream =
       new HeapDataOutputStream(com.gemstone.gemfire.internal.Version.CURRENT);
   try {
     JsonGenerator generator =
         enableDisableJSONGeneratorFeature(
             getObjectMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8));
     JsonWriter.writeQueryListAsJson(generator, "queries", queryRegion);
     generator.close();
     return new String(outputStream.toByteArray());
   } catch (IOException e) {
     throw new RuntimeException(e.getMessage());
   } finally {
     outputStream.close();
   }
 }
Esempio n. 7
0
  public static String convertStructToJson(StructImpl structSet) throws JSONException {
    HeapDataOutputStream outputStream =
        new HeapDataOutputStream(com.gemstone.gemfire.internal.Version.CURRENT);

    try {
      JsonGenerator generator =
          enableDisableJSONGeneratorFeature(
              getObjectMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8));
      JsonWriter.writeStructAsJson(generator, structSet);
      generator.close();
      return new String(outputStream.toByteArray());
    } catch (IOException e) {
      throw new RuntimeException(e.getMessage());
    } finally {
      outputStream.close();
    }
  }
Esempio n. 8
0
  public static String formulateJsonForGetOnKey(Object value) throws JSONException {
    HeapDataOutputStream outputStream =
        new HeapDataOutputStream(com.gemstone.gemfire.internal.Version.CURRENT);

    try {
      JsonGenerator generator =
          enableDisableJSONGeneratorFeature(
              getObjectMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8));
      JsonWriter.writeValueAsJson(generator, value, "GET_ON_KEY_RESPONSE");
      generator.close();
      return new String(outputStream.toByteArray());
    } catch (IOException e) {
      throw new RuntimeException(e.getMessage());
    } finally {
      outputStream.close();
    }
  }
Esempio n. 9
0
 public static String formulateJsonForListFunctionsCall(Set<String> functionIds) {
   HeapDataOutputStream outputStream =
       new HeapDataOutputStream(com.gemstone.gemfire.internal.Version.CURRENT);
   try {
     JsonGenerator generator =
         enableDisableJSONGeneratorFeature(
             getObjectMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8));
     generator.writeStartObject();
     generator.writeFieldName("functions");
     JsonWriter.writeCollectionAsJson(generator, functionIds);
     generator.writeEndObject();
     generator.close();
     return new String(outputStream.toByteArray());
   } catch (IOException e) {
     throw new RuntimeException(e.getMessage());
   } finally {
     outputStream.close();
   }
 }
Esempio n. 10
0
  public static String formulateJsonForGetOnMultipleKey(
      Collection<Object> collection, String regionName) throws JSONException {
    HeapDataOutputStream outputStream =
        new HeapDataOutputStream(com.gemstone.gemfire.internal.Version.CURRENT);

    try {
      JsonGenerator generator =
          enableDisableJSONGeneratorFeature(
              getObjectMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8));
      generator.writeStartObject();
      generator.writeFieldName(regionName);
      JsonWriter.writeCollectionAsJson(generator, collection);
      generator.writeEndObject();
      generator.close();
      return new String(outputStream.toByteArray());
    } catch (IOException e) {
      throw new RuntimeException(e.getMessage());
    } finally {
      outputStream.close();
    }
  }