Skip to content

Native platform GSS Integration

Terry Chow edited this page Sep 27, 2023 · 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();
    ds.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.

Clone this wiki locally