Skip to content

Commit

Permalink
Fixed issue when redirected token contains named instance in serverna…
Browse files Browse the repository at this point in the history
…me (#1568)
  • Loading branch information
lilgreenbird committed Apr 27, 2021
1 parent ae65652 commit 40a6a22
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 57 deletions.
47 changes: 0 additions & 47 deletions src/main/java/com/microsoft/sqlserver/jdbc/FailOverInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package com.microsoft.sqlserver.jdbc;

import java.io.Serializable;
import java.text.MessageFormat;
import java.util.logging.Level;

Expand Down Expand Up @@ -108,49 +107,3 @@ synchronized void failoverAdd(SQLServerConnection connection, boolean actualUseF
}
}
}


// A simple readonly placeholder class to store the current server info.
// We need this class so during a connection open we can keep a copy of the current failover info stable
// This is also used to keep the standalone primary server connection information.
//
final class ServerPortPlaceHolder implements Serializable {
/**
* Always update serialVersionUID when prompted.
*/
private static final long serialVersionUID = 7393779415545731523L;

private final String serverName;
private final int port;
private final String instanceName;
private final boolean checkLink;
private final SQLServerConnectionSecurityManager securityManager;

ServerPortPlaceHolder(String name, int conPort, String instance, boolean fLink) {
serverName = name;
port = conPort;
instanceName = instance;
checkLink = fLink;
securityManager = new SQLServerConnectionSecurityManager(serverName, port);
doSecurityCheck();
}

// accessors
int getPortNumber() {
return port;
}

String getServerName() {
return serverName;
}

String getInstanceName() {
return instanceName;
}

void doSecurityCheck() {
securityManager.checkConnect();
if (checkLink)
securityManager.checkLink();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2817,9 +2817,9 @@ private InetSocketAddress connectHelper(ServerPortPlaceHolder serverInfo, int ti

// if the timeout is infinite slices are infinite too.
tdsChannel = new TDSChannel(this);
InetSocketAddress inetSocketAddress = tdsChannel.open(serverInfo.getServerName(), serverInfo.getPortNumber(),
(0 == timeOutFullInSeconds) ? 0 : timeOutSliceInMillis, useParallel, useTnir, isTnirFirstAttempt,
timeOutsliceInMillisForFullTimeout);
InetSocketAddress inetSocketAddress = tdsChannel.open(serverInfo.getParsedServerName(),
serverInfo.getPortNumber(), (0 == timeOutFullInSeconds) ? 0 : timeOutSliceInMillis, useParallel,
useTnir, isTnirFirstAttempt, timeOutsliceInMillisForFullTimeout);

setState(State.Connected);

Expand All @@ -2830,8 +2830,8 @@ private InetSocketAddress connectHelper(ServerPortPlaceHolder serverInfo, int ti

// If prelogin negotiated SSL encryption then, enable it on the TDS channel.
if (TDS.ENCRYPT_NOT_SUP != negotiatedEncryptionLevel) {
tdsChannel.enableSSL(serverInfo.getServerName(), serverInfo.getPortNumber(), clientCertificate, clientKey,
clientKeyPassword);
tdsChannel.enableSSL(serverInfo.getParsedServerName(), serverInfo.getPortNumber(), clientCertificate,
clientKey, clientKeyPassword);
clientKeyPassword = "";
}

Expand Down Expand Up @@ -4369,7 +4369,6 @@ final void processEnvChange(TDSReader tdsReader) throws SQLServerException {

isRoutedInCurrentAttempt = true;
routingInfo = new ServerPortPlaceHolder(routingServerName, routingPortNumber, null, integratedSecurity);

break;

// Error on unrecognized, unused ENVCHANGES
Expand Down Expand Up @@ -5230,10 +5229,10 @@ final boolean complete(LogonCommand logonCommand, TDSReader tdsReader) throws SQ
// fails
TDS.LOGIN_OPTION2_ODBC_ON | // Use ODBC defaults (ANSI_DEFAULTS ON, IMPLICIT_TRANSACTIONS OFF, TEXTSIZE
// inf, ROWCOUNT inf)
(replication ? TDS.LOGIN_OPTION2_USER_SQLREPL_ON : TDS.LOGIN_OPTION2_USER_SQLREPL_OFF) |
(integratedSecurity ? // integrated security if integratedSecurity requested
TDS.LOGIN_OPTION2_INTEGRATED_SECURITY_ON
: TDS.LOGIN_OPTION2_INTEGRATED_SECURITY_OFF)));
(replication ? TDS.LOGIN_OPTION2_USER_SQLREPL_ON : TDS.LOGIN_OPTION2_USER_SQLREPL_OFF)
| (integratedSecurity ? // integrated security if integratedSecurity requested
TDS.LOGIN_OPTION2_INTEGRATED_SECURITY_ON
: TDS.LOGIN_OPTION2_INTEGRATED_SECURITY_OFF)));

// TypeFlags
tdsWriter.writeByte((byte) (TDS.LOGIN_SQLTYPE_DEFAULT | (applicationIntent != null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
* available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/

package com.microsoft.sqlserver.jdbc;

import java.io.Serializable;


/**
* A simple readonly placeholder class to store the current server info. We need this class so during a connection open
* we can keep a copy of the current failover info stable This is also used to keep the standalone primary server
* connection information.
*/
final class ServerPortPlaceHolder implements Serializable {
/**
* Always update serialVersionUID when prompted.
*/
private static final long serialVersionUID = 7393779415545731523L;

private final String serverName;
private final String parsedServerName;
private final int port;
private final String instanceName;
private final boolean checkLink;
private final SQLServerConnectionSecurityManager securityManager;

ServerPortPlaceHolder(String name, int conPort, String instance, boolean fLink) {
serverName = name;

// serverName without named instance
int px = serverName.indexOf('\\');
parsedServerName = (px >= 0) ? serverName.substring(0, px) : serverName;

port = conPort;
instanceName = instance;
checkLink = fLink;
securityManager = new SQLServerConnectionSecurityManager(serverName, port);
doSecurityCheck();
}

// accessors
int getPortNumber() {
return port;
}

String getServerName() {
return serverName;
}

String getInstanceName() {
return instanceName;
}

String getParsedServerName() {
return parsedServerName;
}

void doSecurityCheck() {
securityManager.checkConnect();
if (checkLink)
securityManager.checkLink();
}
}

0 comments on commit 40a6a22

Please sign in to comment.