ConnectionImpl getConnection(InternalDistributedSystem ds, CancelCriterion cancelCriterion) { return new ConnectionImpl(ds, cancelCriterion); }
void destroyConnection(ConnectionImpl connection) { connection.destroy(); }
@Override public ByteBuffer getCommBuffer() throws SocketException { if (isDestroyed()) { // see bug 52193. Since the code used to see this // as an attempt to use a close socket just throw // a SocketException. throw new SocketException("socket was closed"); } return commBuffer; }
public ConnectionImpl connectClientToServer(ServerLocation location, boolean forQueue) throws IOException { ConnectionImpl connection = null; boolean initialized = false; try { connection = getConnection(this.ds, this.cancelCriterion); ClientSideHandshake connHandShake = getClientSideHandshake(handshake); connection.connect(endpointManager, location, connHandShake, socketBufferSize, handshakeTimeout, readTimeout, getCommMode(forQueue), this.gatewaySender, this.socketCreator); connection.setHandshake(connHandShake); initialized = true; return connection; } finally { if (!initialized && connection != null) { if (logger.isDebugEnabled()) { logger.debug("Destroying failed connection to {}", location); } destroyConnection(connection); } } }
@Override public Object execute(Op op) throws Exception { Object result; // Do not synchronize when used for GatewaySender // as the same connection is being used if ((op instanceof AbstractOp) && ((AbstractOp) op).isGatewaySenderOp()) { result = op.attempt(this); endpoint.updateLastExecute(); return result; } synchronized (this) { if (op instanceof ExecuteFunctionOpImpl || op instanceof ExecuteRegionFunctionOpImpl || op instanceof ExecuteRegionFunctionSingleHopOpImpl) { int earliertimeout = this.getSocket().getSoTimeout(); this.getSocket().setSoTimeout(getClientFunctionTimeout()); try { result = op.attempt(this); } finally { this.getSocket().setSoTimeout(earliertimeout); } } else { result = op.attempt(this); } } endpoint.updateLastExecute(); return result; }
@Test(expected = GemFireSecurityException.class) public void failedConnectionIsDestroyed() throws IOException { ConnectionConnector spyConnector = spy(new ConnectionConnector(endpointManager, ds, 0, 0, 0, cancelCriterion, false, null, socketCreator, handshake)); doReturn(connection).when(spyConnector).getConnection(ds, cancelCriterion); doReturn(handshake).when(spyConnector).getClientSideHandshake(handshake); when(connection.connect(any(), any(), any(), anyInt(), anyInt(), anyInt(), any(), any(), any())) .thenThrow(new GemFireSecurityException("Expected exception")); try { spyConnector.connectClientToServer(mock(ServerLocation.class), false); } finally { verify(spyConnector).destroyConnection(any()); } }
@Override protected void sendMessage(Connection cnx) throws Exception { HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT); byte[] secureBytes = null; hdos.writeLong(cnx.getConnectionID()); Object userId = UserAttributes.userAttributes.get().getServerToId().get(cnx.getServer()); if (userId == null) { // This will ensure that this op is retried on another server, unless // the retryCount is exhausted. Fix for Bug 41501 throw new ServerConnectivityException("Connection error while authenticating user"); } hdos.writeLong((Long) userId); try { secureBytes = ((ConnectionImpl) cnx).encryptBytes(hdos.toByteArray()); } finally { hdos.close(); } getMessage().setSecurePart(secureBytes); getMessage().send(false); }
private void addBytes(byte functionStateOrHasResult) { if (ConnectionImpl .getClientFunctionTimeout() == ConnectionImpl.DEFAULT_CLIENT_FUNCTION_TIMEOUT) { getMessage().addBytesPart(new byte[] {functionStateOrHasResult}); } else { byte[] bytes = new byte[5]; bytes[0] = functionStateOrHasResult; Part.encodeInt(ConnectionImpl.getClientFunctionTimeout(), bytes, 1); getMessage().addBytesPart(bytes); } }
public static void loadEmergencyClasses() { ConnectionImpl.loadEmergencyClasses(); }
/** * Process the security information in a response from the server. If the server sends a security * "part" we must process it so all subclasses should allow this method to be invoked. * * @see ServerConnection#updateAndGetSecurityPart() */ protected void processSecureBytes(Connection cnx, Message message) throws Exception { if (cnx.getServer().getRequiresCredentials()) { if (!message.isSecureMode()) { // This can be seen during shutdown if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER_VERBOSE)) { logger.trace(LogMarker.BRIDGE_SERVER_VERBOSE, "Response message from {} for {} has no secure part.", cnx, this); } return; } byte[] partBytes = message.getSecureBytes(); if (partBytes == null) { if (logger.isDebugEnabled()) { logger.debug("Response message for {} has no bytes in secure part.", this); } return; } byte[] bytes = ((ConnectionImpl) cnx).decryptBytes(partBytes); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes)); cnx.setConnectionID(dis.readLong()); } }
if (msg != null) { msg.setComms(cnx.getSocket(), cnx.getInputStream(), cnx.getOutputStream(), ((ConnectionImpl) cnx).getCommBufferForAsyncRead(), cnx.getStats()); if (msg instanceof ChunkedMessage) { try {
try { DataSerializer.writeProperties(credentials, heapdos); credentialBytes = ((ConnectionImpl) cnx).encryptBytes(heapdos.toByteArray()); } finally { heapdos.close(); secureBytes = ((ConnectionImpl) cnx).encryptBytes(hdos.toByteArray()); } finally { hdos.close();
private void addBytes(byte functionState) { if (ConnectionImpl .getClientFunctionTimeout() == ConnectionImpl.DEFAULT_CLIENT_FUNCTION_TIMEOUT) { getMessage().addBytesPart(new byte[] {functionState}); } else { byte[] bytes = new byte[5]; bytes[0] = functionState; Part.encodeInt(ConnectionImpl.getClientFunctionTimeout(), bytes, 1); getMessage().addBytesPart(bytes); } }
public static void loadEmergencyClasses() { ConnectionImpl.loadEmergencyClasses(); }
} else { cnx.getServer().setRequiresCredentials(true); byte[] decrypted = ((ConnectionImpl) cnx).decryptBytes(bytes); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(decrypted)); userId = dis.readLong();
public AuthenticateUserOpImpl(Connection con, ExecutablePool pool) { super(MessageType.USER_CREDENTIAL_MESSAGE, 1); byte[] credentialBytes = null; DistributedMember server = new InternalDistributedMember(con.getSocket().getInetAddress(), con.getSocket().getPort(), false); DistributedSystem sys = InternalDistributedSystem.getConnectedInstance(); String authInitMethod = sys.getProperties().getProperty(SECURITY_CLIENT_AUTH_INIT); 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().setMessageHasSecurePartFlag(); HeapDataOutputStream heapdos = new HeapDataOutputStream(Version.CURRENT); try { DataSerializer.writeProperties(credentials, heapdos); credentialBytes = ((ConnectionImpl) con).encryptBytes(heapdos.toByteArray()); } catch (Exception e) { throw new ServerOperationException(e); } finally { heapdos.close(); } getMessage().addBytesPart(credentialBytes); }
private void addBytes(byte isReexecute, byte fnStateOrHasResult) { if (ConnectionImpl .getClientFunctionTimeout() == ConnectionImpl.DEFAULT_CLIENT_FUNCTION_TIMEOUT) { if (isReexecute == 1) { getMessage().addBytesPart( new byte[] {AbstractExecution.getReexecuteFunctionState(fnStateOrHasResult)}); } else { getMessage().addBytesPart(new byte[] {fnStateOrHasResult}); } } else { byte[] bytes = new byte[5]; if (isReexecute == 1) { bytes[0] = AbstractExecution.getReexecuteFunctionState(fnStateOrHasResult); } else { bytes[0] = fnStateOrHasResult; } Part.encodeInt(ConnectionImpl.getClientFunctionTimeout(), bytes, 1); getMessage().addBytesPart(bytes); } }
public ByteBuffer getCommBufferForAsyncRead() throws SocketException { if (isDestroyed()) { // see bug 52193. Since the code used to see this // as an attempt to use a close socket just throw // a SocketException. throw new SocketException("socket was closed"); } return commBufferForAsyncRead; }
@Override public void close(boolean keepAlive) throws Exception { try { // if a forced-disconnect has occurred, we can't send messages to anyone boolean sendCloseMsg = !TEST_DURABLE_CLIENT_CRASH; if (sendCloseMsg) { try { ((InternalDistributedSystem) ds).getDistributionManager(); } catch (CancelException e) { // distribution has stopped Throwable t = e.getCause(); if (t instanceof ForcedDisconnectException) { // we're crashing - don't attempt to send a message (bug 39317) sendCloseMsg = false; } } } if (sendCloseMsg) { if (logger.isDebugEnabled()) { logger.debug("Closing connection {} with keepAlive: {}", this, keepAlive); } CloseConnectionOp.execute(this, keepAlive); } } finally { destroy(); } }
hdos.writeLong(cnx.getConnectionID()); hdos.writeLong(userId); getMessage().setSecurePart(((ConnectionImpl) cnx).encryptBytes(hdos.toByteArray())); } finally { hdos.close();