javax.security.auth.login.AppConfigurationEntry Java Examples

The following examples show how to use javax.security.auth.login.AppConfigurationEntry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RegistrySecurity.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Resolve the context of an entry. This is an effective test of
 * JAAS setup, because it will relay detected problems up
 * @param context context name
 * @return the entry
 * @throws RuntimeException if there is no context entry found
 */
public static AppConfigurationEntry[] validateContext(String context)  {
  if (context == null) {
    throw new RuntimeException("Null context argument");
  }
  if (context.isEmpty()) {
    throw new RuntimeException("Empty context argument");
  }
  javax.security.auth.login.Configuration configuration =
      javax.security.auth.login.Configuration.getConfiguration();
  AppConfigurationEntry[] entries =
      configuration.getAppConfigurationEntry(context);
  if (entries == null) {
    throw new RuntimeException(
        String.format("Entry \"%s\" not found; " +
                      "JAAS config = %s",
            context,
            describeProperty(Environment.JAAS_CONF_KEY) ));
  }
  return entries;
}
 
Example #2
Source File: DynamicConfiguration.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the AppConfigurationEntries for the specified <i>name</i>
 * from this Configuration.
 *
 * @param name the name used to index the Configuration.
 *
 * @return an array of AppConfigurationEntries for the specified <i>name</i>
 *          from this Configuration, or null if there are no entries
 *          for the specified <i>name</i>
 */
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
	AppConfigurationEntry[] entry = null;
	if (delegate != null) {
		entry = delegate.getAppConfigurationEntry(name);
	}
	final AppConfigurationEntry[] existing = dynamicEntries.get(name);
	if (existing != null) {
		if (entry != null) {
			entry = merge(entry, existing);
		}
		else {
			entry = Arrays.copyOf(existing, existing.length);
		}
	}
	return entry;
}
 
Example #3
Source File: ConfigFile.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Retrieve an entry from the Configuration using an application name
 * as an index.
 *
 * @param applicationName the name used to index the Configuration.
 * @return an array of AppConfigurationEntries which correspond to
 *         the stacked configuration of LoginModules for this
 *         application, or null if this application has no configured
 *         LoginModules.
 */
@Override
public AppConfigurationEntry[] engineGetAppConfigurationEntry
    (String applicationName) {

    List<AppConfigurationEntry> list = null;
    synchronized (configuration) {
        list = configuration.get(applicationName);
    }

    if (list == null || list.size() == 0) {
        return null;
    }

    AppConfigurationEntry[] entries =
                            new AppConfigurationEntry[list.size()];
    Iterator<AppConfigurationEntry> iterator = list.iterator();
    for (int i = 0; iterator.hasNext(); i++) {
        AppConfigurationEntry e = iterator.next();
        entries[i] = new AppConfigurationEntry(e.getLoginModuleName(),
                                               e.getControlFlag(),
                                               e.getOptions());
    }
    return entries;
}
 
Example #4
Source File: KerberosTestUtils.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
  Map<String, String> options = new HashMap<String, String>();
  options.put("keyTab", KerberosTestUtils.getKeytabFile());
  options.put("principal", principal);
  options.put("useKeyTab", "true");
  options.put("storeKey", "true");
  options.put("doNotPrompt", "true");
  options.put("useTicketCache", "true");
  options.put("renewTGT", "true");
  options.put("refreshKrb5Config", "true");
  options.put("isInitiator", "true");
  String ticketCache = System.getenv("KRB5CCNAME");
  if (ticketCache != null) {
    options.put("ticketCache", ticketCache);
  }
  options.put("debug", "true");

  return new AppConfigurationEntry[]{
    new AppConfigurationEntry(KerberosUtil.getKrb5LoginModuleName(),
                              AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
                              options),};
}
 
