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 (int j = 0; j < entries.length; j++) {
if (i == index) {
realm = r;
entry = entries[j];
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) {