use of org.zaproxy.zap.extension.script.ScriptWrapper in project zaproxy by zaproxy.
the class ScriptBasedAuthenticationMethodType method loadMethod.
public void loadMethod(ScriptBasedAuthenticationMethod method, List<String> scripts, List<String> paramValuesS) {
// Load the script and make sure it still exists and still follows the required interface
String scriptName = "";
if (scripts != null && scripts.size() > 0) {
scriptName = scripts.get(0);
ScriptWrapper script = getScriptsExtension().getScript(scriptName);
if (script == null) {
log.error("Unable to find script while loading Script Based Authentication Method for name: " + scriptName);
if (View.isInitialised()) {
View.getSingleton().showMessageDialog(Constant.messages.getString("authentication.method.script.load.errorScriptNotFound", scriptName));
}
return;
}
log.info("Loaded script:" + script.getName());
method.script = script;
// Check script interface and make sure we load the credentials parameter names
AuthenticationScript s = getScriptInterfaceV2(script);
if (s == null) {
s = getScriptInterface(script);
}
if (s == null) {
log.error("Unable to load Script Based Authentication method. The script " + scriptName + " does not properly implement the Authentication Script interface.");
return;
}
try {
if (s instanceof AuthenticationScriptV2) {
AuthenticationScriptV2 sV2 = (AuthenticationScriptV2) s;
method.setLoggedInIndicatorPattern(sV2.getLoggedInIndicator());
method.setLoggedOutIndicatorPattern(sV2.getLoggedOutIndicator());
}
method.credentialsParamNames = s.getCredentialsParamsNames();
} catch (Exception e) {
getScriptsExtension().handleScriptException(script, e);
}
}
// Load the parameter values
Map<String, String> paramValues = null;
if (paramValuesS != null && paramValuesS.size() > 0) {
paramValues = EncodingUtils.stringToMap(paramValuesS.get(0));
method.paramValues = paramValues;
} else {
method.paramValues = new HashMap<String, String>();
log.error("Unable to load script parameter values loading Script Based Authentication Method for name: " + scriptName);
}
}
Aggregations