use of org.apache.karaf.jaas.modules.NamePasswordCallbackHandler in project karaf by apache.
the class PropertiesLoginModuleTest method testCannotLoginAsGroupDirectly.
private void testCannotLoginAsGroupDirectly(final String name) throws IOException, LoginException {
File f = File.createTempFile(getClass().getName(), ".tmp");
try {
Properties p = new Properties(f);
PropertiesBackingEngine pbe = new PropertiesBackingEngine(p);
pbe.addUser("abc", "xyz");
pbe.addRole("abc", "myrole");
pbe.addUser("pqr", "abc");
pbe.addGroup("pqr", "group1");
pbe.addGroupRole("group1", "r1");
PropertiesLoginModule module = new PropertiesLoginModule();
Map<String, String> options = new HashMap<>();
options.put(PropertiesLoginModule.USER_FILE, f.getAbsolutePath());
module.initialize(new Subject(), new NamePasswordCallbackHandler(name, "group"), null, options);
try {
module.login();
Assert.fail("The login should have failed as you cannot log in under a group name directly");
} catch (FailedLoginException fle) {
// good
}
} finally {
if (!f.delete()) {
Assert.fail("Could not delete temporary file: " + f);
}
}
}
use of org.apache.karaf.jaas.modules.NamePasswordCallbackHandler in project karaf by apache.
the class JdbcLoginModuleTest method testLoginModule.
@Test
public void testLoginModule() throws Exception {
JDBCBackingEngine engine = new JDBCBackingEngine(dataSource);
engine.addUser("abc", "xyz");
engine.addRole("abc", "role1");
JDBCLoginModule module = new JDBCLoginModule();
Subject subject = new Subject();
module.initialize(subject, new NamePasswordCallbackHandler("abc", "xyz"), null, options);
module.login();
module.commit();
assertFalse(subject.getPrincipals(UserPrincipal.class).isEmpty());
assertEquals("abc", subject.getPrincipals(UserPrincipal.class).iterator().next().getName());
assertFalse(subject.getPrincipals(RolePrincipal.class).isEmpty());
assertEquals("role1", subject.getPrincipals(RolePrincipal.class).iterator().next().getName());
}
use of org.apache.karaf.jaas.modules.NamePasswordCallbackHandler in project karaf by apache.
the class LdapLoginModuleTest method testEmptyPassword.
@Test
public void testEmptyPassword() throws Exception {
Properties options = ldapLoginModuleOptions();
LDAPLoginModule module = new LDAPLoginModule();
Subject subject = new Subject();
module.initialize(subject, new NamePasswordCallbackHandler("imnothere", ""), null, options);
assertEquals("Precondition", 0, subject.getPrincipals().size());
try {
module.login();
fail("Should have failed");
} catch (LoginException e) {
assertTrue(e.getMessage().equals("Empty passwords not allowed"));
}
}
use of org.apache.karaf.jaas.modules.NamePasswordCallbackHandler in project karaf by apache.
the class Krb5LoginModuleTest method testLoginUsernameFailure.
@Test(expected = LoginException.class)
public void testLoginUsernameFailure() throws Exception {
Subject subject = new Subject();
Krb5LoginModule module = new Krb5LoginModule();
module.initialize(subject, new NamePasswordCallbackHandler("hnelson0", "secret"), null, new HashMap<>());
assertEquals("Precondition", 0, subject.getPrincipals().size());
Assert.assertFalse(module.login());
}
use of org.apache.karaf.jaas.modules.NamePasswordCallbackHandler in project karaf by apache.
the class Krb5LoginModuleTest method testLoginSuccess.
@Test
public void testLoginSuccess() throws Exception {
Subject subject = new Subject();
Krb5LoginModule module = new Krb5LoginModule();
module.initialize(subject, new NamePasswordCallbackHandler("hnelson", "secret"), null, new HashMap<>());
assertEquals("Precondition", 0, subject.getPrincipals().size());
Assert.assertTrue(module.login());
Assert.assertTrue(module.commit());
assertEquals(1, subject.getPrincipals().size());
assertThat(names(subject.getPrincipals(KerberosPrincipal.class)), containsInAnyOrder("hnelson@EXAMPLE.COM"));
KerberosTicket ticket = subject.getPrivateCredentials(KerberosTicket.class).iterator().next();
assertEquals("hnelson@EXAMPLE.COM", ticket.getClient().getName());
assertEquals("krbtgt/EXAMPLE.COM@EXAMPLE.COM", ticket.getServer().getName());
Assert.assertTrue(module.logout());
}
Aggregations