当前位置: 首页>>代码示例>>Java>>正文


Java Ini.Section方法代码示例

本文整理汇总了Java中org.apache.shiro.config.Ini.Section方法的典型用法代码示例。如果您正苦于以下问题:Java Ini.Section方法的具体用法?Java Ini.Section怎么用?Java Ini.Section使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.shiro.config.Ini的用法示例。


在下文中一共展示了Ini.Section方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shiroFilter

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
@Bean
public ShiroFilterFactoryBean shiroFilter() {
	ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean();
	
	//设置Filter映射
	LinkedHashMap<String, Filter> filterMap = new LinkedHashMap<>();
	DefaultCasFilter casFilter = new DefaultCasFilter();
	casFilter.setFailureUrl(loginProperties.getFailureUrl()); //配置验证错误时的失败页面
	casFilter.setReloginUrl(loginProperties.getCasLogin() + "&msg={0}"); //验证错误后显示登录页面,并提示错误信息。只试用于ErrorContext异常
	casFilter.setLogoutUrl(loginProperties.getCasLogout());
	filterMap.put("casFilter", casFilter);
	LogoutFilter logoutFilter = new LogoutFilter();
	logoutFilter.setRedirectUrl(loginProperties.getCasLogout() + "?service=" + loginProperties.getCasLogoutCallback());
	filterMap.put("logoutFilter", logoutFilter);
	filterMap.put("perms", new DefaultPermissionsAuthorizationFilter());
	filterMap.put("authc", new DefaultFormAuthenticationFilter());
	filterMap.put("sense", new SenseLoginFilter());
	factoryBean.setFilters(filterMap);
	
	factoryBean.setSecurityManager(securityManager());
	factoryBean.setLoginUrl(loginProperties.getCasLogin());
	factoryBean.setUnauthorizedUrl(loginProperties.getUnauthorizedUrl());
	//加载权限配置
	Ini ini = new Ini();
	ini.loadFromPath(loginProperties.getShiroFilterFile());
	//did they explicitly state a 'urls' section?  Not necessary, but just in case:
	Ini.Section section = ini.getSection(IniFilterChainResolverFactory.URLS);
	if (MapUtils.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);
	}
	factoryBean.setFilterChainDefinitionMap(section);
	return factoryBean;
}
 
开发者ID:easycodebox,项目名称:easycode,代码行数:36,代码来源:ShiroConfig.java

示例2: setFilterChainDefinitions

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
/**
 * 从数据库动态读取权限
 */
@Override
public void setFilterChainDefinitions(String definitions) {

    MyShiroFilterFactoryBean.definitions = definitions;

    //数据库动态权限
    List<TbShiroFilter> list = systemService.getShiroFilter();
    for(TbShiroFilter tbShiroFilter : list){
        //字符串拼接权限
        definitions = definitions+tbShiroFilter.getName() + " = "+tbShiroFilter.getPerms()+"\n";
    }

    log.info(definitions);

    //从配置文件加载权限配置
    Ini ini = new Ini();
    ini.load(definitions);
    Ini.Section section = ini.getSection("urls");
    if (CollectionUtils.isEmpty(section)) {
        section = ini.getSection("");
    }

    this.setFilterChainDefinitionMap(section);
}
 
开发者ID:Exrick,项目名称:xmall,代码行数:28,代码来源:MyShiroFilterFactoryBean.java

