| 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 | */ |
| 16 | package com.datastax.driver.auth; |
| 17 | |
| 18 | import com.datastax.driver.core.AuthProvider; |
| 19 | import com.datastax.driver.core.Authenticator; |
| 20 | import com.datastax.driver.core.exceptions.AuthenticationException; |
| 21 | |
| 22 | import 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 | * <p/> |
| 38 | * See the following documents for further details on the |
| 39 | * <a href="https://docs.oracle.com/javase/6/docs/technotes/guides/security/jgss/tutorials/LoginConfigFile.html">JAAS Login Configuration File</a> and the |
| 40 | * <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/jaas/tutorials/GeneralAcnOnly.html">JAAS Authentication Tutorial</a> |
| 41 | * for more on JAAS in general. |
| 42 | * <p/> |
| 43 | * <h1>Authentication using ticket cache</h1> |
| 44 | * Run <code>kinit</code> to obtain a ticket and populate the cache before |
| 45 | * connecting. JAAS config: |
| 46 | * <p/> |
| 47 | * <pre> |
| 48 | * DseClient { |
| 49 | * com.sun.security.auth.module.Krb5LoginModule required |
| 50 | * useTicketCache=true |
| 51 | * renewTGT=true; |
| 52 | * }; |
| 53 | * </pre> |
| 54 | * <p/> |
| 55 | * <p/> |
| 56 | * <h1>Authentication using a keytab file</h1> |
| 57 | * To enable authentication using a keytab file, specify its location on disk. |
| 58 | * If your keytab contains more than one principal key, you should also specify |
| 59 | * which one to select. |
| 60 | * <p/> |
| 61 | * <pre> |
| 62 | * DseClient { |
| 63 | * com.sun.security.auth.module.Krb5LoginModule required |
| 64 | * useKeyTab=true |
| 65 | * keyTab="/path/to/file.keytab" |
| 66 | * principal="user@MYDOMAIN.COM"; |
| 67 | * }; |
| 68 | * </pre> |
| 69 | * <p/> |
| 70 | * To connect to clusters using internal authentication, use the standard method for |
| 71 | * setting credentials. eg: |
| 72 | * <p/> |
| 73 | * <pre> |
| 74 | * Cluster cluster = Cluster.builder() |
| 75 | * .addContactPoint(hostname) |
| 76 | * .withCredentials("username", "password") |
| 77 | * .build(); |
| 78 | * </pre> |
| 79 | */ |
| 80 | public class DseAuthProvider implements AuthProvider { |
| 81 | @Override |
| 82 | public Authenticator newAuthenticator(InetSocketAddress host) throws AuthenticationException { |
| 83 | return new KerberosAuthenticator(host); |
| 84 | } |
| 85 | } |