本文整理汇总了Java中org.apache.shiro.config.Ini.getSection方法的典型用法代码示例。如果您正苦于以下问题:Java Ini.getSection方法的具体用法?Java Ini.getSection怎么用?Java Ini.getSection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.shiro.config.Ini
的用法示例。
在下文中一共展示了Ini.getSection方法的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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例7: getObject
import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
@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;
}
示例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);
}
}
示例9: parseGroups
import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
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);
}
}
示例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;
}
示例11: 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;
}
示例12: 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;
}
示例13: 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);
}
示例14: setFilterChainDefinitions
import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
/**
* 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.
*/
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);
}
示例15: buildChains
import org.apache.shiro.config.Ini; //导入方法依赖的package包/类
protected void buildChains(FilterChainManager manager, Ini ini) {
//filters section:
Ini.Section section = ini.getSection(FILTERS);
if (!CollectionUtils.isEmpty(section)) {
String msg = "The [{}] section has been deprecated and will be removed in a future release! Please " +
"move all object configuration (filters and all other objects) to the [{}] section.";
log.warn(msg, FILTERS, IniSecurityManagerFactory.MAIN_SECTION_NAME);
}
Map<String, Object> defaults = new LinkedHashMap<String, Object>();
Map<String, Filter> defaultFilters = manager.getFilters();
//now let's see if there are any object defaults in addition to the filters
//these can be used to configure the filters:
//create a Map of objects to use as the defaults:
if (!CollectionUtils.isEmpty(defaultFilters)) {
defaults.putAll(defaultFilters);
}
//User-provided objects must come _after_ the default filters - to allow the user-provided
//ones to override the default filters if necessary.
if (!CollectionUtils.isEmpty(this.defaultBeans)) {
defaults.putAll(this.defaultBeans);
}
Map<String, Filter> filters = getFilters(section, defaults);
//add the filters to the manager:
registerFilters(filters, manager);
//urls section:
section = ini.getSection(URLS);
createChains(section, manager);
}