Search in sources :

Example 36 with AppConfigurationEntry

use of javax.security.auth.login.AppConfigurationEntry in project karaf by apache.

the class ListPendingCommand method execute.

@Override
public Object execute() throws Exception {
    JaasRealm realm = (JaasRealm) session.get(JAAS_REALM);
    AppConfigurationEntry entry = (AppConfigurationEntry) session.get(JAAS_ENTRY);
    @SuppressWarnings("unchecked") Queue<JaasCommandSupport> commandQueue = (Queue<JaasCommandSupport>) session.get(JAAS_CMDS);
    if (realm != null && entry != null) {
        String moduleClass = (String) entry.getOptions().get(ProxyLoginModule.PROPERTY_MODULE);
        System.out.println(String.format("JAAS Realm %s/JAAS Login Module %s", realm.getName(), moduleClass));
        if (commandQueue != null && !commandQueue.isEmpty()) {
            for (JaasCommandSupport command : commandQueue) {
                System.out.println(command);
            }
        } else {
            System.err.println("No JAAS modification command in queue");
        }
    } else {
        System.err.println("No JAAS Realm/Login Module selected");
    }
    return null;
}
Also used : JaasRealm(org.apache.karaf.jaas.config.JaasRealm) AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) Queue(java.util.Queue)

Example 37 with AppConfigurationEntry

use of javax.security.auth.login.AppConfigurationEntry in project karaf by apache.

the class UpdateCommand 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 selected");
        return null;
    }
    BackingEngine engine = getBackingEngine(entry);
    if (engine == null) {
        System.err.println("Can't update the JAAS realm (no backing engine service registered)");
        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 38 with AppConfigurationEntry

use of javax.security.auth.login.AppConfigurationEntry 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 39 with AppConfigurationEntry

use of javax.security.auth.login.AppConfigurationEntry 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 40 with AppConfigurationEntry

use of javax.security.auth.login.AppConfigurationEntry 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)

Aggregations

AppConfigurationEntry (javax.security.auth.login.AppConfigurationEntry)76 HashMap (java.util.HashMap)31 Configuration (javax.security.auth.login.Configuration)26 Map (java.util.Map)13 Test (org.junit.Test)11 Subject (javax.security.auth.Subject)10 LoginContext (javax.security.auth.login.LoginContext)10 SSOException (com.iplanet.sso.SSOException)7 SMSException (com.sun.identity.sm.SMSException)7 HashSet (java.util.HashSet)7 JaasRealm (org.apache.karaf.jaas.config.JaasRealm)7 Set (java.util.Set)6 LoginException (javax.security.auth.login.LoginException)5 IOException (java.io.IOException)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 CallbackHandler (javax.security.auth.callback.CallbackHandler)4 LoginModuleControlFlag (javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag)4 LoginModuleImpl (org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl)4 File (java.io.File)3 Principal (java.security.Principal)3