Example #5
Source File: PxfUserGroupInformation.java    From pxf with Apache License 2.0 6 votes vote down vote up
public AppConfigurationEntry[] getAppConfigurationEntry(String appName) {
    if ("hadoop-simple".equals(appName)) {
        return SIMPLE_CONF;
    } else if ("hadoop-user-kerberos".equals(appName)) {
        return USER_KERBEROS_CONF;
    } else if ("hadoop-keytab-kerberos".equals(appName)) {
        if (PlatformName.IBM_JAVA) {
            KEYTAB_KERBEROS_OPTIONS.put("useKeytab", prependFileAuthority(keytabFile));
        } else {
            KEYTAB_KERBEROS_OPTIONS.put("keyTab", keytabFile);
        }

        KEYTAB_KERBEROS_OPTIONS.put("principal", keytabPrincipal);
        return KEYTAB_KERBEROS_CONF;
    } else {
        return null;
    }
}
 
Example #6
Source File: BaseAuthenticationInfo.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>
 * Creates and returns a copy of the specified list of {@code AppConfigurationEntry} objects, adding the security
 * domain option when necessary. Execution of this method requires a {@code getLoginConfiguration} permission.
 * 
 * </p>
 * 
 * @param entries a {@code List} containing the {@code AppConfigurationEntry} objects to be copied.
 * @return an {@code AppConfigurationEntry} array containing the copied entries.
 */
protected AppConfigurationEntry[] copyAppConfigurationEntry(List<Object> entries)
{
   SecurityManager sm = System.getSecurityManager();
   if (sm != null)
      sm.checkPermission(GET_CONFIG_ENTRY_PERM);
   AppConfigurationEntry[] copy = new AppConfigurationEntry[entries.size()];
   for (int i = 0; i < copy.length; i++)
   {
      AppConfigurationEntry entry = (AppConfigurationEntry) entries.get(i);
      HashMap<String, Object> options = new HashMap<String, Object>(entry.getOptions());
      if (!disableSecurityDomainInOptions())
      {
         options.put(SecurityConstants.SECURITY_DOMAIN_OPTION, this.getName());
      }
      copy[i] = new AppConfigurationEntry(entry.getLoginModuleName(), entry.getControlFlag(), options);
   }
   return copy;
}
 
Example #7
Source File: TestKMS.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
  Map<String, String> options = new HashMap<String, String>();
  options.put("keyTab", keytab);
  options.put("principal", principal);
  options.put("useKeyTab", "true");
  options.put("storeKey", "true");
  options.put("doNotPrompt", "true");
  options.put("useTicketCache", "true");
  options.put("renewTGT", "true");
  options.put("refreshKrb5Config", "true");
  options.put("isInitiator", Boolean.toString(isInitiator));
  String ticketCache = System.getenv("KRB5CCNAME");
  if (ticketCache != null) {
    options.put("ticketCache", ticketCache);
  }
  options.put("debug", "true");

  return new AppConfigurationEntry[]{
      new AppConfigurationEntry(getKrb5LoginModuleName(),
          AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
          options)};
}
 
Example #8
Source File: JAASLoginInterceptorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private JAASLoginInterceptor createTestJaasLoginInterceptor() {
    JAASLoginInterceptor jaasInt = new JAASLoginInterceptor();
    jaasInt.setReportFault(true);
    Configuration config = new Configuration() {

        @Override
        public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
            Map<String, String> options = new HashMap<>();
            AppConfigurationEntry configEntry = new AppConfigurationEntry(
                                                                          TestUserPasswordLoginModule.class
                                                                              .getName(),
                                                                          LoginModuleControlFlag.REQUIRED,
                                                                          options);
            return Collections.singleton(configEntry).toArray(new AppConfigurationEntry[] {});
        }
    };
    jaasInt.setLoginConfig(config);
    return jaasInt;
}
 
Example #9
Source File: JaasKrbUtil.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
    Map<String, String> options = new HashMap<String, String>();
    options.put("principal", principal);
    options.put("storeKey", "false");
    options.put("doNotPrompt", "false");
    options.put("useTicketCache", "true");
    options.put("renewTGT", "true");
    options.put("refreshKrb5Config", "true");
    options.put("isInitiator", "true");
    options.put("ticketCache", clientCredentialFile.getAbsolutePath());
    options.put("debug", String.valueOf(ENABLE_DEBUG));

    return new AppConfigurationEntry[]{
            new AppConfigurationEntry(getKrb5LoginModuleName(),
                    AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
                    options)};
}
 
