
# 配置Oozie应用安全认证
#### 场景说明
在安全集群环境下，各个组件需要在通信之前进行相互认证，以确保通信的安全性。
用户在开发Oozie应用程序时，某些场景下需要Oozie与Hadoop、Hive等之间进行通信。那么Oozie应用程序中需要写入安全认证代码，确保Oozie程序能够正常运行。
安全认证有两种方式：
- 命令行认证： 提交Oozie应用程序运行前，在Oozie客户端执行如下命令获得认证。
  **kinit** *组件业务用户*
  
- 代码认证（Kerberos安全认证）： 通过获取客户端的principal和keytab文件在应用程序中进行认证，用于Kerberos安全认证的keytab文件和principal文件您可以联系管理员创建并获取，具体使用方法在样例代码中会有详细说明。
  目前样例代码统一调用LoginUtil类进行安全认证，支持Oracle JAVA平台和IBM JAVA平台。
  代码示例中请根据实际情况，修改"USERNAME"为实际用户名，例如"developuser"。
  ```
  private static void login(String keytabFilePath, String krb5FilePath, String user) throws IOException {
          Configuration conf = new Configuration();
          conf.set(KERBEROS_PRINCIPAL, user);
          conf.set(KEYTAB_FILE, keytabFilePath);
          conf.set(HADOOP_SECURITY_AUTHENTICATION, "kerberos");
          conf.set(HADOOP_SECURITY_AUTHORIZATION, "true");
          /*
           * if need to connect zk, please provide jaas info about zk. of course,
           * you can do it as below:
           * System.setProperty("java.security.auth.login.config", confDirPath +
           * "jaas.conf"); but the demo can help you more : Note: if this process
           * will connect more than one zk cluster, the demo may be not proper. you
           * can contact us for more help
           */
          LoginUtil.setJaasConf(ZOOKEEPER_DEFAULT_LOGIN_CONTEXT_NAME, user, keytabFilePath);
          LoginUtil.setZookeeperServerPrincipal(ZOOKEEPER_DEFAULT_SERVER_PRINCIPAL);
          LoginUtil.login(user, keytabFilePath, krb5FilePath, conf);
      }
  ```
  
 
