if (newSectionName != null) { addSection(sectionName, sectionContent); addSection(sectionName, sectionContent);
Section section = this.getSection(entry.getKey()); if (section == null) { section = addSection(entry.getKey());
/** * Sets a name/value pair for the section with the given {@code sectionName}. If the section does not yet exist, * it will be created. If the {@code sectionName} is null or empty, the name/value pair will be placed in the * default (unnamed, empty string) section. * * @param sectionName the name of the section to add the name/value pair * @param propertyName the name of the property to add * @param propertyValue the property value */ public void setSectionProperty(String sectionName, String propertyName, String propertyValue) { String name = cleanName(sectionName); Section section = getSection(name); if (section == null) { section = addSection(name); } section.put(propertyName, propertyValue); }
public SecurityManagerProvider(String shiroConfig) { this.securityManager = null; IniSecurityManagerFactory factory = new IniSecurityManagerFactory("classpath:" + shiroConfig); // we will need to make sure that shiro uses a case sensitive permission resolver Ini.Section main = factory.getIni().addSection("main"); main.put("geodePermissionResolver", GeodePermissionResolver.class.getName()); if (!main.containsKey("iniRealm.permissionResolver")) { main.put("iniRealm.permissionResolver", "$geodePermissionResolver"); } shiroManager = factory.getInstance(); }
@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); }
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); } }
@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); } } }
Ini.Section users = ini.addSection("users"); users.put("user1", "user1,role1"); users.put("user2", "user2,role2");
/** * Extracts the url section of the Ini file, or creates one if it doesn't * already exist * * @param ini * @return */ private Section getOrCreateUrlSection(final Ini ini) { final String URL_SECTION_TITLE = "urls"; Section urlSection = ini.getSection(URL_SECTION_TITLE); if (urlSection == null) { LOG.debug("shiro.ini does not contain a [urls] section; creating one"); urlSection = ini.addSection(URL_SECTION_TITLE); } else { LOG.debug("shiro.ini contains a [urls] section; appending rules to existing"); } return urlSection; }
@Override public Realm createRealm(Injector injector) { Ini ini = new Ini(); if (users != null && !users.isEmpty()) { ini.addSection("users").putAll(users); } if (roles != null && !roles.isEmpty()) { ini.addSection("roles").putAll(roles); } IniRealm realm = new IniRealm(ini); realm.setIni(ini); if (name != null) { realm.setName(name); } return realm; } }
Ini ini=new Ini(); Ini.Section section = ini.addSection(IniRealm.USERS_SECTION_NAME); section.put("guest", "guest, guest"); section.put("lonestarr", "vespa, goodguy");
/** * Sets a name/value pair for the section with the given {@code sectionName}. If the section does not yet exist, * it will be created. If the {@code sectionName} is null or empty, the name/value pair will be placed in the * default (unnamed, empty string) section. * * @param sectionName the name of the section to add the name/value pair * @param propertyName the name of the property to add * @param propertyValue the property value */ public void setSectionProperty(String sectionName, String propertyName, String propertyValue) { String name = cleanName(sectionName); Section section = getSection(name); if (section == null) { section = addSection(name); } section.put(propertyName, propertyValue); }
ini.addSection("main"); ini.setSectionProperty("main", "ldapRealm", "org.apache.knox.gateway.shirorealm.KnoxLdapRealm"); ini.setSectionProperty("main", "ldapContextFactory", "org.apache.knox.gateway.shirorealm.KnoxLdapContextFactory");
ini.addSection("main"); ini.setSectionProperty("main", "ldapRealm", "org.apache.knox.gateway.shirorealm.KnoxLdapRealm"); ini.setSectionProperty("main", "ldapContextFactory", "org.apache.knox.gateway.shirorealm.KnoxLdapContextFactory");
@Override public void setIni(Ini ini) { try { processAdditionalIniFiles(ini); ini.addSection(IniFilterChainResolverFactory.URLS); // Create the empty section Ini iniWithURLS = readURLPatterns(); addManuallyConfiguredUrls(ini.getSection(IniFilterChainResolverFactory.URLS), iniWithURLS .getSection(APP_URL)); configureCache(ini); configureSessionStorageEvaluator(ini); addPluginConfiguration(ini); String hashAlgorithmName = config.getHashAlgorithmName(); if (!hashAlgorithmName.isEmpty()) { checkHashAlgorithmName(hashAlgorithmName); addHashedCredentialsConfig(ini, hashAlgorithmName); } addAuthenticationListener(ini); } catch (ConfigurationException ex) { LOGGER.error("Exception during configuration of Apache Shiro", ex); } if (config.showDebugFor().contains(Debug.INI)) { logIniContents(ini); } InfoVersionLogging versionLogging = BeanProvider.getContextualReference(InfoVersionLogging.class); versionLogging.showVersionInfo(); super.setIni(ini); }
@Override public void init() throws ShiroException { Ini ini = new Ini(); Preconditions.checkNotNull(getConfigLocations()); for(String p : getConfigLocations()) { Ini subIni = new Ini(ini); subIni.loadFromPath(p); // add all values from the sub file to the main configuration for(Section section : subIni.getSections()) { Section existing = ini.getSection(section.getName()); if(existing == null) { existing = ini.addSection(section.getName()); } existing.putAll(section); } } setIni(ini); configure(); }
@Override protected void configure(CentralDogmaBuilder builder) { builder.authProviderFactory(new ShiroAuthProviderFactory(unused -> { final Ini iniConfig = new Ini(); iniConfig.addSection("users").put(USERNAME, PASSWORD); return iniConfig; })); builder.webAppEnabled(true); } };
protected void configureShiro() { final Ini config = new Ini(); config.addSection("users"); config.getSection("users").put("EntitlementUser", "password, entitlement"); config.addSection("roles"); config.getSection("roles").put("entitlement", Permission.ACCOUNT_CAN_CREATE.toString() + "," + Permission.ENTITLEMENT_CAN_CREATE.toString() + "," + Permission.ENTITLEMENT_CAN_CHANGE_PLAN.toString() + "," + Permission.ENTITLEMENT_CAN_PAUSE_RESUME.toString() + "," + Permission.ENTITLEMENT_CAN_TRANSFER.toString() + "," + Permission.ENTITLEMENT_CAN_CANCEL.toString()); // Reset the security manager ThreadContext.unbindSecurityManager(); final Factory<SecurityManager> factory = new IniSecurityManagerFactory(config); final SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); }
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); } }
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); } }