Esempio n. 1
0
  protected void login() {
    ClassLoader prevCl = Thread.currentThread().getContextClassLoader();
    String errMsg =
        " You can still save the repository and start creating "
            + "policies, but you would not be able to use autocomplete for "
            + "resource names. Check xa_portal.log for more info.";
    try {
      // Thread.currentThread().setContextClassLoader(configHolder.getClassLoader());
      String userName = configHolder.getUserName();
      if (userName == null) {
        String msgDesc =
            "Unable to find login username for hadoop environment, [" + serviceName + "]";
        HadoopException hdpException = new HadoopException(msgDesc);
        hdpException.generateResponseDataMap(false, msgDesc + errMsg, msgDesc + errMsg, null, null);

        throw hdpException;
      }
      String keyTabFile = configHolder.getKeyTabFile();
      if (keyTabFile != null) {
        if (configHolder.isKerberosAuthentication()) {
          LOG.info("Init Login: security enabled, using username/keytab");
          loginSubject = SecureClientLogin.loginUserFromKeytab(userName, keyTabFile);
        } else {
          LOG.info("Init Login: using username");
          loginSubject = SecureClientLogin.login(userName);
        }
      } else {
        String password = configHolder.getPassword();
        if (configHolder.isKerberosAuthentication()) {
          LOG.info("Init Login: using username/password");
          loginSubject = SecureClientLogin.loginUserWithPassword(userName, password);
        } else {
          LOG.info("Init Login: security not enabled, using username");
          loginSubject = SecureClientLogin.login(userName);
        }
      }
    } catch (IOException ioe) {
      String msgDesc = "Unable to login to Hadoop environment [" + serviceName + "]";

      HadoopException hdpException = new HadoopException(msgDesc, ioe);
      hdpException.generateResponseDataMap(
          false, getMessage(ioe) + errMsg, msgDesc + errMsg, null, null);
      throw hdpException;
    } catch (SecurityException se) {
      String msgDesc = "Unable to login to Hadoop environment [" + serviceName + "]";
      HadoopException hdpException = new HadoopException(msgDesc, se);
      hdpException.generateResponseDataMap(
          false, getMessage(se) + errMsg, msgDesc + errMsg, null, null);
      throw hdpException;
    } finally {
      Thread.currentThread().setContextClassLoader(prevCl);
    }
  }