Example #10
Source File: JaasKrbUtil.java    From deprecated-security-advanced-modules with Apache License 2.0 6 votes vote down vote up
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(final String name) {
    final Map<String, String> options = new HashMap<String, String>();
    options.put("keyTab", keytabPath.toAbsolutePath().toString());
    options.put("principal", principal);
    options.put("useKeyTab", "true");
    options.put("storeKey", "true");
    options.put("doNotPrompt", "true");
    options.put("renewTGT", "false");
    options.put("refreshKrb5Config", "true");
    options.put("isInitiator", String.valueOf(initiator));
    options.put("debug", String.valueOf(debug));

    return new AppConfigurationEntry[] { new AppConfigurationEntry(getKrb5LoginModuleName(),
            AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options) };
}
 
Example #11
Source File: JMXPluggableAuthenticator.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an instance of <code>FileLoginConfig</code>
 *
 * @param passwordFile A filepath that identifies the password file to use.
 *                     If null then the default password file is used.
 */
public FileLoginConfig(String passwordFile) {

    Map<String, String> options;
    if (passwordFile != null) {
        options = new HashMap<String, String>(1);
        options.put(PASSWORD_FILE_OPTION, passwordFile);
    } else {
        options = Collections.emptyMap();
    }

    entries = new AppConfigurationEntry[] {
        new AppConfigurationEntry(FILE_LOGIN_MODULE,
            AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
                options)
    };
}
 
Example #12
Source File: ConfigFile.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void readConfig(Reader reader,
    Map<String, List<AppConfigurationEntry>> newConfig)
    throws IOException {

    linenum = 1;

    if (!(reader instanceof BufferedReader)) {
        reader = new BufferedReader(reader);
    }

    st = new StreamTokenizer(reader);
    st.quoteChar('"');
    st.wordChars('$', '$');
    st.wordChars('_', '_');
    st.wordChars('-', '-');
    st.wordChars('*', '*');
    st.lowerCaseMode(false);
    st.slashSlashComments(true);
    st.slashStarComments(true);
    st.eolIsSignificant(true);

    lookahead = nextToken();
    while (lookahead != StreamTokenizer.TT_EOF) {
        parseLoginEntry(newConfig);
    }
}
 
Example #13
Source File: RegistrySecurity.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Resolve the context of an entry. This is an effective test of
 * JAAS setup, because it will relay detected problems up
 * @param context context name
 * @return the entry
 * @throws RuntimeException if there is no context entry found
 */
public static AppConfigurationEntry[] validateContext(String context)  {
  if (context == null) {
    throw new RuntimeException("Null context argument");
  }
  if (context.isEmpty()) {
    throw new RuntimeException("Empty context argument");
  }
  javax.security.auth.login.Configuration configuration =
      javax.security.auth.login.Configuration.getConfiguration();
  AppConfigurationEntry[] entries =
      configuration.getAppConfigurationEntry(context);
  if (entries == null) {
    throw new RuntimeException(
        String.format("Entry \"%s\" not found; " +
                      "JAAS config = %s",
            context,
            describeProperty(Environment.JAAS_CONF_KEY) ));
  }
  return entries;
}
 
Example #14
Source File: ConfigFile.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void readConfig(Reader reader,
    Map<String, List<AppConfigurationEntry>> newConfig)
    throws IOException {

    linenum = 1;

    if (!(reader instanceof BufferedReader)) {
        reader = new BufferedReader(reader);
    }

    st = new StreamTokenizer(reader);
    st.quoteChar('"');
    st.wordChars('$', '$');
    st.wordChars('_', '_');
    st.wordChars('-', '-');
    st.wordChars('*', '*');
    st.lowerCaseMode(false);
    st.slashSlashComments(true);
    st.slashStarComments(true);
    st.eolIsSignificant(true);

    lookahead = nextToken();
    while (lookahead != StreamTokenizer.TT_EOF) {
        parseLoginEntry(newConfig);
    }
}
 
Example #15
Source File: AuthenticationConfigParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the <authentication> element
 * @param reader
 * @return
 * @throws XMLStreamException
 */
