Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAD password on non windows #146

Merged
merged 7 commits into from
Feb 15, 2017

Conversation

xiangyushawn
Copy link
Contributor

No description provided.

@ajlam ajlam changed the title AAD password on non wiondows AAD password on non windows Feb 14, 2017
@codecov-io
Copy link

codecov-io commented Feb 14, 2017

Codecov Report

Merging #146 into dev will decrease coverage by -0.03%.
The diff coverage is 0%.

@@             Coverage Diff              @@
##                dev     #146      +/-   ##
============================================
- Coverage     27.32%   27.29%   -0.03%     
+ Complexity     1142     1140       -2     
============================================
  Files            95       97       +2     
  Lines         23279    23303      +24     
  Branches       3870     3871       +1     
============================================
+ Hits           6360     6361       +1     
- Misses        15641    15661      +20     
- Partials       1278     1281       +3
Flag Coverage Δ Complexity Δ
#JDBC41 27.18% <ø> (-0.06%) 1135 <ø> (-3)
#JDBC42 27.24% <ø> (-0.02%) 1139 <ø> (-1)
Impacted Files Coverage Δ Complexity Δ
...om/microsoft/sqlserver/jdbc/SQLServerResource.java 100% <ø> (ø) 4 <ø> (ø)
.../microsoft/sqlserver/jdbc/SQLServerConnection.java 37.59% <ø> (+0.06%) 179 <ø> (ø)
...microsoft/sqlserver/jdbc/SQLServerADAL4JUtils.java 0% <ø> (ø) 0 <ø> (?)
.../com/microsoft/sqlserver/jdbc/SqlFedAuthToken.java 0% <ø> (ø) 0 <ø> (?)
src/main/java/microsoft/sql/DateTimeOffset.java 37.14% <ø> (-2.86%) 8% <ø> (-2%)
...om/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java 45.81% <ø> (-0.22%) 182% <ø> (-1%)
...in/java/com/microsoft/sqlserver/jdbc/IOBuffer.java 31.05% <ø> (+0.13%) 0% <ø> (ø)
...om/microsoft/sqlserver/jdbc/SimpleInputStream.java 39.7% <ø> (+1.47%) 10% <ø> (+1%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3733637...4878161. Read the comment docs.

Copy link
Contributor

@v-nisidh v-nisidh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with comments.

if (authenticationString.trim().equalsIgnoreCase(SqlAuthentication.ActiveDirectoryPassword.toString())) {
dllInfo = AuthenticationJNI.getAccessToken(user, password, fedAuthInfo.stsurl, fedAuthInfo.spn, clientConnectionId.toString(),
ActiveDirectoryAuthentication.jdbcFedauthClientId, expirationFileTime);
if (authenticationString.trim().equalsIgnoreCase(SqlAuthentication.ActiveDirectoryPassword.toString())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to have constant on left side while comparing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree, but there are a lot of places to change in the driver, maybe we can have a separate PR for this?

@@ -1270,8 +1285,8 @@ Connection connectInternal(Properties propsIn,
}

if ((!System.getProperty("os.name").toLowerCase().startsWith("windows"))
&& (!authenticationString.equalsIgnoreCase(SqlAuthentication.NotSpecified.toString()))) {
throw new SQLServerException(SQLServerException.getErrString("R_FedAuthOnNonWindows"), null);
&& (authenticationString.equalsIgnoreCase(SqlAuthentication.ActiveDirectoryIntegrated.toString()))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in getFedAuthToken(..) we have similar check of ActiveDirectoryPassword. There we used authenticationString.trim(). Is there any possibility that we are getting authenticationString as null?

Copy link
Contributor Author

@xiangyushawn xiangyushawn Feb 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the default is NotSpecified, it cannot be null. you can search for this line in the file and you will see:
sPropValue = SQLServerDriverStringProperty.AUTHENTICATION.getDefaultValue();

assert null != dllInfo.accessTokenBytes;
// the cause error message uses \\n\\r which does not give correct format
// change it to \r\n to provide correct format
String correctedErrorMessage = e.getCause().getMessage().replaceAll("\\\\r\\\\n", "\r\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any Negative JUnit Test cases ? Which will expect some exception / message / cause.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we have tests for AAD error messages

if (authenticationString.trim().equalsIgnoreCase(SqlAuthentication.ActiveDirectoryPassword.toString())) {
ExecutorService executorService = Executors.newFixedThreadPool(1);
try {
AuthenticationContext context = new AuthenticationContext(fedAuthInfo.stsurl, false, executorService);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: May be we can have ADALAuth.getAccesstoken() in which we can create AuthenctioanContext and acquireToken.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good suggestion. It's done now, I have used modular approach now

import com.microsoft.sqlserver.jdbc.SQLServerConnection.ActiveDirectoryAuthentication;
import com.microsoft.sqlserver.jdbc.SQLServerConnection.SqlFedAuthInfo;

class SQLServerADAL4JUtils {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you do not want public class? By default this will use package level visibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would we want it to be public?

private static final int GetAccessTokenTansisentError = 2;
private static final int GetAccessTokenOtherError = 3;
class ActiveDirectoryAuthentication {
static final String jdbcFedauthClientId = "7f98cb04-cd1e-40df-9140-3bf7e2cea4db";
Copy link
Contributor

@v-nisidh v-nisidh Feb 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final static instance variables should be in CAPS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@v-nisidh v-nisidh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Having 2 review comments.

Copy link
Contributor

@v-nisidh v-nisidh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

@xiangyushawn xiangyushawn merged commit d6f1000 into microsoft:dev Feb 15, 2017
@xiangyushawn xiangyushawn deleted the AAD-Password-on-non-Wiondows branch February 15, 2017 21:06
@v-nisidh v-nisidh added this to the 6.1.4 milestone Feb 15, 2017
@lilgreenbird lilgreenbird added this to Closed/Merged PRs in MSSQL JDBC Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
MSSQL JDBC
  
Closed/Merged PRs
Development

Successfully merging this pull request may close these issues.

None yet

3 participants