Java Code Examples for org.apache.shiro.config.Ini#Section
The following examples show how to use
org.apache.shiro.config.Ini#Section .
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 |
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 |
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 |
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: AbstractThymeleafShiroDialectTest.java From thymeleaf-extras-shiro with Apache License 2.0 | 6 votes |
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); }
Example 5
Source File: ChainDefinitionSectionMetaSource.java From zhcc-server with Apache License 2.0 | 5 votes |
@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 6
Source File: ChainDefinitionSectionMetaSource.java From Autumn with GNU General Public License v2.0 | 5 votes |
@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 7
Source File: ChainDefinitionSectionMetaSource.java From Autumn with GNU General Public License v2.0 | 5 votes |
@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; }
Example 8
Source File: HttpSecurityIT.java From attic-aurora with Apache License 2.0 | 5 votes |
@Before public void setUp() { ini = new Ini(); credentialsMatcher = SimpleCredentialsMatcher.class; 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)); 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()); auroraAdmin = createMock(AnnotatedAuroraAdmin.class); afterAuthCalls = new AtomicInteger(); }
Example 9
Source File: ShiroDialectTest.java From thymeleaf-extras-shiro with Apache License 2.0 | 5 votes |
private static void setupShiro() { 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); }