public Set<AppConfigurationEntry> parse(XMLStreamReader reader) throws XMLStreamException
{
   Set<AppConfigurationEntry> entries = new LinkedHashSet<AppConfigurationEntry>();
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT)
   {
      final Element element = Element.forName(reader.getLocalName());
      AppConfigurationEntry entry = null;
      if (element.equals(Element.LOGIN_MODULE))
      {
         entry = getEntry(reader);
      }
      else
         throw StaxParserUtil.unexpectedElement(reader);
      entries.add(entry);
   }
   return entries;
}
 
Example #16
Source File: JMXPluggableAuthenticator.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Creates an instance of <code>FileLoginConfig</code>
 *
 * @param passwordFile A filepath that identifies the password file to use.
 *                     If null then the default password file is used.
 */
public FileLoginConfig(String passwordFile) {

    Map<String, String> options;
    if (passwordFile != null) {
        options = new HashMap<String, String>(1);
        options.put(PASSWORD_FILE_OPTION, passwordFile);
    } else {
        options = Collections.emptyMap();
    }

    entries = new AppConfigurationEntry[] {
        new AppConfigurationEntry(FILE_LOGIN_MODULE,
            AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
                options)
    };
}
 
Example #17
Source File: JMXPluggableAuthenticator.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an instance of <code>FileLoginConfig</code>
 *
 * @param passwordFile A filepath that identifies the password file to use.
 *                     If null then the default password file is used.
 */
public FileLoginConfig(String passwordFile) {

    Map<String, String> options;
    if (passwordFile != null) {
        options = new HashMap<String, String>(1);
        options.put(PASSWORD_FILE_OPTION, passwordFile);
    } else {
        options = Collections.emptyMap();
    }

    entries = new AppConfigurationEntry[] {
        new AppConfigurationEntry(FILE_LOGIN_MODULE,
            AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
                options)
    };
}
 
Example #18
Source File: DynamicConfiguration.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the AppConfigurationEntries for the specified <i>name</i>
 * from this Configuration.
 *
 * @param name the name used to index the Configuration.
 *
 * @return an array of AppConfigurationEntries for the specified <i>name</i>
 *          from this Configuration, or null if there are no entries
 *          for the specified <i>name</i>
 */
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
	AppConfigurationEntry[] entry = null;
	if (delegate != null) {
		entry = delegate.getAppConfigurationEntry(name);
	}
	final AppConfigurationEntry[] existing = dynamicEntries.get(name);
	if (existing != null) {
		if (entry != null) {
			entry = merge(entry, existing);
		}
		else {
			entry = Arrays.copyOf(existing, existing.length);
		}
	}
	return entry;
}
 
Example #19
Source File: JMXPluggableAuthenticator.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an instance of <code>FileLoginConfig</code>
 *
 * @param passwordFile A filepath that identifies the password file to use.
 *                     If null then the default password file is used.
 */
public FileLoginConfig(String passwordFile) {

    Map<String, String> options;
    if (passwordFile != null) {
        options = new HashMap<String, String>(1);
        options.put(PASSWORD_FILE_OPTION, passwordFile);
    } else {
        options = Collections.emptyMap();
    }

    entries = new AppConfigurationEntry[] {
        new AppConfigurationEntry(FILE_LOGIN_MODULE,
            AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
                options)
    };
}
 
Example #20
Source File: SpnegoAuthenticator.java    From gcp-token-broker with Apache License 2.0 6 votes vote down vote up
private static Configuration getConfiguration(String principal, File keytabFile) {
    return new Configuration() {
        @Override
        public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
            Map<String, String> options = new HashMap<String, String>();
            options.put("principal", principal);
            options.put("keyTab", keytabFile.getPath());
            options.put("doNotPrompt", "true");
            options.put("useKeyTab", "true");
            options.put("storeKey", "true");
            options.put("isInitiator", "false");
            return new AppConfigurationEntry[] {
                new AppConfigurationEntry(
                    "com.sun.security.auth.module.Krb5LoginModule",
                    AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options)
            };
        }
    };
}
 
