
br.com.softplan.security.zap.api.SessionManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zap-client-api Show documentation
Show all versions of zap-client-api Show documentation
Java client API for the OWASP Zed Attack Proxy (ZAP), built on top of the official ZAP Java API
package br.com.softplan.security.zap.api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import br.com.softplan.security.zap.api.exception.ZapClientException;
import br.com.softplan.security.zap.zaproxy.clientapi.core.ApiResponse;
import br.com.softplan.security.zap.zaproxy.clientapi.core.ClientApi;
import br.com.softplan.security.zap.zaproxy.clientapi.core.ClientApiException;
/**
* Class to manage ZAP sessions.
*
* @author pdsec
*/
public class SessionManager {
private static final Logger LOGGER = LoggerFactory.getLogger(SessionManager.class);
private static final String SESSION_PREFIX = "zap-session-";
private int sessionId;
public void createNewSession(ClientApi api, String apiKey) {
createNewSession(api, apiKey, true);
}
public void createNewSession(ClientApi api, String apiKey, boolean overwrite) {
LOGGER.debug("Creating a new ZAP session.");
try {
ApiResponse response = api.core.newSession(apiKey, SESSION_PREFIX + sessionId++, Boolean.toString(overwrite));
ZapHelper.validateResponse(response, "Create a new ZAP session.");
} catch (ClientApiException e) {
LOGGER.error("Error creating a new ZAP session.", e);
throw new ZapClientException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy