Search in sources :

Example 61 with Properties

use of org.apache.felix.utils.properties.Properties in project ddf by codice.

the class SystemPropertiesAdmin method writeOutUsersDotPropertiesFile.

/*
     * Writes user property data to the relevant file after replacing the default hostname where
     * necessary.
     */
private void writeOutUsersDotPropertiesFile(File userPropertiesFile) {
    try {
        Properties usersDotProperties = new Properties(userPropertiesFile);
        if (!usersDotProperties.isEmpty()) {
            String oldHostValue = usersDotProperties.getProperty(oldHostName);
            if (oldHostValue != null) {
                usersDotProperties.remove(oldHostName);
                usersDotProperties.setProperty(System.getProperty(SystemBaseUrl.HOST), oldHostValue);
                usersDotProperties.save();
            }
        }
    } catch (IOException e) {
        LOGGER.warn("Exception while writing to users.properties file.", e);
    }
}
Also used : IOException(java.io.IOException) Properties(org.apache.felix.utils.properties.Properties)

Example 62 with Properties

use of org.apache.felix.utils.properties.Properties in project karaf by apache.

the class GSSAPILdapLoginModuleTest method testPasswordFailure.

@Test(expected = LoginException.class)
public void testPasswordFailure() throws Exception {
    Properties options = ldapLoginModuleOptions();
    GSSAPILdapLoginModule module = new GSSAPILdapLoginModule();
    Subject subject = new Subject();
    module.initialize(subject, new NamePasswordCallbackHandler("hnelson", "secret0"), null, options);
    assertEquals("Precondition", 0, subject.getPrincipals().size());
    assertTrue(module.login());
}
Also used : NamePasswordCallbackHandler(org.apache.karaf.jaas.modules.NamePasswordCallbackHandler) Properties(org.apache.felix.utils.properties.Properties) Subject(javax.security.auth.Subject) KarafKerberosITest(org.apache.karaf.jaas.modules.krb5.KarafKerberosITest) Test(org.junit.Test)

Example 63 with Properties

use of org.apache.felix.utils.properties.Properties in project karaf by apache.

the class GSSAPILdapLoginModuleTest method testUserNotFound.

@Test(expected = LoginException.class)
public void testUserNotFound() throws Exception {
    Properties options = ldapLoginModuleOptions();
    GSSAPILdapLoginModule module = new GSSAPILdapLoginModule();
    Subject subject = new Subject();
    module.initialize(subject, new NamePasswordCallbackHandler("test", "test"), null, options);
    assertEquals("Precondition", 0, subject.getPrincipals().size());
    assertFalse(module.login());
}
Also used : NamePasswordCallbackHandler(org.apache.karaf.jaas.modules.NamePasswordCallbackHandler) Properties(org.apache.felix.utils.properties.Properties) Subject(javax.security.auth.Subject) KarafKerberosITest(org.apache.karaf.jaas.modules.krb5.KarafKerberosITest) Test(org.junit.Test)

Example 64 with Properties

use of org.apache.felix.utils.properties.Properties 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());
}
Also used : Path(java.nio.file.Path) Properties(org.apache.felix.utils.properties.Properties) NamePubkeyCallbackHandler(org.apache.karaf.jaas.modules.NamePubkeyCallbackHandler) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 65 with Properties

use of org.apache.felix.utils.properties.Properties in project karaf by apache.

the class LdapCacheTest method testAdminLogin.

@Test
public void testAdminLogin() throws Exception {
    Properties options = ldapLoginModuleOptions();
    LDAPLoginModule module = new LDAPLoginModule();
    CallbackHandler cb = new NamePasswordCallbackHandler("admin", "admin123");
    Subject subject = new Subject();
    module.initialize(subject, cb, 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());
    LDAPCache ldapCache = new LDAPCache(new LDAPOptions(options));
    DirContext context = ldapCache.open();
    addUserToGroup(context, "cn=admin,ou=people,dc=example,dc=com", "another");
    ldapCache.close();
    Thread.sleep(100);
    module = new LDAPLoginModule();
    subject = new Subject();
    module.initialize(subject, cb, null, options);
    assertEquals("Precondition", 0, subject.getPrincipals().size());
    assertTrue(module.login());
    assertTrue(module.commit());
    assertEquals("Postcondition", 3, subject.getPrincipals().size());
}
Also used : NamePasswordCallbackHandler(org.apache.karaf.jaas.modules.NamePasswordCallbackHandler) CallbackHandler(javax.security.auth.callback.CallbackHandler) NamePasswordCallbackHandler(org.apache.karaf.jaas.modules.NamePasswordCallbackHandler) DirContext(javax.naming.directory.DirContext) Properties(org.apache.felix.utils.properties.Properties) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Aggregations

Properties (org.apache.felix.utils.properties.Properties)95 IOException (java.io.IOException)35 File (java.io.File)33 Test (org.junit.Test)27 Subject (javax.security.auth.Subject)25 NamePasswordCallbackHandler (org.apache.karaf.jaas.modules.NamePasswordCallbackHandler)21 Path (java.nio.file.Path)13 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)9 FileInputStream (java.io.FileInputStream)8 URL (java.net.URL)8 MalformedURLException (java.net.MalformedURLException)7 HashSet (java.util.HashSet)6 Hashtable (java.util.Hashtable)6 LinkedHashMap (java.util.LinkedHashMap)6 TreeMap (java.util.TreeMap)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 FileNotFoundException (java.io.FileNotFoundException)5 LoginException (javax.security.auth.login.LoginException)5