Package org.apache.shiro.config

Examples of org.apache.shiro.config.Ini$Section


public class PermissionToRoleMapperFromIniTest {

    @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();
       
        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:*"))));
 
View Full Code Here


     */
    public void setResourcePath(String resourcePath) {
        if(permissionToRoleMapper != null) {
            throw new IllegalStateException("Permissions already set, " + permissionToRoleMapper.getClass().getName());
        }
        final Ini ini = Ini.fromResourcePath(resourcePath);
        this.permissionToRoleMapper = new PermissionToRoleMapperFromIni(ini);
    }
View Full Code Here

        }
        return brokerService;
    }

    protected ShiroPlugin createPlugin(String iniPath) {
        Ini ini = Ini.fromResourcePath(iniPath);
        Environment env = new IniEnvironment(ini);
        ShiroPlugin plugin = new ShiroPlugin();
        plugin.setEnvironment(env);
        return plugin;
    }
View Full Code Here

    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());
    }
View Full Code Here

        assertEquals(ini, realm.getIni());
    }

    public void testSetIni() throws Exception {
        ShiroPlugin plugin = new ShiroPlugin();
        Ini ini = Ini.fromResourcePath("classpath:minimal.shiro.ini");
        plugin.setIni(ini);
        plugin.installPlugin(new MutableBrokerFilter(null));

        IniRealm realm = (IniRealm) ((DefaultSecurityManager) plugin.getEnvironment().getSecurityManager()).getRealms().iterator().next();
        assertSame(ini, realm.getIni());
View Full Code Here

                "[roles]\n" +
                "system = *");
        plugin.installPlugin(new MutableBrokerFilter(null));

        IniRealm realm = (IniRealm) ((DefaultSecurityManager) plugin.getEnvironment().getSecurityManager()).getRealms().iterator().next();
        Ini ini = realm.getIni();
        assertEquals(1, ini.getSection("users").size());
        assertEquals("manager, system", ini.getSection("users").get("system"));
        assertEquals(1, ini.getSection("roles").size());
        assertEquals("*", ini.getSection("roles").get("system"));
    }
View Full Code Here

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

        plugin.setIniResourcePath(path);
        plugin.installPlugin(new MutableBrokerFilter(null));

        Ini ini = Ini.fromResourcePath(path);

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

        subject.login(new UsernamePasswordToken(username, password));
    }

    @Test
    public void testIniInstanceConstructorArg() {
        Ini ini = new Ini();
        ini.addSection("users").put("foo", "bar");
        env = new IniEnvironment(ini);
        authenticate();
    }
View Full Code Here

        authenticate();
    }

    @Test
    public void testSetIni() {
        Ini ini = new Ini();
        ini.addSection("users").put("foo", "bar");

        env = new IniEnvironment();
        env.setIni(ini);
        env.init();
View Full Code Here

     
     
      /*
       * Main ini section
       */
      Ini ini = new Ini();
      Section main = ini.addSection("main");
     

      /*
       * Get the login url
       * TODO: Should we also allow a configuration with a standard 403 response?
       */
      String loginUrl = (String) securityConfig.get("loginUrl");
      main.put("authc.loginUrl", loginUrl == null ? "/login/" : loginUrl);
     
      /*
       * Set up our realm, right now only LDAP
       * This also sets up an authorization cache
       * TODO: Add ability to have other and more advanced realms
       */
      Map<String,String> ldapConfig = (Map<String, String>) securityConfig.get("ldap");
      if (ldapConfig != null) {
        main.put("ldapRealm", "com.adaptrex.core.security.realm.BasicLdapRealm");
        main.put("ldapRealm.searchBase", ldapConfig.get("searchBase"));
        main.put("ldapRealm.userDnTemplate", ldapConfig.get("userDnTemplate"));
        main.put("ldapRealm.contextFactory.url", ldapConfig.get("url"));
        main.put("ldapRealm.authorizationCacheName", "com.adaptrex.cache.authorizationCache");
        main.put("ldapRealm.authenticationCacheName", "com.adaptrex.cache.authenticationCache");
      }
     
      // Adaptrex Shiro Cache Manager
      main.put("cacheManager", "com.adaptrex.core.security.shiro.AdaptrexShiroCacheManager");
      main.put("cacheManager.cacheManagerConfigFile", "classpath:adaptrex-ehcache.xml");
      main.put("securityManager.cacheManager", "$cacheManager");

      // Need to use native session for single sign on
      main.put("sessionManager", "org.apache.shiro.web.session.mgt.DefaultWebSessionManager");
      main.put("sessionManager.globalSessionTimeout", timeout);
      main.put("securityManager.sessionManager", "$sessionManager");

      // DAO for cached sessions
      main.put("sessionDAO", "org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO");
      main.put("sessionDAO.activeSessionsCacheName", "com.adaptrex.cache.ActiveSession." + ssoName);
      main.put("securityManager.sessionManager.sessionDAO", "$sessionDAO");
     
      // cookie for single sign on
      main.put("cookie", "org.apache.shiro.web.servlet.SimpleCookie");
      main.put("cookie.name", "session." + ssoName);
      main.put("cookie.path", "/");
      main.put("securityManager.sessionManager.sessionIdCookie", "$cookie");
     
     
      /*
       * URLs ini section
       */
      Section urls = ini.addSection("urls");
     
      /*
       * Add standard urls
       * TODO: login should be customized based on the config for this webapp
       */
 
View Full Code Here

TOP

Related Classes of org.apache.shiro.config.Ini$Section

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.