Search in sources :

Example 1 with Configuration

use of javax.security.auth.login.Configuration in project storm by apache.

the class AuthUtilsTest method getNonExistentSectionTest.

@Test
public void getNonExistentSectionTest() throws IOException {
    Map<String, String> optionMap = new HashMap<String, String>();
    AppConfigurationEntry entry = Mockito.mock(AppConfigurationEntry.class);
    Mockito.<Map<String, ?>>when(entry.getOptions()).thenReturn(optionMap);
    String section = "bogus-section";
    Configuration mockConfig = Mockito.mock(Configuration.class);
    Mockito.when(mockConfig.getAppConfigurationEntry(section)).thenReturn(new AppConfigurationEntry[] { entry });
    Assert.assertNull(AuthUtils.get(mockConfig, section, "nonexistent-key"));
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) Configuration(javax.security.auth.login.Configuration) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with Configuration

use of javax.security.auth.login.Configuration in project storm by apache.

the class AuthUtilsTest method makeDigestPayloadTest.

@Test
public void makeDigestPayloadTest() throws NoSuchAlgorithmException {
    String section = "user-pass-section";
    Map<String, String> optionMap = new HashMap<String, String>();
    String user = "user";
    String pass = "pass";
    optionMap.put("username", user);
    optionMap.put("password", pass);
    AppConfigurationEntry entry = Mockito.mock(AppConfigurationEntry.class);
    Mockito.<Map<String, ?>>when(entry.getOptions()).thenReturn(optionMap);
    Configuration mockConfig = Mockito.mock(Configuration.class);
    Mockito.when(mockConfig.getAppConfigurationEntry(section)).thenReturn(new AppConfigurationEntry[] { entry });
    MessageDigest digest = MessageDigest.getInstance("SHA-512");
    byte[] output = digest.digest((user + ":" + pass).getBytes());
    String sha = Hex.encodeHexString(output);
    // previous code used this method to generate the string, ensure the two match
    StringBuilder builder = new StringBuilder();
    for (byte b : output) {
        builder.append(String.format("%02x", b));
    }
    String stringFormatMethod = builder.toString();
    Assert.assertEquals(AuthUtils.makeDigestPayload(mockConfig, "user-pass-section"), sha);
    Assert.assertEquals(sha, stringFormatMethod);
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) Configuration(javax.security.auth.login.Configuration) HashMap(java.util.HashMap) MessageDigest(java.security.MessageDigest) Test(org.junit.Test)

Example 3 with Configuration

use of javax.security.auth.login.Configuration in project storm by apache.

the class AuthUtilsTest method getFirstValueForValidKeyTest.

@Test
public void getFirstValueForValidKeyTest() throws IOException {
    String k = "the-key";
    String expected = "good-value";
    Map<String, String> optionMap = new HashMap<String, String>();
    optionMap.put(k, expected);
    Map<String, String> badOptionMap = new HashMap<String, String>();
    badOptionMap.put(k, "bad-value");
    AppConfigurationEntry emptyEntry = Mockito.mock(AppConfigurationEntry.class);
    AppConfigurationEntry badEntry = Mockito.mock(AppConfigurationEntry.class);
    AppConfigurationEntry goodEntry = Mockito.mock(AppConfigurationEntry.class);
    Mockito.<Map<String, ?>>when(emptyEntry.getOptions()).thenReturn(new HashMap<String, String>());
    Mockito.<Map<String, ?>>when(badEntry.getOptions()).thenReturn(badOptionMap);
    Mockito.<Map<String, ?>>when(goodEntry.getOptions()).thenReturn(optionMap);
    String section = "bogus-section";
    Configuration mockConfig = Mockito.mock(Configuration.class);
    Mockito.when(mockConfig.getAppConfigurationEntry(section)).thenReturn(new AppConfigurationEntry[] { emptyEntry, goodEntry, badEntry });
    Assert.assertEquals(AuthUtils.get(mockConfig, section, k), expected);
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) Configuration(javax.security.auth.login.Configuration) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with Configuration

use of javax.security.auth.login.Configuration in project opennms by OpenNMS.

the class OpenNMSConfiguration method init.

public void init() throws InterruptedException {
    LOG.debug("OpenNMSConfiguration initializing.");
    new Thread(new Runnable() {

        @Override
        public void run() {
            // wait up to 2 minutes for Karaf's JAAS Configuration to become active so we can put a facade on top of it.
            final long giveUp = System.currentTimeMillis() + Long.getLong(JAAS_TIMEOUT_SYS_PROP, DEFAULT_JAAS_TIMEOUT_MS);
            do {
                final Configuration c = Configuration.getConfiguration();
                if (c != null) {
                    // gather all configurations that are found, until the Karaf implementation is loaded
                    if (m_delegates.add(c)) {
                        LOG.trace("OpenNMSConfiguration found existing configuration: " + c.getClass().getName());
                        if (c.getClass().getName().contains("OsgiConfiguration")) {
                            LOG.debug("Found Karaf OSGi JAAS configuration.  Inserting OpenNMS redirector.");
                            break;
                        }
                    }
                }
                LOG.trace("OpenNMSConfiguration still waiting for Karaf OsgiConfiguration to activate...");
                try {
                    Thread.sleep(200);
                } catch (final InterruptedException e) {
                    LOG.warn("Interrupted while waiting for Karaf's OSGi Configuration to initialize.", e);
                    break;
                }
            } while (System.currentTimeMillis() < giveUp);
            Configuration.setConfiguration(OpenNMSConfiguration.this);
        }
    }).start();
}
Also used : Configuration(javax.security.auth.login.Configuration)

Example 5 with Configuration

use of javax.security.auth.login.Configuration in project jackrabbit-oak by apache.

the class TokenDefaultLoginModuleTest method getConfiguration.

@Override
protected Configuration getConfiguration() {
    return new Configuration() {

        @Override
        public AppConfigurationEntry[] getAppConfigurationEntry(String s) {
            AppConfigurationEntry tokenEntry = new AppConfigurationEntry(TokenLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, Collections.<String, Object>emptyMap());
            AppConfigurationEntry defaultEntry = new AppConfigurationEntry(LoginModuleImpl.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, Collections.<String, Object>emptyMap());
            return new AppConfigurationEntry[] { tokenEntry, defaultEntry };
        }
    };
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) LoginModuleImpl(org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl) Configuration(javax.security.auth.login.Configuration)

Aggregations

Configuration (javax.security.auth.login.Configuration)91 AppConfigurationEntry (javax.security.auth.login.AppConfigurationEntry)43 LoginContext (javax.security.auth.login.LoginContext)27 HashMap (java.util.HashMap)24 Subject (javax.security.auth.Subject)20 Test (org.junit.Test)16 IOException (java.io.IOException)14 LoginException (javax.security.auth.login.LoginException)12 CallbackHandler (javax.security.auth.callback.CallbackHandler)8 File (java.io.File)7 Principal (java.security.Principal)7 URI (java.net.URI)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ArrayList (java.util.ArrayList)5 Test (org.junit.jupiter.api.Test)5 URIParameter (java.security.URIParameter)4 Map (java.util.Map)4 Callback (javax.security.auth.callback.Callback)4 PasswordCallback (javax.security.auth.callback.PasswordCallback)4 LoginModuleImpl (org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl)4