/** * Sets the config path to be used to load a .ini file for configuration if a configuration is * not specified via the {@link #getConfig() config} attribute. * <p/> * This value is {@code null} by default, but it will be automatically set to the value of the * '{@code configPath}' {@code init-param} if it exists in the {@code FilterConfig} provided by the servlet * container at startup. * * @param configPath the config path to be used to load a .ini file for configuration if a configuration is * not specified via the {@link #getConfig() config} attribute. */ public void setConfigPath(String configPath) { this.configPath = StringUtils.clean(configPath); }
/** * Convenience method that returns a request parameter value, first running it through * {@link StringUtils#clean(String)}. * * @param request the servlet request. * @param paramName the parameter name. * @return the clean param value, or null if the param does not exist or is empty. */ public static String getCleanParam(ServletRequest request, String paramName) { return StringUtils.clean(request.getParameter(paramName)); }
private static String cleanName(String sectionName) { String name = StringUtils.clean(sectionName); if (name == null) { log.trace("Specified name was null or empty. Defaulting to the default section (name = \"\")"); name = DEFAULT_SECTION_NAME; } return name; }
protected static boolean isSectionHeader(String line) { String s = StringUtils.clean(line); return s != null && s.startsWith(SECTION_PREFIX) && s.endsWith(SECTION_SUFFIX); }
/** * Returns the value for the named {@code init-param}, or {@code null} if there was no {@code init-param} * specified by that name. * * @param paramName the name of the {@code init-param} * @return the value for the named {@code init-param}, or {@code null} if there was no {@code init-param} * specified by that name. */ protected String getInitParam(String paramName) { FilterConfig config = getFilterConfig(); if (config != null) { return StringUtils.clean(config.getInitParameter(paramName)); } return null; }
/** * Returns the Cookie's calculated path setting. If the {@link javax.servlet.http.Cookie#getPath() path} is {@code null}, then the * {@code request}'s {@link javax.servlet.http.HttpServletRequest#getContextPath() context path} * will be returned. If getContextPath() is the empty string or null then the ROOT_PATH constant is returned. * * @param request the incoming HttpServletRequest * @return the path to be used as the path when the cookie is created or removed */ private String calculatePath(HttpServletRequest request) { String path = StringUtils.clean(getPath()); if (!StringUtils.hasText(path)) { path = StringUtils.clean(request.getContextPath()); } //fix for http://issues.apache.org/jira/browse/SHIRO-9: if (path == null) { path = ROOT_PATH; } log.trace("calculated path: {}", path); return path; }
private void addSection(String name, StringBuilder content) { if (content.length() > 0) { String contentString = content.toString(); String cleaned = StringUtils.clean(contentString); if (cleaned != null) { Section section = new Section(name, contentString); if (!section.isEmpty()) { sections.put(name, section); } } } }
protected static String getSectionName(String line) { String s = StringUtils.clean(line); if (isSectionHeader(s)) { return cleanName(s.substring(1, s.length() - 1)); } return null; }
protected void setParts(String wildcardString, boolean caseSensitive) { wildcardString = StringUtils.clean(wildcardString); if (wildcardString == null || wildcardString.isEmpty()) { throw new IllegalArgumentException("Wildcard string cannot be null or empty. Make sure permission strings are properly formatted."); } if (!caseSensitive) { wildcardString = wildcardString.toLowerCase(); } List<String> parts = CollectionUtils.asList(wildcardString.split(PART_DIVIDER_TOKEN)); this.parts = new ArrayList<Set<String>>(); for (String part : parts) { Set<String> subparts = CollectionUtils.asSet(part.split(SUBPART_DIVIDER_TOKEN)); if (subparts.isEmpty()) { throw new IllegalArgumentException("Wildcard string cannot contain parts with only dividers. Make sure permission strings are properly formatted."); } this.parts.add(subparts); } if (this.parts.isEmpty()) { throw new IllegalArgumentException("Wildcard string cannot contain only dividers. Make sure permission strings are properly formatted."); } }
private static Map<String, String> toMapProps(String content) { Map<String, String> props = new LinkedHashMap<String, String>(); String line; StringBuilder lineBuffer = new StringBuilder(); Scanner scanner = new Scanner(content); while (scanner.hasNextLine()) { line = StringUtils.clean(scanner.nextLine()); if (isContinued(line)) { //strip off the last continuation backslash: line = line.substring(0, line.length() - 1); lineBuffer.append(line); continue; } else { lineBuffer.append(line); } line = lineBuffer.toString(); lineBuffer = new StringBuilder(); String[] kvPair = splitKeyValue(line); props.put(kvPair[0], kvPair[1]); } return props; }
/** * Specifies a comma-delimited list of JNDI names to lookup, each one corresponding to a jndi-bound * {@link Realm Realm}. The Realms will be made available to the SecurityManager in the order * they are defined. * * @param commaDelimited a comma-delimited list of JNDI names, each representing the JNDI name used to * look up a corresponding jndi-bound Realm. * @throws IllegalStateException if the specified argument is null or the empty string. */ public void setJndiNames(String commaDelimited) throws IllegalStateException { String arg = StringUtils.clean(commaDelimited); if (arg == null) { String msg = "One or more comma-delimited jndi names must be specified for the " + getClass().getName() + " to locate Realms."; throw new IllegalStateException(msg); } String[] names = StringUtils.tokenizeToStringArray(arg, ","); setJndiNames(Arrays.asList(names)); }
public String readValue(HttpServletRequest request, HttpServletResponse ignored) { String name = getName(); String value = null; javax.servlet.http.Cookie cookie = getCookie(request, name); if (cookie != null) { // Validate that the cookie is used at the correct place. String path = StringUtils.clean(getPath()); if (path != null && !pathMatches(path, request.getRequestURI())) { log.warn("Found '{}' cookie at path '{}', but should be only used for '{}'", new Object[] { name, request.getRequestURI(), path}); } else { value = cookie.getValue(); log.debug("Found '{}' cookie value [{}]", name, value); } } else { log.trace("No '{}' cookie value", name); } return value; }
String line = clean(aLine); if (line == null) { return null;
String line = StringUtils.clean(rawLine);
remaining = propertyPath.substring(mapEnd+1); if (remaining.startsWith(".")) { remaining = StringUtils.clean(remaining.substring(1));
/** * Specifies a comma-delimited list of JNDI names to lookup, each one corresponding to a jndi-bound * {@link Realm Realm}. The Realms will be made available to the SecurityManager in the order * they are defined. * * @param commaDelimited a comma-delimited list of JNDI names, each representing the JNDI name used to * look up a corresponding jndi-bound Realm. * @throws IllegalStateException if the specified argument is null or the empty string. */ public void setJndiNames(String commaDelimited) throws IllegalStateException { String arg = StringUtils.clean(commaDelimited); if (arg == null) { String msg = "One or more comma-delimited jndi names must be specified for the " + getClass().getName() + " to locate Realms."; throw new IllegalStateException(msg); } String[] names = StringUtils.tokenizeToStringArray(arg, ","); setJndiNames(Arrays.asList(names)); }
protected void setParts(String wildcardString, boolean caseSensitive) { wildcardString = StringUtils.clean(wildcardString); if (wildcardString == null || wildcardString.isEmpty()) { throw new IllegalArgumentException("Wildcard string cannot be null or empty. Make sure permission strings are properly formatted."); } if (!caseSensitive) { wildcardString = wildcardString.toLowerCase(); } List<String> parts = CollectionUtils.asList(wildcardString.split(PART_DIVIDER_TOKEN)); this.parts = new ArrayList<Set<String>>(); for (String part : parts) { Set<String> subparts = CollectionUtils.asSet(part.split(SUBPART_DIVIDER_TOKEN)); if (subparts.isEmpty()) { throw new IllegalArgumentException("Wildcard string cannot contain parts with only dividers. Make sure permission strings are properly formatted."); } this.parts.add(subparts); } if (this.parts.isEmpty()) { throw new IllegalArgumentException("Wildcard string cannot contain only dividers. Make sure permission strings are properly formatted."); } }