Example usage for org.apache.shiro.config Ini getSection

List of usage examples for org.apache.shiro.config Ini getSection

Introduction

In this page you can find the example usage for org.apache.shiro.config Ini getSection.

Prototype

public Section getSection(String sectionName) 

Source Link

Document

Returns the Section with the given name or null if no section with that name exists.

Usage

From source file:annis.security.MultipleIniWebEnvironment.java

License:Apache License

@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);//from   ww  w .j  a v a  2 s  . c o  m

        // 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();
}

From source file:com.caricah.iotracah.bootstrap.security.realm.impl.IOTIniBasedRealm.java

License:Apache License

private void processDefinitions(Ini ini) {
    if (CollectionUtils.isEmpty(ini)) {
        log.warn("{} defined, but the ini instance is null or empty.", getClass().getSimpleName());
        return;//from w  w  w  .  ja  v  a2  s  .c  o  m
    }

    Ini.Section rolesSection = ini.getSection(ROLES_SECTION_NAME);
    if (!CollectionUtils.isEmpty(rolesSection)) {
        log.debug("Discovered the [{}] section.  Processing...", ROLES_SECTION_NAME);
        processRoleDefinitions(rolesSection);
    }

    Ini.Section usersSection = ini.getSection(USERS_SECTION_NAME);
    if (!CollectionUtils.isEmpty(usersSection)) {
        log.debug("Discovered the [{}] section.  Processing...", USERS_SECTION_NAME);
        processUserDefinitions(usersSection);
    } else {
        log.info("{} defined, but there is no [{}] section defined.  This realm will not be populated with any "
                + "users and it is assumed that they will be populated programatically.  Users must be defined "
                + "for this Realm instance to be useful.", getClass().getSimpleName(), USERS_SECTION_NAME);
    }
}

From source file:com.centfor.frame.shiro.FrameShiroFilterFactoryBean.java

License:Apache License

/**
 * 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.
 *///from  ww  w.j  a v a 2 s  .  co m
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);
}

From source file:com.codestudio.dorm.web.security.shiro.ChainDefinitionSectionMetaSource.java

License:Open Source License

@Override
public Section getObject() throws Exception {
    // ??//from  w ww. j a  va 2 s. c om
    Ini ini = new Ini();
    // url
    ini.load(filterChainDefinitions);
    Ini.Section section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
    return section;
}

From source file:com.ineunet.knife.security.DefaultChainDefinitionSectionInternal.java

License:Apache License

Section getObject() throws BeansException {
    Ini ini = new Ini();
    ini.load(defaultChainDefinitionSection.filterChainDefinitions);
    //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);
    }/*from w  w  w .ja  v a 2  s  .c o m*/
    defaultChainDefinitionSection.section = section;
    return section;
}

From source file:com.stormpath.shiro.servlet.env.StormpathShiroIniEnvironment.java

License:Apache License

private Ini.Section getConfigSection(Ini ini) {

    Ini.Section configSection = ini.getSection(IniSecurityManagerFactory.MAIN_SECTION_NAME);
    if (CollectionUtils.isEmpty(configSection)) {
        configSection = ini.getSection(Ini.DEFAULT_SECTION_NAME);
        if (configSection == null) {
            configSection = ini.addSection(Ini.DEFAULT_SECTION_NAME);
        }/*from w w w.  jav  a 2  s. c o m*/
    }

    return configSection;
}

From source file:com.stormpath.shiro.servlet.env.StormpathShiroIniEnvironment.java

License:Apache License

private void addDefaultsToIni(Ini ini) {

    // TODO: this is not ideal, we need to make shiro a bit more flexible
    // and this is tightly coupled with the following method
    Ini.Section configSection = getConfigSection(ini);

    // lazy associate the client with the realm, so changes can be made if needed.
    if (!configSection.containsKey(DEFAULTS_STORMPATH_REALM_PROPERTY + ".client")) {
        configSection.put(DEFAULTS_STORMPATH_REALM_PROPERTY + ".client",
                "$" + DEFAULTS_STORMPATH_CLIENT_PROPERTY);
    }//from w ww .  j  av a 2s .  c o m

    // global properties 'shiro.*' are not loaded from the defaults, we must set it in the ini.
    if (!configSection.containsKey("shiro.loginUrl")) {
        configSection.put("shiro.loginUrl", "/login");
    }

    // 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());
    }

}

From source file:com.webarch.common.shiro.dynamic.DynamicPermissionServiceImpl.java

License:Apache License

/**
 * ?????????shiro??map/*from  w  w  w . ja v  a2 s  .co  m*/
 * {@see org.apache.shiro.spring.web.ShiroFilterFactoryBean#setFilterChainDefinitions(String)}
 *
 * @return Section
 */
private Map<String, String> generateSection() {
    Ini ini = new Ini();
    ini.load(definitions); // ?????
    Ini.Section section = ini.getSection(IniFilterChainResolverFactory.URLS); // 
    if (CollectionUtils.isEmpty(section)) {
        section = ini.getSection(Ini.DEFAULT_SECTION_NAME);//?,?
    }
    /**
     * ?????
     */
    Map<String, String> permissionMap = loadDynamicPermission();
    if (!CollectionUtils.isEmpty(permissionMap)) {
        if (CollectionUtils.isEmpty(section)) {
            logger.error(
                    "*********?????URL??????*********");
            return permissionMap;
        } else {
            section.putAll(permissionMap);
        }
    }
    return section;
}

From source file:edu.usu.sdl.openstorefront.security.IniRealmManager.java

License:Apache License

@Override
public List<UserRecord> findUsers(List<String> users) {
    List<UserRecord> userRecords = new ArrayList<>();

    Set<String> userSet = new HashSet<>(users);

    //load config
    Ini ini = new Ini();
    try (InputStream in = new FileInputStream(FileSystemManager.getConfig("shiro.ini"))) {
        ini.load(in);//from   w ww  .j av  a2 s . co m
        Section section = ini.getSection("users");
        for (String user : section.keySet()) {
            if (userSet.contains(user)) {
                UserRecord userRecord = new UserRecord();
                userRecord.setUsername(user);
                userRecords.add(userRecord);
            }
        }
    } catch (IOException ex) {
        throw new OpenStorefrontRuntimeException("Unable to read shiro.ini file.",
                "Check config path and permissions", ex);
    }

    return userRecords;
}

From source file:io.bootique.shiro.realm.IniRealmFactoryTest.java

License:Apache License

@Test
public void testCreateRealm() {
    IniRealmFactory factory = new IniRealmFactory();
    factory.setName("xyz");
    factory.setRoles(Collections.singletonMap("r1", "p1, p2"));
    factory.setUsers(Collections.singletonMap("u1", "up, r1"));

    IniRealm realm = (IniRealm) factory.createRealm(mock(Injector.class));

    assertEquals("xyz", realm.getName());
    assertNull(realm.getResourcePath());

    Ini ini = realm.getIni();
    assertNotNull(realm.getIni());/* ww w .  j a  v  a2s  .  com*/
    assertNotNull(ini.getSection("users"));
    assertNotNull(ini.getSection("roles"));
}