Listing the Login Modules of an Entry in the Current Login Configuration - Java Security

Java examples for Security:Login

Description

Listing the Login Modules of an Entry in the Current Login Configuration

Demo Code


import javax.security.auth.login.AppConfigurationEntry;
import javax.security.auth.login.Configuration;

public class Main {
  public static void m() {
    Configuration config = Configuration.getConfiguration();

    // Get the login modules
    AppConfigurationEntry[] loginModuleEntries = config
        .getAppConfigurationEntry("AppName");
    if (loginModuleEntries == null) {
      // There are no entries for the specified login-app name
    }//ww  w.  j  av a  2 s.  c  om
    for (int i = 0; i < loginModuleEntries.length; i++) {
      String name = loginModuleEntries[i].getLoginModuleName();
      AppConfigurationEntry.LoginModuleControlFlag flag = loginModuleEntries[i]
          .getControlFlag();

      if (flag == AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL) {
      } else if (flag == AppConfigurationEntry.LoginModuleControlFlag.REQUIRED) {
      } else if (flag == AppConfigurationEntry.LoginModuleControlFlag.REQUISITE) {
      } else if (flag == AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT) {
      }
    }
  }
}
AppName {
    com.sun.security.auth.module.NTLoginModule required;
    MyLoginModule1 requisite;
    MyLoginModule2 sufficient;
    MyLoginModule3 optional;
};
> java -Djava.security.auth.login.config=myconfig.config MyApp

Related Tutorials