use of org.apache.karaf.jaas.modules.NamePubkeyCallbackHandler in project karaf by apache.
the class LDAPPubkeyLoginModuleTest method testBadPrivateKey.
@Test
public void testBadPrivateKey() throws Exception {
Properties options = ldapLoginModuleOptions();
LDAPPubkeyLoginModule module = new LDAPPubkeyLoginModule();
Subject subject = new Subject();
Path pubkeyFile = srcTestResourcePath("org/apache/karaf/jaas/modules/ldap/ldaptest.cheese.id_rsa");
module.initialize(subject, new NamePubkeyCallbackHandler("admin", pubkeyFile), null, options);
assertEquals("Precondition", 0, subject.getPrincipals().size());
org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(LDAPLoginModule.class);
Level oldLevel = logger.getLevel();
logger.setLevel(Level.OFF);
try {
module.login();
fail("Should have thrown LoginException");
} catch (LoginException e) {
assertTrue(e.getMessage().startsWith("Authentication failed"));
} finally {
logger.setLevel(oldLevel);
}
}
use of org.apache.karaf.jaas.modules.NamePubkeyCallbackHandler in project karaf by apache.
the class LDAPPubkeyLoginModuleTest method testUserNotFound.
@Test
public void testUserNotFound() throws Exception {
Properties options = ldapLoginModuleOptions();
LDAPPubkeyLoginModule module = new LDAPPubkeyLoginModule();
Subject subject = new Subject();
Path pubkeyFile = srcTestResourcePath("org/apache/karaf/jaas/modules/ldap/ldaptest.admin.id_rsa");
module.initialize(subject, new NamePubkeyCallbackHandler("imnothere", pubkeyFile), null, options);
assertEquals("Precondition", 0, subject.getPrincipals().size());
assertFalse(module.login());
}
use of org.apache.karaf.jaas.modules.NamePubkeyCallbackHandler in project karaf by apache.
the class LDAPPubkeyLoginModuleTest method testAdminLogin.
@Test
public void testAdminLogin() throws Exception {
Properties options = ldapLoginModuleOptions();
LDAPPubkeyLoginModule module = new LDAPPubkeyLoginModule();
Subject subject = new Subject();
Path pubkeyFile = srcTestResourcePath("org/apache/karaf/jaas/modules/ldap/ldaptest.admin.id_rsa");
module.initialize(subject, new NamePubkeyCallbackHandler("admin", pubkeyFile), null, options);
assertEquals("Precondition", 0, subject.getPrincipals().size());
assertTrue(module.login());
assertTrue(module.commit());
assertEquals(2, subject.getPrincipals().size());
assertThat(names(subject.getPrincipals(UserPrincipal.class)), containsInAnyOrder("admin"));
assertThat(names(subject.getPrincipals(RolePrincipal.class)), containsInAnyOrder("admin"));
assertTrue(module.logout());
assertEquals("Principals should be gone as the user has logged out", 0, subject.getPrincipals().size());
}
use of org.apache.karaf.jaas.modules.NamePubkeyCallbackHandler in project karaf by apache.
the class LDAPPubkeyLoginModuleTest method testNonAdminLogin.
@Test
public void testNonAdminLogin() throws Exception {
Properties options = ldapLoginModuleOptions();
LDAPPubkeyLoginModule module = new LDAPPubkeyLoginModule();
Subject subject = new Subject();
Path pubkeyFile = srcTestResourcePath("org/apache/karaf/jaas/modules/ldap/ldaptest.cheese.id_rsa");
module.initialize(subject, new NamePubkeyCallbackHandler("cheese", pubkeyFile), null, options);
assertEquals("Precondition", 0, subject.getPrincipals().size());
assertTrue(module.login());
assertTrue(module.commit());
assertEquals(1, subject.getPrincipals().size());
assertThat(names(subject.getPrincipals(UserPrincipal.class)), containsInAnyOrder("cheese"));
assertThat(names(subject.getPrincipals(RolePrincipal.class)), Matchers.empty());
assertTrue(module.logout());
assertEquals("Principals should be gone as the user has logged out", 0, subject.getPrincipals().size());
}
Aggregations