protected void logCacheSettings(Logger log) { Util.logSetting(log, "caching", accountCache != null); Util.logSetting(log, "cacheTtl (mins)", cacheTtl); Util.logSetting(log, "cacheMax (accounts)", cacheMax); }
public static String toString(Method method) { return toString(method.getDeclaringClass(), method.getName()); }
public DomainPermission(String actions, String targets) { this.domain = getDomain(getClass()); this.actions = Util.splitToSet(actions, SUBPART_DIVIDER_TOKEN); this.targets = Util.splitToSet(targets, SUBPART_DIVIDER_TOKEN); encodeParts(this.domain, actions, targets); }
String contentType = Util.getPreSubstring(context.getRequest().getHeader("Content-Type").toLowerCase(), ';'); if (!guardedTypes.contains(contentType)) { log.debug("Ignoring '{}' request for {} '{}'", contentType, context.getRequestMethod(),
/** * Returns {@code true} if the resource at the specified path exists, {@code false} otherwise. This * method supports scheme prefixes on the path as defined in {@link #getInputStreamForPath(String)}. * * @param resourcePath the path of the resource to check. * @return {@code true} if the resource at the specified path exists, {@code false} otherwise. * @since 0.9 */ public static boolean resourceExists(String resourcePath) { InputStream stream = null; boolean exists = false; try { stream = getInputStreamForPath(resourcePath); exists = true; } catch (IOException e) { stream = null; } finally { if (stream != null) { try { stream.close(); } catch (IOException ignored) { } } } return exists; }
String contentType = Util.getPreSubstring(context.getRequest().getHeader("Content-Type").toLowerCase(), ';'); if (!guardedTypes.contains(contentType)) { log.debug("Ignoring '{}' request for {} '{}'", contentType, context.getRequestMethod(),
protected void logCacheSettings(Logger log) { Util.logSetting(log, "caching", accountCache != null); Util.logSetting(log, "cacheTtl (mins)", cacheTtl); Util.logSetting(log, "cacheMax (accounts)", cacheMax); }
Object invokeMethod(Method method, List<Object> methodParameters) throws Exception { Object[] argValues = null; if (methodParameters != null) { argValues = new Object[methodParameters.size()]; for (int i = 0; i < methodParameters.size(); i++) { argValues[i] = methodParameters.get(i); } } try { method.setAccessible(true); return method.invoke(invokeTarget, argValues); } catch (IllegalAccessException | IllegalArgumentException e) { throw e; } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); log.error("Failed to execute {}", Util.toString(method), t); throw new FathomException(t.getMessage()); } }
public DomainPermission(String actions, String targets) { this.domain = getDomain(getClass()); this.actions = Util.splitToSet(actions, SUBPART_DIVIDER_TOKEN); this.targets = Util.splitToSet(targets, SUBPART_DIVIDER_TOKEN); encodeParts(this.domain, actions, targets); }
@Override public void start() { log.debug("Realm '{}' configuration:", getRealmName()); Util.logSetting(log, "url", ldapUrl); Util.logSetting(log, "username", ldapUsername); Util.logSetting(log, "password", ldapPassword); Util.logSetting(log, "bindPattern", ldapBindPattern); Util.logSetting(log, "accountBase", accountBase); Util.logSetting(log, "accountPattern", accountPattern); Util.logSetting(log, "nameMapping", nameMapping); Util.logSetting(log, "emailMapping", emailMapping); Util.logSetting(log, "groupBase", groupBase); Util.logSetting(log, "groupMemberPattern", groupMemberPattern); Util.logSetting(log, "adminGroups", adminGroups); super.logCacheSettings(log); }
public static Class<?> getParameterGenericType(Method method, Parameter parameter) { Type parameterType = parameter.getParameterizedType(); if (!ParameterizedType.class.isAssignableFrom(parameterType.getClass())) { throw new FathomException("Please specify a generic parameter type for '{}' of '{}'", parameter.getType().getName(), Util.toString(method)); } ParameterizedType parameterizedType = (ParameterizedType) parameterType; try { Class<?> genericClass = (Class<?>) parameterizedType.getActualTypeArguments()[0]; return genericClass; } catch (ClassCastException e) { throw new FathomException("Please specify a generic parameter type for '{}' of '{}'", parameter.getType().getName(), Util.toString(method)); } }
protected void setParts(String wildcardString, boolean caseSensitive) { if (wildcardString == null || wildcardString.trim().length() == 0) { throw new IllegalArgumentException("Wildcard string cannot be null or empty. Make sure permission strings are properly formatted."); } wildcardString = wildcardString.trim(); List<String> parts = Arrays.asList(wildcardString.split(PART_DIVIDER_TOKEN)); this.parts = new ArrayList<>(); for (String part : parts) { Set<String> subparts = Util.splitToSet(part, SUBPART_DIVIDER_TOKEN); if (!caseSensitive) { subparts = lowercase(subparts); } 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."); } }
@Override public void start() { log.debug("Realm '{}' configuration:", getRealmName()); Util.logSetting(log, "url", ldapUrl); Util.logSetting(log, "username", ldapUsername); Util.logSetting(log, "password", ldapPassword); Util.logSetting(log, "bindPattern", ldapBindPattern); Util.logSetting(log, "accountBase", accountBase); Util.logSetting(log, "accountPattern", accountPattern); Util.logSetting(log, "nameMapping", nameMapping); Util.logSetting(log, "emailMapping", emailMapping); Util.logSetting(log, "groupBase", groupBase); Util.logSetting(log, "groupMemberPattern", groupMemberPattern); Util.logSetting(log, "adminGroups", adminGroups); super.logCacheSettings(log); }
/** * Validates that the declared content-types can actually be generated by Fathom. * * @param fathomContentTypes */ protected void validateProduces(Collection<String> fathomContentTypes) { Set<String> ignoreProduces = new TreeSet<>(); ignoreProduces.add(Produces.TEXT); ignoreProduces.add(Produces.HTML); ignoreProduces.add(Produces.XHTML); for (String produces : declaredProduces) { if (ignoreProduces.contains(produces)) { continue; } if (!fathomContentTypes.contains(produces)) { throw new FatalException("{} declares @{}(\"{}\") but there is no registered ContentTypeEngine for that type!", Util.toString(method), Produces.class.getSimpleName(), produces); } } }
protected void setParts(String wildcardString, boolean caseSensitive) { if (wildcardString == null || wildcardString.trim().length() == 0) { throw new IllegalArgumentException("Wildcard string cannot be null or empty. Make sure permission strings are properly formatted."); } wildcardString = wildcardString.trim(); List<String> parts = Arrays.asList(wildcardString.split(PART_DIVIDER_TOKEN)); this.parts = new ArrayList<>(); for (String part : parts) { Set<String> subparts = Util.splitToSet(part, SUBPART_DIVIDER_TOKEN); if (!caseSensitive) { subparts = lowercase(subparts); } 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."); } }
public static void logSetting(Logger log, Enum<?> name, Object value) { logSetting(log, name.toString(), value); }
/** * Validates that the declared content-types can actually be generated by Fathom. * * @param fathomContentTypes */ protected void validateProduces(Collection<String> fathomContentTypes) { Set<String> ignoreProduces = new TreeSet<>(); ignoreProduces.add(Produces.TEXT); ignoreProduces.add(Produces.HTML); ignoreProduces.add(Produces.XHTML); for (String produces : declaredProduces) { if (ignoreProduces.contains(produces)) { continue; } if (!fathomContentTypes.contains(produces)) { throw new FatalException("{} declares @{}(\"{}\") but there is no registered ContentTypeEngine for that type!", Util.toString(method), Produces.class.getSimpleName(), produces); } } }
public DomainPermission(String actions) { domain = getDomain(getClass()); this.actions = Util.splitToSet(actions, SUBPART_DIVIDER_TOKEN); encodeParts(domain, actions, null); }
@Override public void start() { log.debug("Realm '{}' configuration:", getRealmName()); Util.logSetting(log, "file", file); Util.logSetting(log, "allowClearPasswords", isAllowClearTextPasswords); }
Object invokeMethod(Method method, List<Object> methodParameters) throws Exception { Object[] argValues = null; if (methodParameters != null) { argValues = new Object[methodParameters.size()]; for (int i = 0; i < methodParameters.size(); i++) { argValues[i] = methodParameters.get(i); } } try { method.setAccessible(true); return method.invoke(invokeTarget, argValues); } catch (IllegalAccessException | IllegalArgumentException e) { throw e; } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); log.error("Failed to execute {}", Util.toString(method), t); throw new FathomException(t.getMessage()); } }