List of usage examples for org.apache.shiro.config Ini.Section get
public Section get(Object key)
From source file:com.meltmedia.cadmium.servlets.shiro.WebEnvironment.java
License:Apache License
@Override protected FilterChainResolver createFilterChainResolver() { Ini.Section section = this.getIni().getSection(TRUSTED_SECTION_NAME); trustedHosts = new ArrayList<String>(); if (!CollectionUtils.isEmpty(section)) { logger.debug("Found " + TRUSTED_SECTION_NAME + " ini section in shiro.ini"); for (String key : section.keySet()) { logger.debug("Adding " + section.get(key) + " to list of trusted ip addresses."); trustedHosts.add(section.get(key).trim()); }// w ww . ja v a 2 s .com } if (!CollectionUtils.isEmpty(trustedHosts)) { Ini.Section filterConfigs = getIni().getSection(IniFilterChainResolverFactory.FILTERS); if (CollectionUtils.isEmpty(filterConfigs)) { filterConfigs = getIni().addSection(IniFilterChainResolverFactory.FILTERS); } if (!filterConfigs.containsKey(DefaultFilter.authcBasic.name())) { filterConfigs.put(DefaultFilter.authcBasic.name(), "com.meltmedia.cadmium.servlets.shiro.TrustedBasicHttpAuthenticationFilter"); String trustedHostStr = ""; for (String host : trustedHosts) { if (trustedHostStr.length() > 0) { trustedHostStr += ","; } trustedHostStr += host; } filterConfigs.put(DefaultFilter.authcBasic.name() + ".trustedHosts", trustedHostStr); } } return super.createFilterChainResolver(); }
From source file:org.apache.access.provider.file.SimplePolicyEngine.java
License:Apache License
/** * Parse the resource. Should not be used in the normal course *//*from w w w . j av a2s . co m*/ protected void parse() { LOGGER.info("Parsing " + resourcePath); Roles roles = new Roles(); try { perDbResources.clear(); Ini ini = PolicyFiles.loadFromPath(fileSystem, resourcePath); if (LOGGER.isDebugEnabled()) { for (String sectionName : ini.getSectionNames()) { LOGGER.debug("Section: " + sectionName); Ini.Section section = ini.get(sectionName); for (String key : section.keySet()) { String value = section.get(key); LOGGER.debug(key + " = " + value); } } } ImmutableSetMultimap<String, String> globalRoles; Map<String, ImmutableSetMultimap<String, String>> perDatabaseRoles = Maps.newHashMap(); globalRoles = parseIni(null, ini); Ini.Section filesSection = ini.getSection(DATABASES); if (filesSection == null) { LOGGER.info("Section " + DATABASES + " needs no further processing"); } else { for (Map.Entry<String, String> entry : filesSection.entrySet()) { String database = Strings.nullToEmpty(entry.getKey()).trim().toLowerCase(); Path perDbPolicy = new Path(Strings.nullToEmpty(entry.getValue()).trim()); if (isRelative(perDbPolicy)) { perDbPolicy = new Path(resourcePath.getParent(), perDbPolicy); } try { LOGGER.info("Parsing " + perDbPolicy); perDatabaseRoles.put(database, parseIni(database, PolicyFiles.loadFromPath(fileSystem, perDbPolicy))); perDbResources.add(perDbPolicy); } catch (Exception e) { LOGGER.error("Error processing key " + entry.getKey() + ", skipping " + entry.getValue(), e); throw e; } } } roles = new Roles(globalRoles, ImmutableMap.copyOf(perDatabaseRoles)); } catch (Exception e) { LOGGER.error("Error processing file, ignoring " + resourcePath, e); } rolesReference.set(roles); }
From source file:org.apache.sentry.binding.hive.SentryIniPolicyFileFormatter.java
License:Apache License
private Map<String, Set<String>> parseSection(Ini ini, String sctionName) { Map<String, Set<String>> resultMap = Maps.newHashMap(); Ini.Section sction = ini.getSection(sctionName); if (sction == null) { return resultMap; }/*from ww w . j ava 2 s . co m*/ for (String key : sction.keySet()) { String value = sction.get(key); Set<String> roles = Sets.newHashSet(); for (String role : value.split(SentryConstants.ROLE_SEPARATOR)) { if (StringUtils.isNotEmpty(role)) { roles.add(role); } } resultMap.put(key, roles); } return resultMap; }
From source file:org.apache.sentry.provider.file.SimpleFileProviderBackend.java
License:Apache License
private void parse() { configErrors.clear();//from w ww .ja va 2 s . c o m configWarnings.clear(); Table<String, String, Set<String>> groupRolePrivilegeTableTemp = HashBasedTable.create(); Ini ini; LOGGER.info("Parsing " + resourcePath); try { try { ini = PolicyFiles.loadFromPath(fileSystem, resourcePath); } catch (IOException e) { configErrors.add("Failed to read policy file " + resourcePath + " Error: " + e.getMessage()); throw new SentryConfigurationException("Error loading policy file " + resourcePath, e); } catch (IllegalArgumentException e) { configErrors.add("Failed to read policy file " + resourcePath + " Error: " + e.getMessage()); throw new SentryConfigurationException("Error loading policy file " + resourcePath, e); } if (LOGGER.isDebugEnabled()) { for (String sectionName : ini.getSectionNames()) { LOGGER.debug("Section: " + sectionName); Ini.Section section = ini.get(sectionName); for (String key : section.keySet()) { String value = section.get(key); LOGGER.debug(key + " = " + value); } } } parseIni(null, ini, validators, resourcePath, groupRolePrivilegeTableTemp); mergeResult(groupRolePrivilegeTableTemp); groupRolePrivilegeTableTemp.clear(); Ini.Section filesSection = ini.getSection(DATABASES); if (filesSection == null) { LOGGER.info("Section " + DATABASES + " needs no further processing"); } else if (!allowPerDatabaseSection) { String msg = "Per-db policy file is not expected in this configuration."; throw new SentryConfigurationException(msg); } else { for (Map.Entry<String, String> entry : filesSection.entrySet()) { String database = Strings.nullToEmpty(entry.getKey()).trim().toLowerCase(); Path perDbPolicy = new Path(Strings.nullToEmpty(entry.getValue()).trim()); if (isRelative(perDbPolicy)) { perDbPolicy = new Path(resourcePath.getParent(), perDbPolicy); } try { LOGGER.info("Parsing " + perDbPolicy); Ini perDbIni = PolicyFiles.loadFromPath(perDbPolicy.getFileSystem(conf), perDbPolicy); if (perDbIni.containsKey(USERS)) { configErrors.add( "Per-db policy file cannot contain " + USERS + " section in " + perDbPolicy); throw new SentryConfigurationException( "Per-db policy files cannot contain " + USERS + " section"); } if (perDbIni.containsKey(DATABASES)) { configErrors.add("Per-db policy files cannot contain " + DATABASES + " section in " + perDbPolicy); throw new SentryConfigurationException( "Per-db policy files cannot contain " + DATABASES + " section"); } parseIni(database, perDbIni, validators, perDbPolicy, groupRolePrivilegeTableTemp); } catch (Exception e) { configErrors.add( "Failed to read per-DB policy file " + perDbPolicy + " Error: " + e.getMessage()); LOGGER.error("Error processing key " + entry.getKey() + ", skipping " + entry.getValue(), e); } } } mergeResult(groupRolePrivilegeTableTemp); groupRolePrivilegeTableTemp.clear(); } catch (Exception e) { configErrors.add("Error processing file " + resourcePath + e.getMessage()); LOGGER.error("Error processing file, ignoring " + resourcePath, e); } }
From source file:org.apache.sentry.provider.file.SimplePolicyEngine.java
License:Apache License
/** * Parse the resource. Should not be used in the normal course */// w w w .j ava 2s .c om protected void parse() { LOGGER.info("Parsing " + resourcePath); Roles roles = new Roles(); try { perDbResources.clear(); Ini ini = PolicyFiles.loadFromPath(fileSystem, resourcePath); if (LOGGER.isDebugEnabled()) { for (String sectionName : ini.getSectionNames()) { LOGGER.debug("Section: " + sectionName); Ini.Section section = ini.get(sectionName); for (String key : section.keySet()) { String value = section.get(key); LOGGER.debug(key + " = " + value); } } } ImmutableSetMultimap<String, String> globalRoles; Map<String, ImmutableSetMultimap<String, String>> perDatabaseRoles = Maps.newHashMap(); globalRoles = parseIni(null, ini); Ini.Section filesSection = ini.getSection(DATABASES); if (filesSection == null) { LOGGER.info("Section " + DATABASES + " needs no further processing"); } else { for (Map.Entry<String, String> entry : filesSection.entrySet()) { String database = Strings.nullToEmpty(entry.getKey()).trim().toLowerCase(); Path perDbPolicy = new Path(Strings.nullToEmpty(entry.getValue()).trim()); if (isRelative(perDbPolicy)) { perDbPolicy = new Path(resourcePath.getParent(), perDbPolicy); } try { LOGGER.info("Parsing " + perDbPolicy); Ini perDbIni = PolicyFiles.loadFromPath(fileSystem, perDbPolicy); if (perDbIni.containsKey(USERS)) { throw new ConfigurationException( "Per-db policy files cannot contain " + USERS + " section"); } if (perDbIni.containsKey(DATABASES)) { throw new ConfigurationException( "Per-db policy files cannot contain " + DATABASES + " section"); } ImmutableSetMultimap<String, String> currentDbRoles = parseIni(database, perDbIni); perDatabaseRoles.put(database, currentDbRoles); perDbResources.add(perDbPolicy); } catch (Exception e) { LOGGER.error("Error processing key " + entry.getKey() + ", skipping " + entry.getValue(), e); } } } roles = new Roles(globalRoles, ImmutableMap.copyOf(perDatabaseRoles)); } catch (Exception e) { LOGGER.error("Error processing file, ignoring " + resourcePath, e); } rolesReference.set(roles); }
From source file:org.obiba.opal.core.upgrade.security.HashShiroIniPasswordUpgradeStepTest.java
License:Open Source License
@Test public void testExecute() throws Exception { String iniFileMd5 = new Md5Hash(iniFile).toHex(); upgradeStep.execute(null);/*from w ww .j av a 2 s .c o m*/ assertThat(iniBackup.exists()).isTrue(); assertThat(new Md5Hash(iniBackup).toHex()).isEqualTo(iniFileMd5); assertThat(destIniFile.exists()).isTrue(); assertThat(new Md5Hash(destIniFile).toHex()).isNotEqualTo(iniFileMd5); Ini ini = new Ini(); ini.loadFromPath(destIniFile.getAbsolutePath()); Ini.Section section = ini.getSection(IniRealm.USERS_SECTION_NAME); assertThat(section).isNotNull(); assertThat(section).hasSize(3); for (String username : usernamePassword.keySet()) { assertThat(section.containsKey(username)).isTrue(); String[] passwordAndRolesArray = StringUtils.split(section.get(username)); String encrypted = passwordAndRolesArray[0]; assertThat(passwordService.passwordsMatch(usernamePassword.get(username), encrypted)).isTrue(); } }
From source file:org.ow2.proactive.workflowcatalog.security.LoginConfigurationIniRealmTest.java
License:Open Source License
@Test public void users_list_is_correct() throws Exception { Ini.Section usersSection = getUsersSection(); Assert.assertNotNull(usersSection.get("admin")); Assert.assertNotNull(usersSection.get("user")); Assert.assertEquals(usersSection.get("admin"), "adminpwd,usergrp,admingrp"); Assert.assertEquals(usersSection.get("user"), "userpwd,usergrp"); }