Java Code Examples for org.apache.shiro.config.Ini#getSection()

The following examples show how to use org.apache.shiro.config.Ini#getSection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShiroFilterChainDefinitions.java    From shiroDemo with Apache License 2.0 6 votes vote down vote up
public Ini.Section getObject() throws Exception {
    List<AuthcMap> list = this.getAuthService().getFilterChainDefinitions();
    Ini ini = new Ini();
    ini.load(this.getFilterChainDefinitions());
    Ini.Section section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
    for (AuthcMap map : list) {
        String s = null;
        switch (AuthcType.valueOf(map.getAuthcType())) {
            case roles:
                s = MessageFormat.format(ROLE_STRING, map.getVal());
                break;
            case perms:
                s = MessageFormat.format(PREMISSION_STRING, map.getVal());
                break;
            case authc:
                s = AuthcType.authc.name();
            case anon:
                s = AuthcType.anon.name();
            default:
                s = AuthcType.authc.name();
        }
        section.put(map.getUrl(), s);
    }
    return section;
}
 
Example 2
Source File: ChainDefinitionSectionMetaSource.java    From dubai with MIT License 6 votes vote down vote up
public Ini.Section getObject() throws BeansException {

        //获取所有Resource
        Iterable<Resource> list = resourceRepository.findAll();

        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.getResource()) && StringUtils.isNotEmpty(resource.getPermission())) {
                section.put(resource.getResource(), MessageFormat.format(PERMISSION_STRING, resource.getPermission()));
            }

        }

        return section;
    }
 
Example 3
Source File: SimpleFileProviderBackend.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example 4
Source File: LocalGroupMappingService.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
private void parseGroups(FileSystem fileSystem, Path resourcePath) throws IOException {
  Ini ini = PolicyFiles.loadFromPath(fileSystem, resourcePath);
  Section usersSection = ini.getSection(PolicyFileConstants.USERS);
  if (usersSection == null) {
    LOGGER.warn("No section " + PolicyFileConstants.USERS + " in the " + resourcePath);
    return;
  }
  for (Entry<String, String> userEntry : usersSection.entrySet()) {
    String userName = Strings.nullToEmpty(userEntry.getKey()).trim();
    String groupNames = Strings.nullToEmpty(userEntry.getValue()).trim();
    if (userName.isEmpty()) {
      LOGGER.error("Invalid user name in the " + resourcePath);
      continue;
    }
    if (groupNames.isEmpty()) {
      LOGGER.warn("No groups available for user " + userName +
          " in the " + resourcePath);
      continue;
    }
    Set<String> groupList = Sets.newHashSet(PolicyConstants.ROLE_SPLITTER.trimResults().split(
        groupNames));
    LOGGER.debug("Got user mapping: " + userName + ", Groups: " + groupNames);
    groupMap.put(userName, groupList);
  }
}
 
Example 5
Source File: ChainDefinitionSectionMetaSource.java    From base-framework with Apache License 2.0 6 votes vote down vote up
@Override
public Section getObject() throws BeansException {
	Ini ini = new Ini();
       //加载默认的url
       ini.load(filterChainDefinitions);
       Section section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
       //循环数据库资源的url
       for (Resource resource : accountManager.getResources()) {
       	if(StringUtils.isNotEmpty(resource.getValue()) && StringUtils.isNotEmpty(resource.getPermission())) {
       		section.put(resource.getValue(), resource.getPermission());
       	}
       }
       
       //循环数据库组的url
       for (Group group : accountManager.getGroup(GroupType.RoleGorup)) {
       	if(StringUtils.isNotEmpty(group.getValue()) && StringUtils.isNotEmpty(group.getRole())) {
       		section.put(group.getValue(), group.getRole());
       	}
       }
       
       return section;
}
 
Example 6
Source File: ChainDefinitionSectionMetaSource.java    From zhcc-server with Apache License 2.0 5 votes vote down vote up
@Override
public Section getObject() throws Exception {
	/*******************************************
	 * rest:例子/admins/user/**=rest[user],根据请求的方法,相当于/admins/user/**=perms[user:method]
	 * ,其中method为post,get,delete等。
	 * port:例子/admins/user/**=port[8081],当请求的url的端口不是8081是跳转到schemal://serverName:8081?queryString,
	 * 其中schmal是协议http或https等,serverName是你访问的host,8081是url配置里port的端口,queryString是你访问的url里的?后面的参数。
	 * perms:例子/admins/user/**=perms[user:add:*],perms参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,
	 * 例如/admins/user/**=perms["user:add:*,user:modify:*"],当有多个参数时必须每个参数都通过才通过,想当于isPermitedAll()方法。
	 * roles:例子/admins/user/**=roles[admin],参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,当有多个参数时,
	 * 例如/admins/user/**=roles["admin,guest"],每个参数通过才算通过,相当于hasAllRoles()方法。
	 * anon:例子/admins/**=anon 没有参数,表示可以匿名使用。
	 * authc:例如/admins/user/**=authc表示需要认证才能使用,没有参数。
	 * authcBasic:例如/admins/user/**=authcBasic没有参数表示httpBasic认证。
	 * ssl:例子/admins/user/**=ssl没有参数,表示安全的url请求,协议为https
	 * user:例如/admins/user/**=user没有参数表示必须存在用户,当登入操作时不做检查。
	 *******************************************/
    //jwtAuthcFilter控制器用来做身份认证,用restfulPermissionFilter做restful权限验证。
	String restPermissionString = "jwtAuthcFilter,restfulPermissionFilter[{0}]";
	
	// 加载默认的url过滤定义
	Ini ini = new Ini();
	ini.load(this.filterChainDefinitions);
	Ini.Section section = ini.getSection(Ini.DEFAULT_SECTION_NAME);

	List<AvailableResourceDTO> dtoList = this.resourceService.listAllAvailable();
	// 将自定义url过滤添加到section中
	for (AvailableResourceDTO dto : dtoList) {
           if(dto.getCode() != null && !dto.getCode().trim().equals("")) {
               if(!section.containsKey(dto.getCode())) {
                   section.put(dto.getUrl(), MessageFormat.format(restPermissionString, dto.getCode()));
               }
           }
	}
	section.put("/**", "jwtAuthcFilter");
	return section;
}
 
Example 7
Source File: ChainDefinitionSectionMetaSource.java    From Autumn with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example 8
Source File: ChainDefinitionSectionMetaSource.java    From Autumn with GNU General Public License v2.0 5 votes vote down vote up
@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;
}