Search in sources :

Example 6 with ScriptWrapper

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);
    }
}
Also used : ScriptWrapper(org.zaproxy.zap.extension.script.ScriptWrapper) ScriptException(javax.script.ScriptException) ApiException(org.zaproxy.zap.extension.api.ApiException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Aggregations

ScriptWrapper (org.zaproxy.zap.extension.script.ScriptWrapper)6 IOException (java.io.IOException)2 ScriptException (javax.script.ScriptException)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 HttpException (org.apache.commons.httpclient.HttpException)2 DatabaseException (org.parosproxy.paros.db.DatabaseException)2 HttpMessage (org.parosproxy.paros.network.HttpMessage)2 ApiException (org.zaproxy.zap.extension.api.ApiException)2 HashMap (java.util.HashMap)1 JSONObject (net.sf.json.JSONObject)1 RecordContext (org.parosproxy.paros.db.RecordContext)1 ApiDynamicActionImplementor (org.zaproxy.zap.extension.api.ApiDynamicActionImplementor)1 PassiveScript (org.zaproxy.zap.extension.pscan.PassiveScript)1 Context (org.zaproxy.zap.model.Context)1