1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| public class Shield {
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory
.getLogger(Shield.class);
public Shield(String evaluation) {
this();
setEvaluation(evaluation);
}
public Shield() {
}
private String evaluation;
/**
* @return the evaluation
*/
public String getEvaluation() {
return evaluation;
}
/**
* @param evaluation
* the evaluation to set
*/
public void setEvaluation(String evaluation) {
this.evaluation = evaluation;
}
/**
* check a {@link Stresser} for correctness
*
* @param s
* the {@link Stresser} to check
* @return true if the {@link Stresser} passes the correctness test.
*/
public boolean check(Stresser s) {
if (evaluation == null || evaluation.length() == 0) {
return true;
}
Binding bind = new Binding();
/** RO proxy, to prevent groovy modification */
bind.setVariable("s", new ROStresser(s));
try {
return (Boolean) new GroovyShell(bind).evaluate(getEvaluation());
} catch (Exception e) {
logger.warn("while shielding " + s + " against " + this, e);
return false;
}
}
@Override
public String toString() {
return "[" + getEvaluation() + "]";
}
} |
Partager