@Test public void testRealmAdd() throws Exception { RealmAddCommand cmd = new RealmAddCommand(); cmd.setRealmname("myDummyRealm"); Session session = createMock(Session.class); BundleContext bundleContext = createMock(BundleContext.class); Bundle bundle = createMock(Bundle.class); cmd.setContext(bundleContext); cmd.setSession(session); Object[] mocks = { session, bundleContext, bundle }; expect(bundleContext.registerService(anyObject(Class.class), (Object)anyObject(), anyObject())).andReturn(null).anyTimes(); replay(mocks); cmd.execute(); verify(mocks); }
@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) { 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; }
ManageRealmCommand extends JaasCommandSupport { @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) { 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; } }
ManageRealmCommand extends JaasCommandSupport { @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) { 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; }  }
ManageRealmCommand extends JaasCommandSupport { @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) { 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; }  @SuppressWarnings("unchecked") @Override Object execute(); }
ManageRealmCommand extends JaasCommandSupport { @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) { 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; }  @SuppressWarnings("unchecked") @Override Object execute();  }