skip to main content
Using the Driver : Using Authentication : Configuring the Driver for Kerberos Authentication : Specifying User Credentials for Kerberos Authentication (Delegation of Credentials)

Try DataDirect Drivers Now
Specifying User Credentials for Kerberos Authentication (Delegation of Credentials)
By default, when Kerberos authentication is used, the driver takes advantage of the user name and password maintained by the operating system to authenticate users to the database. By allowing the database to share the user name and password used for the operating system, users with a valid operating system account can log into the database without supplying a user name and password.
Many application servers or Web servers act on behalf of the client user logged on the machine on which the application is running, rather than the server user. If you want the driver to use user credentials other than the server the operating system user name and password, include code in your application to obtain and pass a used for authentication as shown in the following example.

import java.sql.*;
// The following code creates a instance
// used for authentication. Refer to the Java Authentication
// and Authorization Service documentation for details on using a
// LoginContext to obtain a Subject.
LoginContext lc = null;
Subject subject = null;
try {
    lc = new LoginContext("JaasSample", new TextCallbackHandler());
    subject = lc.getSubject();
catch (Exception le) {
    ... // display login error
}// This application passes the
// to the driver by executing the driver code as the subject
Connection con =
   (Connection) Subject.doAs(subject, new PrivilegedExceptionAction() {
   public Object run() {
         Connection con = null;
    try {
         String url = "jdbc:datadirect:sparksql://myServer:10000";
         con = DriverManager.getConnection(url);
    catch (Exception except) {
     ... //log the connection error
            Return null;
         return con;
//  This application now has a connection that was authenticated with
//  the subject. The application can now use the connection.
Statement   stmt = con.createStatement();
String      sql = "SELECT * FROM employee";
ResultSet   rs = stmt.executeQuery(sql);
... // do something with the results