Search in sources :

Example 6 with JaasRealm

use of org.apache.karaf.jaas.config.JaasRealm in project karaf by apache.

the class ListRealmsCommand method execute.

@Override
public Object execute() throws Exception {
    ShellTable table = new ShellTable();
    table.column("Index");
    table.column("Realm Name");
    table.column("Login Module Class Name");
    List<JaasRealm> realms = getRealms(hidden);
    if (realms != null && realms.size() > 0) {
        int index = 1;
        for (JaasRealm realm : realms) {
            String realmName = realm.getName();
            AppConfigurationEntry[] entries = realm.getEntries();
            if (entries != null && entries.length > 0) {
                for (AppConfigurationEntry entry : entries) {
                    String moduleClass = (String) entry.getOptions().get(ProxyLoginModule.PROPERTY_MODULE);
                    table.addRow().addContent(index++, realmName, moduleClass);
                }
            }
        }
    }
    table.print(System.out, !noFormat);
    return null;
}
Also used : JaasRealm(org.apache.karaf.jaas.config.JaasRealm) AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) ShellTable(org.apache.karaf.shell.support.table.ShellTable)

Example 7 with JaasRealm

use of org.apache.karaf.jaas.config.JaasRealm in project karaf by apache.

the class ListUsersCommand method execute.

@Override
public Object execute() throws Exception {
    JaasRealm realm = (JaasRealm) session.get(JAAS_REALM);
    AppConfigurationEntry entry = (AppConfigurationEntry) session.get(JAAS_ENTRY);
    if (realm == null || entry == null) {
        System.err.println("No JAAS Realm/Login Module has been selected");
        return null;
    }
    BackingEngine engine = getBackingEngine(entry);
    if (engine == null) {
        System.err.println("Can't get the list of users (no backing engine service found)");
        return null;
    }
    return doExecute(engine);
}
Also used : JaasRealm(org.apache.karaf.jaas.config.JaasRealm) BackingEngine(org.apache.karaf.jaas.modules.BackingEngine) AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry)

Example 8 with JaasRealm

use of org.apache.karaf.jaas.config.JaasRealm in project karaf by apache.

the class ManageRealmCommand method execute.

