本文整理汇总了Java中org.apache.shiro.config.Ini.Section类的典型用法代码示例。如果您正苦于以下问题:Java Section类的具体用法?Java Section怎么用?Java Section使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Section类属于org.apache.shiro.config.Ini包,在下文中一共展示了Section类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: usersSection
import org.apache.shiro.config.Ini.Section; //导入依赖的package包/类
private Section usersSection(ServletContext servletContext) {
if ( !initialized ) {
synchronized (this) {
try {
if ( initialized )
return usersSection;
initialized = true;
IniWebEnvironment env = (IniWebEnvironment)WebUtils.getWebEnvironment(servletContext) ;
usersSection = env.getIni().getSection("users") ;
} catch (Exception ex) {
LoggerFactory.getLogger(getClass()).error("Failed to find the shiro.ini [users] section");
}
}
}
return usersSection ;
}
示例2: getObject
import org.apache.shiro.config.Ini.Section; //导入依赖的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;
}
示例3: getObject
import org.apache.shiro.config.Ini.Section; //导入依赖的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;
}
示例4: parseGroups
import org.apache.shiro.config.Ini.Section; //导入依赖的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);
}
}
示例5: getObject
import org.apache.shiro.config.Ini.Section; //导入依赖的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;
}
示例6: createDefaults
import org.apache.shiro.config.Ini.Section; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected Map<String, ?> createDefaults(Ini ini, Section mainSection) {
Map defaults = super.createDefaults(ini, mainSection);
defaults.putAll(namedBeanMap);
return defaults;
}
示例7: entrySet
import org.apache.shiro.config.Ini.Section; //导入依赖的package包/类
@Override
public Set<java.util.Map.Entry<String, String>> entrySet() {
Section section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
if(section!=null){
return section.entrySet();
}else{
return EMPTY_SECTION.entrySet();
}
}
示例8: getObjectType
import org.apache.shiro.config.Ini.Section; //导入依赖的package包/类
public Class<?> getObjectType() {
return Ini.Section.class;
}
示例9: putDefinitionSection
import org.apache.shiro.config.Ini.Section; //导入依赖的package包/类
private void putDefinitionSection(Section section, String key, String value) {
log.debug("加载数据库权限:【key=" + key + "/tvalue=" + value + "】");
section.put(key, MessageFormat.format(PREMISSION_FORMAT, value));
}
示例10: getObjectType
import org.apache.shiro.config.Ini.Section; //导入依赖的package包/类
@Override
public Class<?> getObjectType() {
return Section.class;
}
示例11: afterPropertiesSet
import org.apache.shiro.config.Ini.Section; //导入依赖的package包/类
public void afterPropertiesSet() throws Exception {
log.info("start detect url filter chain definitions.");
//加载默认的url
ini.load(filterChainDefinitions);
Ini.Section section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
Map<String, Object> beansWithAnnotation = this.applicationContext.getBeansWithAnnotation(Controller.class);
Iterator<Entry<String, Object>> iterator = beansWithAnnotation.entrySet().iterator();
Map<String,Protected> urls = new LinkedHashMap<String,Protected>();
while(iterator.hasNext()){
Entry<String, Object> next = iterator.next();
String beanName = next.getKey();
RequestMapping mapping = applicationContext.findAnnotationOnBean(beanName, RequestMapping.class);
Class<?> handlerType = applicationContext.getType(beanName);
Protected typeProtect = applicationContext.findAnnotationOnBean(beanName, Protected.class);
Map<String, Protected> methodUrls = determineMethodsProtected(handlerType, mapping, typeProtect);
urls.putAll(methodUrls);
Boolean isControllerProtected = typeProtect!=null;
boolean haveMappingSetting = (mapping!=null) && haveMappingSetting(mapping.value());
if(isControllerProtected && haveMappingSetting){
// controller 設置了protected 而且有Mapping設置
for (String typeLevelPattern : mapping.value()) {
if (!typeLevelPattern.startsWith("/")) {
typeLevelPattern = "/" + typeLevelPattern;
}
if(!typeLevelPattern.endsWith("/")){
typeLevelPattern = typeLevelPattern+"/";
}
urls.put(typeLevelPattern,typeProtect);
urls.put(typeLevelPattern+"**",typeProtect);
}
}
}
for(String url:urls.keySet()){
if(StringUtils.isNotEmpty(url) && !"/".equals(url)) {
Protected protectAno = urls.get(url);
StringBuilder auth = new StringBuilder("");
if(protectAno!=null && protectAno.allowAnon()){
auth.append("anon");
}else if(protectAno!=null){
auth.append("authc");
String[] roles = protectAno.role();
String[] permission = protectAno.permission();
if(protectAno!=null && !isCollectionEmpty(roles)){
auth.append(",roles[");
for(int i=0;i<roles.length;i++){
if(i>0){
auth.append(",");
}
auth.append(roles[i]);
}
auth.append("]");
}
if(protectAno!=null && !isCollectionEmpty(permission)){
auth.append(",perms[");
for(int i=0;i<permission.length;i++){
if(i>0){
auth.append(",");
}
auth.append(permission[i]);
}
auth.append("]");
}
}
if(protectAno == null){
System.out.println();
}
log.info("detected url filter chain:"+url+"="+auth.toString());
section.put(url,auth.toString());
}
}
if(protectAll){
section.put("/**","authc");
}else if(StringUtils.isNotEmpty(defaultAccess)){
section.put("/**",defaultAccess);
}
// cache the annotation information;
this.sectionUrls = urls;
}