-
Notifications
You must be signed in to change notification settings - Fork 426
Native platform GSS Integration
Terry edited this page Nov 2, 2022
·
2 revisions
The following is a code example of how to use native platform GSS with the driver.
GSSCredential credential = GSSManager.getInstance().createCredential(null, GSSCredential.DEFAULT_LIFETIME, new Oid("1.2.840.113554.1.2.2"), GSSCredential.ACCEPT_ONLY);
SQLServerDataSource ds = new SQLServerDataSource();
dataSource.setURL("jdbc:sqlserver://<your-server-name>;databaseName=<your-database-name>;integratedSecurity=true;authenticationScheme=JavaKerberos;");
ds.setGSSCredentials(credential);
ds.getConnection();
try (Connection conn = ds.getConnection()) {
ResultSet rs = conn.createStatement().executeQuery("select @@version");
rs.next();
System.out.println(rs.getString(1));
}
In addition to the above code, you will need to provide the following JVM arguments:
-Dsun.security.jgss.native=true
-Djavax.security.auth.useSubjectCredsOnly=false
-Dsun.security.jgss.lib=path/to/native/gss/library // This is optional
For more information on the above JVM arguments refer to this document.