@SuppressWarnings("unchecked")
@Override
public Object execute() throws Exception {
    if (realmName == null && index <= 0) {
        System.err.println("A valid realm or the realm index need to be specified");
        return null;
    }
    JaasRealm oldRealm = (JaasRealm) this.session.get(JAAS_REALM);
    AppConfigurationEntry oldEntry = (AppConfigurationEntry) this.session.get(JAAS_ENTRY);
    if (oldRealm != null && !oldRealm.getName().equals(realmName) && !force) {
        System.err.println("Another JAAS Realm is being edited. Cancel/update first, or use the --force option.");
    } else if (oldEntry != null && !oldEntry.getLoginModuleName().equals(moduleName) && !force) {
        System.err.println("Another JAAS Login Module is being edited. Cancel/update first, or use the --force option.");
    } else {
        JaasRealm realm = null;
        AppConfigurationEntry entry = null;
        if (index > 0) {
            // user provided the index, get the realm AND entry from the index
            List<JaasRealm> realms = getRealms(hidden);
            if (realms != null && realms.size() > 0) {
                int i = 1;
                realms_loop: for (JaasRealm r : realms) {
                    AppConfigurationEntry[] entries = r.getEntries();
                    if (entries != null) {
                        for (AppConfigurationEntry entry1 : entries) {
                            if (i == index) {
                                realm = r;
                                entry = entry1;
                                break realms_loop;
                            }
                            i++;
                        }
                    }
                }
            }
        } else {
            List<JaasRealm> realms = getRealms(hidden);
            if (realms != null && realms.size() > 0) {
                for (JaasRealm r : realms) {
                    if (r.getName().equals(realmName)) {
                        realm = r;
                        AppConfigurationEntry[] entries = realm.getEntries();
                        if (entries != null) {
                            for (AppConfigurationEntry e : entries) {
                                String moduleClass = (String) e.getOptions().get(ProxyLoginModule.PROPERTY_MODULE);
                                if (moduleName == null) {
                                    if (getBackingEngine(e) != null) {
                                        entry = e;
                                        break;
                                    }
                                } else {
                                    if (moduleName.equals(e.getLoginModuleName()) || moduleName.equals(moduleClass)) {
                                        if (getBackingEngine(e) != null) {
                                            entry = e;
                                            break;
                                        }
                                    }
                                }
                            }
                            if (entry != null) {
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (realm == null) {
            System.err.println("JAAS realm has not been found.");
            return null;
        }
        if (entry == null) {
            System.err.println("JAAS module has not been found.");
            return null;
        }
        Queue<JaasCommandSupport> commands = null;
        commands = (Queue<JaasCommandSupport>) this.session.get(JAAS_CMDS);
        if (commands == null) {
            commands = new LinkedList<>();
        }
        this.session.put(JAAS_REALM, realm);
        this.session.put(JAAS_ENTRY, entry);
        this.session.put(JAAS_CMDS, commands);
    }
    return null;
}
Also used : JaasRealm(org.apache.karaf.jaas.config.JaasRealm) AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) List(java.util.List) LinkedList(java.util.LinkedList) Queue(java.util.Queue) LinkedList(java.util.LinkedList)

Example 9 with JaasRealm

use of org.apache.karaf.jaas.config.JaasRealm in project ddf by codice.

the class LdapLoginConfigTest method testLdapLoginConfig.

/**
     * Verifies that the JaasRealm is properly registered and that multiple ldap modules can be
     * created, updated and deleted.
     */
@Test
public void testLdapLoginConfig() {
    LdapService ldapService = new LdapService(context);
    LdapLoginConfig ldapConfigOne = createLdapConfig(ldapService);
    ldapConfigOne.configure();
    String configIdOne = ldapConfigOne.getId();
    // Verify the JaasRealm is registered.
    verify(context).registerService(eq(JaasRealm.class), any(JaasRealm.class), Matchers.<Dictionary<String, Object>>any());
    LdapLoginConfig ldapConfigTwo = createLdapConfig(ldapService);
    ldapConfigTwo.configure();
    String configIdTwo = ldapConfigTwo.getId();
    Map<String, String> ldapPropsOne = createLdapProperties("cn=user1");
    ldapConfigOne.update(ldapPropsOne);
    Map<String, String> ldapPropsTwo = createLdapProperties("cn=user2");
    ldapConfigTwo.update(ldapPropsTwo);
    List<Module> ldapModules = ldapService.getModules();
    for (Module module : ldapModules) {
        String moduleName = module.getName();
        String username = module.getOptions().getProperty(CONNECTION_USERNAME);
        // Assert the ldap modules were updated.
        if (moduleName.equals(configIdOne)) {
            assertThat(username, is(equalTo("cn=user1")));
        } else if (moduleName.equals(configIdTwo)) {
            assertThat(username, is(equalTo("cn=user2")));
        } else {
            fail("The ldap modules did not update correctly.");
        }
    }
    // Verify the JaasRealm has only been registered once.
    verify(context, times(1)).registerService(eq(JaasRealm.class), any(JaasRealm.class), Matchers.<Dictionary<String, Object>>any());
    // Destroy the first ldap module.
    ldapConfigOne.destroy(1);
    // Assert that the ldap module had already been removed.
    assertThat(ldapService.delete(configIdOne), is(equalTo(false)));
    // Assert the second ldap module is removed.
    assertThat(ldapService.delete(configIdTwo), is(equalTo(true)));
}
Also used : JaasRealm(org.apache.karaf.jaas.config.JaasRealm) Module(org.apache.karaf.jaas.config.impl.Module) Test(org.junit.Test)

Example 10 with JaasRealm

use of org.apache.karaf.jaas.config.JaasRealm in project ddf by codice.

the class UPBSTValidator method removeRealm.

public void removeRealm(ServiceReference<JaasRealm> serviceReference) {
    Bundle bundle = FrameworkUtil.getBundle(UPBSTValidator.class);
    if (null != bundle) {
        JaasRealm realm = bundle.getBundleContext().getService(serviceReference);
        LOGGER.trace("Removing validator for JaasRealm {}", realm.getName());
        validators.remove(realm.getName());
    }
}
Also used : JaasRealm(org.apache.karaf.jaas.config.JaasRealm) Bundle(org.osgi.framework.Bundle)

Aggregations

JaasRealm (org.apache.karaf.jaas.config.JaasRealm)13 AppConfigurationEntry (javax.security.auth.login.AppConfigurationEntry)7 Bundle (org.osgi.framework.Bundle)4 Queue (java.util.Queue)3 BackingEngine (org.apache.karaf.jaas.modules.BackingEngine)3 JAASUsernameTokenValidator (org.apache.wss4j.dom.validate.JAASUsernameTokenValidator)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 KeystoreInstance (org.apache.karaf.jaas.config.KeystoreInstance)1 KeystoreManager (org.apache.karaf.jaas.config.KeystoreManager)1 Module (org.apache.karaf.jaas.config.impl.Module)1 ShellTable (org.apache.karaf.shell.support.table.ShellTable)1 Test (org.junit.Test)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)1