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"));
}
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);
}
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);
}
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();
}
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 };
}
};
}
Aggregations