-
Notifications
You must be signed in to change notification settings - Fork 435
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
AAD password on non windows #146
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
There was a problem hiding this 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())) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()))) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved.
No description provided.