Ini ini = new Ini(new File(filename)); java.util.prefs.Preferences prefs = new IniPreferences(ini); System.out.println("grumpy/homePage: " + prefs.node("grumpy").get("homePage", null));
protected Ini mergeIni(Ini ini1, Ini ini2) { if (ini1 == null) { return ini2; } if (ini2 == null) { return ini1; } // at this point we have two valid ini objects, create a new one and merge the contents of 2 into 1 Ini iniResult = new Ini(ini1); iniResult.merge(ini2); return iniResult; }
protected Ini convertConfigToIni(String config) { Ini ini = new Ini(); ini.load(config); return ini; }
Ini ini = new Ini(new File("/path/to/file")); System.out.println(ini.get("header", "key"));
/** * Creates a new {@code Ini} instance loaded with the INI-formatted data in the resource at the given path. The * resource path may be any value interpretable by the * {@link ResourceUtils#getInputStreamForPath(String) ResourceUtils.getInputStreamForPath} method. * * @param resourcePath the resource location of the INI data to load when creating the {@code Ini} instance. * @return a new {@code Ini} instance loaded with the INI-formatted data in the resource at the given path. * @throws ConfigurationException if the path cannot be loaded into an {@code Ini} instance. */ public static Ini fromResourcePath(String resourcePath) throws ConfigurationException { if (!StringUtils.hasLength(resourcePath)) { throw new IllegalArgumentException("Resource Path argument cannot be null or empty."); } Ini ini = new Ini(); ini.loadFromPath(resourcePath); return ini; }
/** * Returns a new Ini instance created from the default {@code classpath:shiro.ini} file, or {@code null} if * the file does not exist. * * @return a new Ini instance created from the default {@code classpath:shiro.ini} file, or {@code null} if * the file does not exist. */ public static Ini loadDefaultClassPathIni() { Ini ini = null; if (ResourceUtils.resourceExists(DEFAULT_INI_RESOURCE_PATH)) { log.debug("Found shiro.ini at the root of the classpath."); ini = new Ini(); ini.loadFromPath(DEFAULT_INI_RESOURCE_PATH); if (CollectionUtils.isEmpty(ini)) { log.warn("shiro.ini found at the root of the classpath, but it did not contain any data."); } } return ini; }
@Test public void testEmptyIni() { new IniRealm(new Ini()); }
/** * Returns the INI instance reflecting the specified servlet context resource path or {@code null} if no * resource was found. * * @param servletContextPath the servlet context resource path of the INI file to load * @return the INI instance reflecting the specified servlet context resource path or {@code null} if no * resource was found. * @since 1.2 */ protected Ini getServletContextIniResource(String servletContextPath) { String path = WebUtils.normalize(servletContextPath); if (getServletContext() != null) { InputStream is = getServletContext().getResourceAsStream(path); if (is != null) { Ini ini = new Ini(); ini.load(is); if (CollectionUtils.isEmpty(ini)) { log.warn("ServletContext INI resource '" + servletContextPath + "' exists, but it did not contain " + "any data."); } return ini; } } return null; }
@Inject public KillBillOktaRealm(final SecurityConfig securityConfig) { this.securityConfig = securityConfig; this.httpClient = new AsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeout(DEFAULT_TIMEOUT_SECS * 1000).build()); if (securityConfig.getShiroOktaPermissionsByGroup() != null) { final Ini ini = new Ini(); // When passing properties on the command line, \n can be escaped ini.load(securityConfig.getShiroOktaPermissionsByGroup().replace("\\n", "\n")); for (final Section section : ini.getSections()) { for (final String role : section.keySet()) { final Collection<String> permissions = ImmutableList.<String>copyOf(SPLITTER.split(section.get(role))); permissionsByGroup.put(role, permissions); } } } }
Ini ini = new Ini();
/** * A convenience method that sets the {@link #setFilterChainDefinitionMap(java.util.Map) filterChainDefinitionMap} * property by accepting a {@link java.util.Properties Properties}-compatible string (multi-line key/value pairs). * Each key/value pair must conform to the format defined by the * {@link FilterChainManager#createChain(String,String)} JavaDoc - each property key is an ant URL * path expression and the value is the comma-delimited chain definition. * * @param definitions a {@link java.util.Properties Properties}-compatible string (multi-line key/value pairs) * where each key/value pair represents a single urlPathExpression-commaDelimitedChainDefinition. */ public void setFilterChainDefinitions(String definitions) { Ini ini = new Ini(); ini.load(definitions); //did they explicitly state a 'urls' section? Not necessary, but just in case: Ini.Section section = ini.getSection(IniFilterChainResolverFactory.URLS); if (CollectionUtils.isEmpty(section)) { //no urls section. Since this _is_ a urls chain definition property, just assume the //default section contains only the definitions: section = ini.getSection(Ini.DEFAULT_SECTION_NAME); } setFilterChainDefinitionMap(section); }
ini = new Ini(); ini.load(is); } else {
protected static SecurityManager createTestSecurityManager() { Ini ini = new Ini(); ini.setSectionProperty("users", "test", "test"); return new DefaultSecurityManager(new IniRealm(ini)); }
final Ini ini = new Ini();
@Before public void setup() { sm = new DefaultSecurityManager(); Ini ini = new Ini(); Ini.Section section = ini.addSection(IniRealm.USERS_SECTION_NAME); section.put("guest", "guest, guest"); section.put("lonestarr", "vespa, goodguy"); sm.setRealm(new IniRealm(ini)); SecurityUtils.setSecurityManager(sm); }
@Test public void testVMSingleton() { DefaultSecurityManager sm = new DefaultSecurityManager(); Ini ini = new Ini(); Ini.Section section = ini.addSection(IniRealm.USERS_SECTION_NAME); section.put("guest", "guest"); sm.setRealm(new IniRealm(ini)); SecurityUtils.setSecurityManager(sm); try { Subject subject = SecurityUtils.getSubject(); AuthenticationToken token = new UsernamePasswordToken("guest", "guest"); subject.login(token); subject.getSession().setAttribute("key", "value"); assertTrue(subject.getSession().getAttribute("key").equals("value")); subject = SecurityUtils.getSubject(); assertTrue(subject.isAuthenticated()); assertTrue(subject.getSession().getAttribute("key").equals("value")); } finally { sm.destroy(); //SHIRO-270: SecurityUtils.setSecurityManager(null); } } }
@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 void configureShiro() { final Ini config = new Ini(); config.addSection("users"); config.getSection("users").put("pierre", "password, creditor"); config.getSection("users").put("stephane", "password, refunder"); config.addSection("roles"); config.getSection("roles").put("creditor", Permission.INVOICE_CAN_CREDIT.toString() + "," + Permission.INVOICE_CAN_ITEM_ADJUST.toString()); config.getSection("roles").put("refunder", Permission.PAYMENT_CAN_REFUND.toString()); // Reset the security manager ThreadContext.unbindSecurityManager(); final Factory<SecurityManager> factory = new IniSecurityManagerFactory(config); final SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); } }
@Override public Ini.Section getObject() throws Exception { Ini ini = new Ini(); ini.load(filterChainDefinitions); Ini.Section section = ini.getSection("urls"); if (CollectionUtils.isEmpty(section)) { section = ini.getSection(""); } return section; }
@Test public void testRunAs() { Ini ini = new Ini(); Ini.Section users = ini.addSection("users"); users.put("user1", "user1,role1");