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

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

Introduction

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

Prototype

public static Ini fromResourcePath(String resourcePath) throws ConfigurationException 

Source Link

Document

Creates a new Ini instance loaded with the INI-formatted data in the resource at the given path.

Usage

From source file:QuickstartShiroModule.java

License:Apache License

@Provides
Ini loadShiroIni() {
    return Ini.fromResourcePath("classpath:shiro.ini");
}

From source file:fathom.shiro.ShiroModule.java

License:Apache License

@Override
protected void setup() {

    String configFile = getSettings().getString("shiro.configurationFile", "classpath:conf/shiro.ini");
    Ini ini = Ini.fromResourcePath(configFile);

    IniWebEnvironment webEnvironment = new IniWebEnvironment();
    webEnvironment.setIni(ini);//from  w ww .  ja  v a2  s .com
    webEnvironment.setServletContext(getServletContext());
    webEnvironment.init();

    bind(WebEnvironment.class).toInstance(webEnvironment);
    bind(SecurityManager.class).toInstance(webEnvironment.getSecurityManager());
    bind(WebSecurityManager.class).toInstance(webEnvironment.getWebSecurityManager());

    String basePath = Strings.nullToEmpty(getSettings().getString(RestServlet.SETTING_URL, null)).trim();
    filter(basePath + "/*").through(ShiroFilter.class);

    install(new AopModule());
}

From source file:influent.server.auth.SimpleShiroAuthModule.java

License:MIT License

@Provides
Ini loadShiroIni() {
    // Load INI file from specified path
    return Ini.fromResourcePath("classpath:shiro.ini");
}

From source file:org.apache.activemq.shiro.ShiroPluginTest.java

License:Apache License

protected ShiroPlugin createPlugin(String iniPath) {
    Ini ini = Ini.fromResourcePath(iniPath);
    Environment env = new IniEnvironment(ini);
    ShiroPlugin plugin = new ShiroPlugin();
    plugin.setEnvironment(env);// ww w  .  ja v  a 2s  .  c  om
    return plugin;
}

From source file:org.apache.activemq.shiro.ShiroPluginTest.java

License:Apache License

public void testNoEnvironmentOrSecurityManager() throws Exception {
    //should build IniEnvironment from shiro.ini in the classpath at the least:
    ShiroPlugin plugin = new ShiroPlugin();
    plugin.installPlugin(new MutableBrokerFilter(null));

    Ini ini = Ini.fromResourcePath("classpath:shiro.ini");
    IniRealm realm = (IniRealm) ((DefaultSecurityManager) plugin.getEnvironment().getSecurityManager())
            .getRealms().iterator().next();
    assertEquals(ini, realm.getIni());// w w  w.  j  av a2s. c  o m
}

From source file:org.apache.activemq.shiro.ShiroPluginTest.java

License:Apache License

public void testSetIni() throws Exception {
    ShiroPlugin plugin = new ShiroPlugin();
    Ini ini = Ini.fromResourcePath("classpath:minimal.shiro.ini");
    plugin.setIni(ini);/*  www .j ava  2  s  .  co m*/
    plugin.installPlugin(new MutableBrokerFilter(null));

    IniRealm realm = (IniRealm) ((DefaultSecurityManager) plugin.getEnvironment().getSecurityManager())
            .getRealms().iterator().next();
    assertSame(ini, realm.getIni());
}

From source file:org.apache.activemq.shiro.ShiroPluginTest.java

License:Apache License

public void testSetIniResourcePath() throws Exception {
    ShiroPlugin plugin = new ShiroPlugin();

    String path = "classpath:minimal.shiro.ini";

    plugin.setIniResourcePath(path);//from   w  w  w . j a  va  2  s . c o  m
    plugin.installPlugin(new MutableBrokerFilter(null));

    Ini ini = Ini.fromResourcePath(path);

    IniRealm realm = (IniRealm) ((DefaultSecurityManager) plugin.getEnvironment().getSecurityManager())
            .getRealms().iterator().next();
    assertEquals(ini, realm.getIni());
}

From source file:org.apache.aurora.scheduler.http.api.security.ShiroIniConverter.java

License:Apache License

@Override
public Ini convert(String raw) {
    Ini ini;//  ww  w  . j ava2  s .  c o m
    try {
        ini = Ini.fromResourcePath(raw);
    } catch (ConfigurationException e) {
        throw new ParameterException(getErrorString(raw, e.getMessage()), e);
    }

    Set<String> presentSections = ImmutableSortedSet.copyOf(ini.getSectionNames());
    if (presentSections.isEmpty()) {
        throw new MissingSectionsException();
    }

    Set<String> extraSections = Sets.difference(presentSections, ALLOWED_SECTION_NAMES);
    if (!extraSections.isEmpty()) {
        throw new ExtraSectionsException(extraSections);
    }

    return ini;
}

From source file:org.apache.aurora.scheduler.http.api.security.ShiroIniParser.java

License:Apache License

@Override
public Ini doParse(String raw) throws IllegalArgumentException {
    Ini ini;/*from www. j a  va 2 s  . c o m*/
    try {
        ini = Ini.fromResourcePath(raw);
    } catch (ConfigurationException e) {
        throw new ShiroConfigurationException(e);
    }

    Set<String> presentSections = ImmutableSortedSet.copyOf(ini.getSectionNames());
    if (presentSections.isEmpty()) {
        throw new MissingSectionsException();
    }

    Set<String> extraSections = Sets.difference(presentSections, ALLOWED_SECTION_NAMES);
    if (!extraSections.isEmpty()) {
        throw new ExtraSectionsException(extraSections);
    }

    return ini;
}

From source file:org.apache.isis.security.shiro.permrolemapper.PermissionToRoleMapperFromIniTest.java

License:Apache License

@Test
public void test() {
    final Ini ini = Ini.fromResourcePath("classpath:org/apache/isis/security/shiro/permrolemapper/my.ini");
    final Map<String, List<String>> permissionsByRole = new PermissionToRoleMapperFromIni(ini)
            .getPermissionsByRole();/*  w w  w. j a  va2 s  .  c o m*/

    assertThat(permissionsByRole.get("role1"), is(equalTo((List<String>) Lists.newArrayList("foo", "bar"))));
    assertThat(permissionsByRole.get("role2"),
            is(equalTo((List<String>) Lists.newArrayList("fiz:x", "bip:bop:*"))));
    assertThat(permissionsByRole.get("role3"), is(equalTo((List<String>) Lists.newArrayList("*"))));
    assertThat(permissionsByRole.size(), is(3));
}