private static void validate(
      final String username,
      final String password,
      final String krbfile,
      final String loginfile,
      final String moduleName)
      throws FileNotFoundException, NoSuchAlgorithmException {

    // confirm username was provided
    if (null == username || username.isEmpty()) {
      throw new IllegalArgumentException("Must provide a username");
    }

    // confirm password was provided
    if (null == password || password.isEmpty()) {
      throw new IllegalArgumentException("Must provide a password");
    }

    // confirm krb5.conf file exists
    if (null == krbfile || krbfile.isEmpty()) {
      throw new IllegalArgumentException("Must provide a krb5 file");
    } else {
      final File file = new File(krbfile);
      if (!file.exists()) {
        throw new FileNotFoundException(krbfile);
      }
    }

    // confirm loginfile
    if (null == loginfile || loginfile.isEmpty()) {
      throw new IllegalArgumentException("Must provide a login file");
    } else {
      final File file = new File(loginfile);
      if (!file.exists()) {
        throw new FileNotFoundException(loginfile);
      }
    }

    // confirm that runtime loaded the login file
    final Configuration config = Configuration.getConfiguration();

    // confirm that the module name exists in the file
    if (null == config.getAppConfigurationEntry(moduleName)) {
      throw new IllegalArgumentException(
          "The module name " + moduleName + " was not found in the login file");
    }
  }
 @Override
 public AppConfigurationEntry[] getAppConfigurationEntry(String appName) {
   if (SIMPLE_CONFIG_NAME.equals(appName)) {
     return SIMPLE_CONF;
   } else if (USER_KERBEROS_CONFIG_NAME.equals(appName)) {
     return USER_KERBEROS_CONF;
   } else if (KEYTAB_KERBEROS_CONFIG_NAME.equals(appName)) {
     KEYTAB_KERBEROS_OPTIONS.put("keyTab", keytabFile);
     KEYTAB_KERBEROS_OPTIONS.put("principal", keytabPrincipal);
     return KEYTAB_KERBEROS_CONF;
   } else if (FILE_CONFIG_NAME.equals(appName)) {
     return FILE_CONF;
   } else if (parent != null) {
     return parent.getAppConfigurationEntry(appName);
   }
   return null;
 }
示例#3
0
  public static void main(String[] args) {

    Configuration config = null;
    try {
      config = Configuration.getConfiguration();
    } catch (SecurityException se) {
      System.out.println("test 1 failed");
      throw se;
    }

    AppConfigurationEntry[] entries = config.getAppConfigurationEntry("InnerClassConfig");

    System.out.println("module = " + entries[0].getLoginModuleName());
    if (entries[0].getLoginModuleName().equals("package.Foo$Bar")) {
      System.out.println("test succeeded");
    } else {
      System.out.println("test 2 failed");
      throw new SecurityException("package name incorrect");
    }
  }