示例3: applyFilterChainResolver

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
protected void applyFilterChainResolver(Ini ini, Map<String, ?> defaults) {
    if (ini == null || ini.isEmpty()) {
        //nothing to use to create the resolver, just return
        //(the AbstractShiroFilter allows a null resolver, in which case the original FilterChain is
        // always used).
        return;
    }

    //only create a resolver if the 'filters' or 'urls' sections are defined:
    Ini.Section urls = ini.getSection(IniFilterChainResolverFactory.URLS);
    Ini.Section filters = ini.getSection(IniFilterChainResolverFactory.FILTERS);
    if ((urls != null && !urls.isEmpty()) || (filters != null && !filters.isEmpty())) {
        //either the urls section or the filters section was defined.  Go ahead and create the resolver
        //and set it:
        IniFilterChainResolverFactory filterChainResolverFactory = new IniFilterChainResolverFactory(ini, defaults);
        filterChainResolverFactory.setFilterConfig(getFilterConfig());
        FilterChainResolver resolver = filterChainResolverFactory.getInstance();
        setFilterChainResolver(resolver);
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:21,代码来源:IniShiroFilter.java

示例4: createFilterChainResolver

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
protected FilterChainResolver createFilterChainResolver() {

        FilterChainResolver resolver = null;

        Ini ini = getIni();

        if (!CollectionUtils.isEmpty(ini)) {
            //only create a resolver if the 'filters' or 'urls' sections are defined:
            Ini.Section urls = ini.getSection(IniFilterChainResolverFactory.URLS);
            Ini.Section filters = ini.getSection(IniFilterChainResolverFactory.FILTERS);
            if (!CollectionUtils.isEmpty(urls) || !CollectionUtils.isEmpty(filters)) {
                //either the urls section or the filters section was defined.  Go ahead and create the resolver:
                IniFilterChainResolverFactory factory = new IniFilterChainResolverFactory(ini, this.objects);
                resolver = factory.getInstance();
            }
        }

        return resolver;
    }
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:20,代码来源:IniWebEnvironment.java

示例5: processDefinitions

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
private void processDefinitions(Ini ini) {
    if (CollectionUtils.isEmpty(ini)) {
        log.warn("{} defined, but the ini instance is null or empty.", getClass().getSimpleName());
        return;
    }

    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);
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:23,代码来源:IniRealm.java

示例6: getObject

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
@Override
public Section getObject() throws Exception {
	Ini ini = new Ini();
	ini.load(filterChainDefinitions);
	Ini.Section section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
	//由注入的资源管理对象获取所有资源数据,并且Resource的authorities的属性是EAGER的fetch类型
	List<Resource> resources = resourceManager.getAll();
	for(Resource resource : resources) {
		if(StringUtils.isEmpty(resource.getSource())) {
			continue;
		}
		for (Authority entity : resource.getAuthorities()) {
			//如果资源的值为分号分隔,则循环构造元数据。分号分隔好处是对一批相同权限的资源,不需要逐个定义
			if(resource.getSource().indexOf(";") != -1) {
				String[] sources = resource.getSource().split(";");
				for(String source : sources) {
				    putDefinitionSection(section, source, entity.getName());
				}
			} else {
			    putDefinitionSection(section, resource.getSource(), entity.getName());
			}
		}
	}
	return section;
}
 
开发者ID:shaisxx,项目名称:snaker-demo,代码行数:26,代码来源:ShiroDefinitionSectionMetaSource.java

示例7: createSecurityManager

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked"})
private SecurityManager createSecurityManager(Ini ini, Ini.Section mainSection) {

    Map<String, ?> defaults = createDefaults(ini, mainSection);
    Map<String, ?> objects = buildInstances(mainSection, defaults);

    SecurityManager securityManager = getSecurityManagerBean();

    boolean autoApplyRealms = isAutoApplyRealms(securityManager);

    if (autoApplyRealms) {
        //realms and realm factory might have been created - pull them out first so we can
        //initialize the securityManager:
        Collection<Realm> realms = getRealms(objects);
        //set them on the SecurityManager
        if (!CollectionUtils.isEmpty(realms)) {
            applyRealmsToSecurityManager(realms, securityManager);
        }
    }

    return securityManager;
}
 
开发者ID:icode,项目名称:ameba-shiro,代码行数:23,代码来源:IniSecurityManagerFactory.java

示例8: parseIni

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
private void parseIni(String database, Ini ini,
    List<? extends PrivilegeValidator> validators, Path policyPath,
    Table<String, String, Set<String>> groupRolePrivilegeTable) {
  Ini.Section privilegesSection = ini.getSection(PolicyFileConstants.ROLES);
  boolean invalidConfiguration = false;
  if (privilegesSection == null) {
    String errMsg = String.format("Section %s empty for %s", PolicyFileConstants.ROLES, policyPath);
    LOGGER.warn(errMsg);
    configErrors.add(errMsg);
    invalidConfiguration = true;
  }
  Ini.Section groupsSection = ini.getSection(PolicyFileConstants.GROUPS);
  if (groupsSection == null) {
    String warnMsg = String.format("Section %s empty for %s", PolicyFileConstants.GROUPS, policyPath);
    LOGGER.warn(warnMsg);
    configErrors.add(warnMsg);
    invalidConfiguration = true;
  }
  if (!invalidConfiguration) {
    parsePrivileges(database, privilegesSection, groupsSection, validators, policyPath,
        groupRolePrivilegeTable);
  }
}
 
开发者ID:apache,项目名称:incubator-sentry,代码行数:24,代码来源:SimpleFileProviderBackend.java

示例9: setupShiro

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
private static void setupShiro() {
    Ini ini = new Ini();
    Ini.Section usersSection = ini.addSection("users");

    usersSection.put(ALICE.email(), ALICE.roles());
    usersSection.put(BOB.email(), BOB.roles());
    usersSection.put(CAESAR.email(), CAESAR.roles());

    Ini.Section rolesSection = ini.addSection("roles");
    rolesSection.put(ROLE_A.label(), ROLE_A.permissions());
    rolesSection.put(ROLE_B.label(), ROLE_B.permissions());
    rolesSection.put(ROLE_C.label(), ROLE_C.permissions());
    rolesSection.put(ROLE_D.label(), ROLE_D.permissions());

    Factory<SecurityManager> factory = new TestIniSecurityManagerFactory(ini);
    SecurityManager secMgr = factory.getInstance();
    setSecurityManager(secMgr);
}
 
开发者ID:theborakompanioni,项目名称:thymeleaf-extras-shiro,代码行数:19,代码来源:AbstractThymeleafShiroDialectTest.java

示例10: getObject

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
public Section getObject() throws Exception {
	String urlPermissions = filterChainDefinitions;
	String dynamicUrlPermissions = getDynamicUrlPermissions();
	urlPermissions = urlPermissions.replace(buildPlaceHolder(), dynamicUrlPermissions);
	urlPermissions = beautifyUrlPermissionExpression(urlPermissions);
	logger.info(">>> Global URL based permission configuration :\n{}", urlPermissions);
	Ini ini = new Ini();
       ini.load(urlPermissions);
       Ini.Section section = ini.getSection(IniFilterChainResolverFactory.URLS);
       if(CollectionUtils.isEmpty(section)){
           section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
       }
	return section;
}
 
开发者ID:penggle,项目名称:xproject,代码行数:15,代码来源:GlobalUrlPermissionFilterChainDefinition.java

示例11: setUp

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
@Before
public void setUp() {
  ini = new Ini();

  Ini.Section users = ini.addSection(IniRealm.USERS_SECTION_NAME);
  users.put(ROOT.getUserName(), COMMA_JOINER.join(ROOT.getPassword(), ADMIN_ROLE));
  users.put(WFARNER.getUserName(), COMMA_JOINER.join(WFARNER.getPassword(), ENG_ROLE));
  users.put(UNPRIVILEGED.getUserName(), UNPRIVILEGED.getPassword());
  users.put(
      BACKUP_SERVICE.getUserName(),
      COMMA_JOINER.join(BACKUP_SERVICE.getPassword(), BACKUP_ROLE));
  users.put(
      DEPLOY_SERVICE.getUserName(),
      COMMA_JOINER.join(DEPLOY_SERVICE.getPassword(), DEPLOY_ROLE));
  users.put(H2_USER.getUserName(), COMMA_JOINER.join(H2_USER.getPassword(), H2_ROLE));

  Ini.Section roles = ini.addSection(IniRealm.ROLES_SECTION_NAME);
  roles.put(ADMIN_ROLE, "*");
  roles.put(ENG_ROLE, "thrift.AuroraSchedulerManager:*");
  roles.put(BACKUP_ROLE, "thrift.AuroraAdmin:listBackups");
  roles.put(
      DEPLOY_ROLE,
      "thrift.AuroraSchedulerManager:killTasks:"
          + ADS_STAGING_JOB.getRole()
          + ":"
          + ADS_STAGING_JOB.getEnvironment()
          + ":"
          + ADS_STAGING_JOB.getName());
  roles.put(H2_ROLE, H2_PERM);

  auroraAdmin = createMock(AnnotatedAuroraAdmin.class);
  shiroAfterAuthFilter = createMock(Filter.class);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:34,代码来源:HttpSecurityIT.java

示例12: beforeClass

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() {
	//Set up shiro
	Ini ini = new Ini();
	Ini.Section usersSection = ini.addSection("users");
	usersSection.put(USER1, PASS1 + ",rolea,roled");
	usersSection.put(USER2, PASS2 + ",roleb,rolec");
	usersSection.put(USER3, PASS3 + ",rolec,rolee");
	Ini.Section rolesSection = ini.addSection("roles");
	rolesSection.put("rolea", "*");
	rolesSection.put("roleb", "permtype1:permaction1:perminst1");
	rolesSection.put("rolec", "permtype1:permaction2:*");
	rolesSection.put("roled", "permtype3:*");
	Factory<SecurityManager> factory = new TestIniSecurityManagerFactory(ini);
	SecurityManager secMgr = factory.getInstance();
	setSecurityManager(secMgr);

	//Set up thymeleaf
	ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
	templateResolver.setCacheable(false);
	templateResolver.setCharacterEncoding("UTF-8");
	templateResolver.setTemplateMode("HTML5");

	templateEngine = new TemplateEngine();
	templateEngine.setTemplateResolver(templateResolver);
	templateEngine.addDialect("shiro", new ShiroDialect());
}
 
开发者ID:usydapeng,项目名称:thymeleaf3-shiro,代码行数:28,代码来源:ShiroDialectTest.java

示例13: getObject

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
@Override
public synchronized Ini.Section getObject() throws Exception {

    //获取所有的插件
    List<Plugin> pluginList = pluginMapper.selectAllStatus1Plugin();

    //获取所有Resource
    List<Resource> list = resourceMapper.selectResourceAllList();

    Ini ini = new Ini();
    //加载默认的url
    ini.load(filterChainDefinitions);
    Ini.Section section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
    //循环Resource的url,逐个添加到section中。section就是filterChainDefinitionMap,
    //里面的键就是链接URL,值就是存在什么条件才能访问该链接
    for (Iterator<Resource> it = list.iterator(); it.hasNext();) {

        Resource resource = it.next();
        //如果不为空值添加到section中
        if(StringUtils.isNotEmpty(resource.getLink_address())) {
            section.put(resource.getLink_address(),  MessageFormat.format(PERMISSION_STRING,resource.getId()));
        }
    }

    for (Iterator<Plugin> iterator = pluginList.iterator(); iterator.hasNext();){
        Plugin plugin = iterator.next();
        if (StringUtils.isNotEmpty(plugin.getDir()) && StringUtils.isNotEmpty(plugin.getHtmlcurl())){
            section.put(plugin.getDir()+plugin.getHtmlcurl(), MessageFormat.format(PERMISSION_STRING,plugin.getId()));
        }
    }
    section.put("/**", "authc");
    logger.debug("the list of filter url:" + section.values() + "---Total:" +section.values().size());
    return section;
}
 
开发者ID:shuaijunlan,项目名称:Autumn-Framework,代码行数:35,代码来源:ChainDefinitionSectionMetaSource.java

示例14: getObject

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
@Override
public synchronized Ini.Section getObject() throws Exception {
    //获取所有Resource
    List<Resource> list = resourceMapper.selectResourceAllList();

    //获取所有的插件
    List<Plugin> pluginList = pluginMapper.selectAllStatus1Plugin();

    Ini ini = new Ini();
    //加载默认的url
    ini.load(filterChainDefinitions);
    Ini.Section section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
    //循环Resource的url,逐个添加到section中。section就是filterChainDefinitionMap,
    //里面的键就是链接URL,值就是存在什么条件才能访问该链接
    for (Iterator<Resource> it = list.iterator(); it.hasNext();) {

        Resource resource = it.next();
        //如果不为空值添加到section中
        if(StringUtils.isNotEmpty(resource.getLink_address())) {
            section.put(resource.getLink_address(),  MessageFormat.format(PERMISSION_STRING,resource.getId()));
        }
    }

    for (Iterator<Plugin> iterator = pluginList.iterator(); iterator.hasNext();){
        Plugin plugin = iterator.next();
        if (StringUtils.isNotEmpty(plugin.getDir()) && StringUtils.isNotEmpty(plugin.getHtmlcurl())){
            section.put(plugin.getDir()+plugin.getHtmlcurl(), MessageFormat.format(PERMISSION_STRING,plugin.getId()));
        }
    }
    section.put("/**", "authc");
    logger.debug("the list of filter url:" + section.values() + "---Total:" +section.values().size());
    return section;
}
 
开发者ID:shuaijunlan,项目名称:Autumn-Framework,代码行数:34,代码来源:ChainDefinitionSectionMetaSource.java

示例15: setDefaultFilterChainDefinitions

import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
public void setDefaultFilterChainDefinitions(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);
}
 
开发者ID:simbest,项目名称:simbest-cores,代码行数:13,代码来源:CustomDefaultFilterChainManager.java


注:本文中的org.apache.shiro.config.Ini.Section方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。