Elffuss BraidHub

kikocis/java-driver public

35167456ffff · 3.1 KiBRawPermalink
1/*
2 * Copyright (C) 2012-2015 DataStax Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.datastax.driver.auth;
17
18import com.datastax.driver.core.AuthProvider;
19import com.datastax.driver.core.Authenticator;
20import com.datastax.driver.core.exceptions.AuthenticationException;
21
22import java.net.InetSocketAddress;
23
24/**
25 * AuthProvider which supplies authenticator instances for clients to connect t
26 * DSE clusters secured with Kerberos
27 * <p/>
28 * The SASL protocol name defaults to "dse"; should you need to change that
29 * it can be overridden using the <code>dse.sasl.protocol</code> system property.
30 * <p/>
31 * Keytab and ticket cache settings are specified using a standard JAAS
32 * configuration file. The location of the file can be set using the
33 * <code>java.security.auth.login.config</code> system property or by adding a
34 * <code>login.config.url.n</code> entry in the <code>java.security</code> properties
35 * file.
36 * <p/>
37 * See the following documents for further details on the
38 * <a href="https://docs.oracle.com/javase/6/docs/technotes/guides/security/jgss/tutorials/LoginConfigFile.html">JAAS Login Configuration File</a> and the
39 * <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/jaas/tutorials/GeneralAcnOnly.html">JAAS Authentication Tutorial</a>
40 * for more on JAAS in general.
41 * <p/>
42 * <h1>Authentication using ticket cache</h1>
43 * Run <code>kinit</code> to obtain a ticket and populate the cache before
44 * connecting. JAAS config:
45 * <p/>
46 * <pre>
47 * DseClient {
48 * com.sun.security.auth.module.Krb5LoginModule required
49 * useTicketCache=true
50 * renewTGT=true;
51 * };
52 * </pre>
53 * <p/>
54 * <p/>
55 * <h1>Authentication using a keytab file</h1>
56 * To enable authentication using a keytab file, specify its location on disk.
57 * If your keytab contains more than one principal key, you should also specify
58 * which one to select.
59 * <p/>
60 * <pre>
61 * DseClient {
62 * com.sun.security.auth.module.Krb5LoginModule required
63 * useKeyTab=true
64 * keyTab="/path/to/file.keytab"
65 * principal="user@MYDOMAIN.COM";
66 * };
67 * </pre>
68 * <p/>
69 * To connect to clusters using internal authentication, use the standard method for
70 * setting credentials. eg:
71 * <p/>
72 * <pre>
73 * Cluster cluster = Cluster.builder()
74 * .addContactPoint(hostname)
75 * .withCredentials("username", "password")
76 * .build();
77 * </pre>
78 */
79public class DseAuthProvider implements AuthProvider {
80 @Override
81 public Authenticator newAuthenticator(InetSocketAddress host) throws AuthenticationException {
82 return new KerberosAuthenticator(host);
83 }
84}