/** * Creates a realm for a test method and puts it in the realMap. */ protected void createRealm(String testMethodName) { JdbcRealm realm = (JdbcRealm) securityManager.getRealms().iterator().next(); realmMap.put(testMethodName, realm); }
private void invalidateJDBCAuthorizationCache(final String username) { final Collection<Realm> realms = ((DefaultSecurityManager) SecurityUtils.getSecurityManager()).getRealms(); final KillBillJdbcRealm killBillJdbcRealm = (KillBillJdbcRealm) Iterables.tryFind(realms, new Predicate<Realm>() { @Override public boolean apply(@Nullable final Realm input) { return (input instanceof KillBillJdbcRealm); } }).orNull(); if (killBillJdbcRealm != null) { final SimplePrincipalCollection principals = new SimplePrincipalCollection(); principals.add(username, killBillJdbcRealm.getName()); killBillJdbcRealm.clearCachedAuthorizationInfo(principals); } } }
public static Collection<Realm> get(final ConfigSource configSource) { final SecurityConfig securityConfig = new ConfigurationObjectFactory(configSource).build(SecurityConfig.class); Collection<Realm> realms = null; try { final Factory<SecurityManager> factory = new IniSecurityManagerFactory(securityConfig.getShiroResourcePath()); // TODO Pierre hack - lame cast here, but we need to have Shiro go through its reflection magic // to parse the [main] section of the ini file. Without duplicating code, this seems to be possible only // by going through IniSecurityManagerFactory. final DefaultSecurityManager securityManager = (DefaultSecurityManager) factory.getInstance(); realms = securityManager.getRealms(); } catch (final ConfigurationException e) { log.warn("Unable to configure RBAC", e); } return realms != null ? realms : ImmutableSet.<Realm>of(new IniRealm(securityConfig.getShiroResourcePath())); // Mainly for testing }
protected static void setupRealms() { Set<Realm> realms = getServices(Realm.class); if (realms.size() > 0) { // if realms are found they probably came from the config, keep them in addition to the ones discovered //note that the ones discovered via SPI takes precedence if (securityManager.getRealms() != null) { realms.addAll(securityManager.getRealms()); } securityManager.setRealms(realms); } else if (securityManager.getRealms() == null || securityManager.getRealms().size() == 0) { log.info("No Realm services setup on the class path, this means if authorization or authentication is " + "configured they may not work as expected"); } }
private void invalidateJDBCAuthorizationCache(final String username) { final Collection<Realm> realms = ((DefaultSecurityManager) SecurityUtils.getSecurityManager()).getRealms(); final KillBillJdbcRealm killBillJdbcRealm = (KillBillJdbcRealm) Iterables.tryFind(realms, new Predicate<Realm>() { @Override public boolean apply(@Nullable final Realm input) { return (input instanceof KillBillJdbcRealm); } }).orNull(); if (killBillJdbcRealm != null) { final SimplePrincipalCollection principals = new SimplePrincipalCollection(); principals.add(username, killBillJdbcRealm.getName()); killBillJdbcRealm.clearCachedAuthorizationInfo(principals); } } }
@Test @RunAsClient public void test() throws InterruptedException { driver.get(deploymentURL.toString()); assertEquals(2, manager.getRealms().size()); WebElement john = driver.findElement(By.id("john")); john.click(); waitForPresent("can not access"); driver.get(deploymentURL.toString()); WebElement marry = driver.findElement(By.id("marry")); marry.click(); waitForPresent("ok"); }
public static Collection<Realm> get(final ConfigSource configSource) { final SecurityConfig securityConfig = new ConfigurationObjectFactory(configSource).build(SecurityConfig.class); Collection<Realm> realms = null; try { final Factory<SecurityManager> factory = new IniSecurityManagerFactory(securityConfig.getShiroResourcePath()); // TODO Pierre hack - lame cast here, but we need to have Shiro go through its reflection magic // to parse the [main] section of the ini file. Without duplicating code, this seems to be possible only // by going through IniSecurityManagerFactory. final DefaultSecurityManager securityManager = (DefaultSecurityManager) factory.getInstance(); realms = securityManager.getRealms(); } catch (final ConfigurationException e) { log.warn("Unable to configure RBAC", e); } return realms != null ? realms : ImmutableSet.<Realm>of(new IniRealm(securityConfig.getShiroResourcePath())); // Mainly for testing }
@Test @RunAsClient public void test() throws Exception { driver.get(deploymentURL.toString()); assertTrue(manager instanceof MySecurityManager); assertTrue(manager.getRememberMeManager() instanceof MyRememberMe); assertEquals(1, manager.getRealms().size()); assertTrue(manager.getRealms().iterator().next() instanceof MyRealm); } }
@Test @RunAsClient public void test() throws Exception { driver.get(deploymentURL.toString()); assertTrue(manager instanceof MySecurityManager); assertTrue(manager.getRememberMeManager() instanceof MyRememberMe); assertEquals(1, manager.getRealms().size()); assertTrue(manager.getRealms().iterator().next() instanceof MyRealm); } }