in jaas/command/src/main/java/org/apache/karaf/jaas/command/ManageRealmCommand.java [57:149]
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;
}