Example #21
Source File: ConfigFile.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Retrieve an entry from the Configuration using an application name
 * as an index.
 *
 * @param applicationName the name used to index the Configuration.
 * @return an array of AppConfigurationEntries which correspond to
 *         the stacked configuration of LoginModules for this
 *         application, or null if this application has no configured
 *         LoginModules.
 */
@Override
public AppConfigurationEntry[] engineGetAppConfigurationEntry
    (String applicationName) {

    List<AppConfigurationEntry> list = null;
    synchronized (configuration) {
        list = configuration.get(applicationName);
    }

    if (list == null || list.size() == 0) {
        return null;
    }

    AppConfigurationEntry[] entries =
                            new AppConfigurationEntry[list.size()];
    Iterator<AppConfigurationEntry> iterator = list.iterator();
    for (int i = 0; iterator.hasNext(); i++) {
        AppConfigurationEntry e = iterator.next();
        entries[i] = new AppConfigurationEntry(e.getLoginModuleName(),
                                               e.getControlFlag(),
                                               e.getOptions());
    }
    return entries;
}
 
Example #22
Source File: ConfigFile.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void readConfig(Reader reader,
    Map<String, List<AppConfigurationEntry>> newConfig)
    throws IOException {

    linenum = 1;

    if (!(reader instanceof BufferedReader)) {
        reader = new BufferedReader(reader);
    }

    st = new StreamTokenizer(reader);
    st.quoteChar('"');
    st.wordChars('$', '$');
    st.wordChars('_', '_');
    st.wordChars('-', '-');
    st.wordChars('*', '*');
    st.lowerCaseMode(false);
    st.slashSlashComments(true);
    st.slashStarComments(true);
    st.eolIsSignificant(true);

    lookahead = nextToken();
    while (lookahead != StreamTokenizer.TT_EOF) {
        parseLoginEntry(newConfig);
    }
}
 
Example #23
Source File: ConfigFile.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void init(URL config,
                  Map<String, List<AppConfigurationEntry>> newConfig)
                  throws IOException {

    try (InputStreamReader isr
            = new InputStreamReader(getInputStream(config), "UTF-8")) {
        readConfig(isr, newConfig);
    } catch (FileNotFoundException fnfe) {
        if (debugConfig != null) {
            debugConfig.println(fnfe.toString());
        }
        throw new IOException(ResourcesMgr.getString
            ("Configuration.Error.No.such.file.or.directory",
            "sun.security.util.AuthResources"));
    }
}
 
Example #24
Source File: ConfigFile.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void readConfig(Reader reader,
    Map<String, List<AppConfigurationEntry>> newConfig)
    throws IOException {

    linenum = 1;

    if (!(reader instanceof BufferedReader)) {
        reader = new BufferedReader(reader);
    }

    st = new StreamTokenizer(reader);
    st.quoteChar('"');
    st.wordChars('$', '$');
    st.wordChars('_', '_');
    st.wordChars('-', '-');
    st.wordChars('*', '*');
    st.lowerCaseMode(false);
    st.slashSlashComments(true);
    st.slashStarComments(true);
    st.eolIsSignificant(true);

    lookahead = nextToken();
    while (lookahead != StreamTokenizer.TT_EOF) {
        parseLoginEntry(newConfig);
    }
}
 
Example #25
Source File: AuthTestUtil.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
public static Configuration makeConfiguration() {
  return new Configuration() {
    @Override
    public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
      if (name.equals("Wave")) {
        AppConfigurationEntry entry =
            new AppConfigurationEntry(AccountStoreLoginModule.class.getName(),
                LoginModuleControlFlag.REQUIRED, new HashMap<String, Object>());

        return new AppConfigurationEntry[] {entry};
      } else {
        return null;
      }
    }
  };
}
 
Example #26
Source File: JMXPluggableAuthenticator.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an instance of <code>FileLoginConfig</code>
 *
 * @param passwordFile A filepath that identifies the password file to use.
 *                     If null then the default password file is used.
 */
