com.mitchellbosecke.pebble.attributes.methodaccess.BlacklistMethodAccessValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pebble Show documentation
Show all versions of pebble Show documentation
Templating engine for Java.
package com.mitchellbosecke.pebble.attributes.methodaccess;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Method;
public class BlacklistMethodAccessValidator implements MethodAccessValidator {
private static final String[] FORBIDDEN_METHODS = {"getClass",
"wait",
"notify",
"notifyAll"};
@Override
public boolean isMethodAccessAllowed(Object object, Method method) {
boolean methodForbidden = object instanceof Class
|| object instanceof Runtime
|| object instanceof Thread
|| object instanceof ThreadGroup
|| object instanceof System
|| object instanceof AccessibleObject
|| this.isUnsafeMethod(method);
return !methodForbidden;
}
private boolean isUnsafeMethod(Method member) {
return this.isAnyOfMethods(member, FORBIDDEN_METHODS);
}
private boolean isAnyOfMethods(Method member, String... methods) {
for (String method : methods) {
if (this.isMethodWithName(member, method)) {
return true;
}
}
return false;
}
private boolean isMethodWithName(Method member, String method) {
return member.getName().equals(method);
}
}