@Before public void setup() { ThreadContext.remove(); Ini config = new Ini(); config.setSectionProperty("main", "myRealm", "org.apache.shiro.realm.jdbc.JdbcRealm"); config.setSectionProperty("main", "myRealmCredentialsMatcher", "org.apache.shiro.authc.credential.Sha256CredentialsMatcher"); config.setSectionProperty("main", "myRealm.credentialsMatcher", "$myRealmCredentialsMatcher"); config.setSectionProperty("main", "securityManager.sessionManager.sessionValidationSchedulerEnabled", "false"); IniSecurityManagerFactory factory = new IniSecurityManagerFactory(config); securityManager = (DefaultSecurityManager) factory.createInstance(); SecurityUtils.setSecurityManager(securityManager); // Create a database and realm for the test createRealm(name.getMethodName()); }
protected static SecurityManager createTestSecurityManager() { Ini ini = new Ini(); ini.setSectionProperty("users", "test", "test"); return new DefaultSecurityManager(new IniRealm(ini)); }
private Ini readURLPatterns() { Ini iniWithURLS = createIni(config.getLocationSecuredURLProperties(), false); //securedURLs.ini is optional since 0.9.7 if (iniWithURLS == null) { iniWithURLS = new Ini(); } if (iniWithURLS.getSectionProperty(APP_URL, "/**") != null) { LOGGER.warn("securedURLs.ini file contains /** definition and thus blocks programmatic URL definition (by system or developer)"); } List<ProgrammaticURLProtectionProvider> urlProtectionProviders = BeanProvider.getContextualReferences(ProgrammaticURLProtectionProvider.class, true); orderURLProtectionProviders(urlProtectionProviders); for (ProgrammaticURLProtectionProvider urlProtectionProvider : urlProtectionProviders) { for (Map.Entry<String, String> entry : urlProtectionProvider.getURLEntriesToAdd().entrySet()) { iniWithURLS.setSectionProperty(APP_URL, entry.getKey(), entry.getValue()); } } iniWithURLS.setSectionProperty(APP_URL, "/**", "anon"); return iniWithURLS; }
ini.setSectionProperty("main", "ldapRealm", "org.apache.knox.gateway.shirorealm.KnoxLdapRealm"); ini.setSectionProperty("main", "ldapContextFactory", "org.apache.knox.gateway.shirorealm.KnoxLdapContextFactory"); ini.setSectionProperty("main", "ldapRealm.contextFactory.url", url);
ini.setSectionProperty("main", "ldapRealm", "org.apache.knox.gateway.shirorealm.KnoxLdapRealm"); ini.setSectionProperty("main", "ldapContextFactory", "org.apache.knox.gateway.shirorealm.KnoxLdapContextFactory"); ini.setSectionProperty("main", "ldapRealm.contextFactory.url", url);
/** * Adds a default filter chain path <code>/** = authc</code> if one is not found in the Ini file, otherwise * returns the <code>ini</code> object untouched. * * @param ini The configuration Ini object to be updated * @return an updated configuration Ini. */ private Ini addDefaultsToIni(Ini ini) { // protect the world if the URL section is missing Ini.Section urls = ini.getSection(IniFilterChainResolverFactory.URLS); Ini.Section filters = ini.getSection(IniFilterChainResolverFactory.FILTERS); // deprecated behavior if (CollectionUtils.isEmpty(urls) && CollectionUtils.isEmpty(filters)) { ini.setSectionProperty(IniFilterChainResolverFactory.URLS, "/**", DefaultFilter.authc.name()); } return ini; }