public FileLoginConfig(String passwordFile) {

    Map<String, String> options;
    if (passwordFile != null) {
        options = new HashMap<String, String>(1);
        options.put(PASSWORD_FILE_OPTION, passwordFile);
    } else {
        options = Collections.emptyMap();
    }

    entries = new AppConfigurationEntry[] {
        new AppConfigurationEntry(FILE_LOGIN_MODULE,
            AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
                options)
    };
}
 
Example #27
Source File: LoginConfigImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Default value for a caller-mech pair when no entry is defined in
 * the system-wide Configuration object.
 */
private AppConfigurationEntry[] getDefaultConfigurationEntry() {
    HashMap <String, String> options = new HashMap <String, String> (2);

    if (mechName == null || mechName.equals("krb5")) {
        if (isServerSide(caller)) {
            // Assuming the keytab file can be found through
            // krb5 config file or under user home directory
            options.put("useKeyTab", "true");
            options.put("storeKey", "true");
            options.put("doNotPrompt", "true");
            options.put("principal", "*");
            options.put("isInitiator", "false");
        } else {
            options.put("useTicketCache", "true");
            options.put("doNotPrompt", "false");
        }
        return new AppConfigurationEntry[] {
            new AppConfigurationEntry(
                    "com.sun.security.auth.module.Krb5LoginModule",
                    AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
                    options)
        };
    }
    return null;
}
 
Example #28
Source File: ClientCallbackHandler.java    From jstorm with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor based on a JAAS configuration
 * 
 * For digest, you should have a pair of user name and password defined.
 * 
 * @param configuration
 * @throws IOException
 */
public ClientCallbackHandler(Configuration configuration) throws IOException {
    if (configuration == null)
        return;
    AppConfigurationEntry configurationEntries[] = configuration.getAppConfigurationEntry(AuthUtils.LOGIN_CONTEXT_CLIENT);
    if (configurationEntries == null) {
        String errorMessage = "Could not find a '" + AuthUtils.LOGIN_CONTEXT_CLIENT + "' entry in this configuration: Client cannot start.";
        throw new IOException(errorMessage);
    }

    _password = "";
    for (AppConfigurationEntry entry : configurationEntries) {
        if (entry.getOptions().get(USERNAME) != null) {
            _username = (String) entry.getOptions().get(USERNAME);
        }
        if (entry.getOptions().get(PASSWORD) != null) {
            _password = (String) entry.getOptions().get(PASSWORD);
        }
    }
}
 
Example #29
Source File: JMXPluggableAuthenticator.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an instance of <code>FileLoginConfig</code>
 *
 * @param passwordFile A filepath that identifies the password file to use.
 *                     If null then the default password file is used.
 */
public FileLoginConfig(String passwordFile) {

    Map<String, String> options;
    if (passwordFile != null) {
        options = new HashMap<String, String>(1);
        options.put(PASSWORD_FILE_OPTION, passwordFile);
    } else {
        options = Collections.emptyMap();
    }

    entries = new AppConfigurationEntry[] {
        new AppConfigurationEntry(FILE_LOGIN_MODULE,
            AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
                options)
    };
}
 
Example #30
Source File: ConfigFile.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Retrieve an entry from the Configuration using an application name
 * as an index.
 *
 * @param applicationName the name used to index the Configuration.
 * @return an array of AppConfigurationEntries which correspond to
 *         the stacked configuration of LoginModules for this
 *         application, or null if this application has no configured
 *         LoginModules.
 */
@Override
public AppConfigurationEntry[] engineGetAppConfigurationEntry
    (String applicationName) {

    List<AppConfigurationEntry> list = null;
    synchronized (configuration) {
        list = configuration.get(applicationName);
    }

    if (list == null || list.size() == 0) {
        return null;
    }

    AppConfigurationEntry[] entries =
                            new AppConfigurationEntry[list.size()];
    Iterator<AppConfigurationEntry> iterator = list.iterator();
    for (int i = 0; iterator.hasNext(); i++) {
        AppConfigurationEntry e = iterator.next();
        entries[i] = new AppConfigurationEntry(e.getLoginModuleName(),
                                               e.getControlFlag(),
                                               e.getOptions());
    }
    return entries;
}