The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.security.auth.login  [3 examples]

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

This example retrieves the login modules of a login-application entry in the current login configuration.
    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
    }
    
    // List the login modules
    for (int i=0; i<loginModuleEntries.length; i++) {
        // Get login module name
        String name = loginModuleEntries[i].getLoginModuleName();
    
        // Get login module flag
        AppConfigurationEntry.LoginModuleControlFlag flag
            = loginModuleEntries[i].getControlFlag();
    
        if (flag == AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL) {
            // The login module is not required to succeed.
            // Whether it succeeds or not, the next login module is invoked.
        } else if (flag == AppConfigurationEntry.LoginModuleControlFlag.REQUIRED) {
            // The login module is required to succeed.
            // Whether it succeeds or not, the next login module is invoked.
        } else if (flag == AppConfigurationEntry.LoginModuleControlFlag.REQUISITE) {
            // The login module is required to succeed. If it succeeds, the next
            // login module is invoked; otherwise, authentication fails and
            // no more login modules are invoked.
        } else if (flag == AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT) {
            // If this login module succeeds, authentication succeeds and no
            // more login modules are invoked
        }
    }
Here's a sample of a login configuration file:
    AppName {
        com.sun.security.auth.module.NTLoginModule required;
        MyLoginModule1 requisite;
        MyLoginModule2 sufficient;
        MyLoginModule3 optional;
    };
The login configuration file is specified at the command line:
    > java -Djava.security.auth.login.config=myconfig.config MyApp

 Related Examples
e508. Getting the Login Name of the Currently Logged-In User
e509. Handling the Callbacks from a Login Module


© 2002 Addison-Wesley.