@@ -68,6 +68,9 @@ public class ZestAuthenticationRunner extends ZestZapRunner implements Authentic
6868 private ZestScriptWrapper script = null ;
6969 private AuthenticationHelper helper ;
7070
71+ private boolean autoCloseProxy ;
72+ private Server proxyServer ;
73+
7174 public ZestAuthenticationRunner (
7275 ExtensionZest extension , ExtensionNetwork extensionNetwork , ZestScriptWrapper script ) {
7376 super (extension , extensionNetwork , script );
@@ -76,6 +79,7 @@ public ZestAuthenticationRunner(
7679 script .getZestScript ().getParameters ().getTokenStart ()
7780 + TOTP_VAR_NAME
7881 + script .getZestScript ().getParameters ().getTokenEnd ();
82+ autoCloseProxy = true ;
7983 }
8084
8185 @ Override
@@ -127,10 +131,9 @@ public HttpMessage authenticate(
127131 Map <String , String > paramsValues ,
128132 GenericAuthenticationCredentials credentials )
129133 throws ScriptException {
130-
134+ closeProxy ();
131135 this .helper = helper ;
132136
133- Server proxyServer = null ;
134137 try {
135138 if (hasClientStatements ()) {
136139 proxyServer =
@@ -174,13 +177,41 @@ public HttpMessage authenticate(
174177 } catch (Exception e ) {
175178 throw new ScriptException (e );
176179 } finally {
177- if (proxyServer != null ) {
178- try {
179- proxyServer .close ();
180- } catch (IOException e ) {
181- LOGGER .debug ("An error occurred while stopping the proxy." , e );
182- }
180+ if (autoCloseProxy ) {
181+ closeProxy ();
182+ }
183+ }
184+ }
185+
186+ /**
187+ * Sets whether or not the proxy created for the authentication should be automatically closed
188+ * after the authentication, true by default.
189+ *
190+ * <p>Allows to use the browser after the authentication has finished, callers should close the
191+ * proxy once no longer needed.
192+ *
193+ * @param autoCloseProxy {@code true} to auto close the proxy, {@code false} otherwise.
194+ * @since 48.9.0
195+ * @see #closeProxy()
196+ */
197+ public void setAutoCloseProxy (boolean autoCloseProxy ) {
198+ this .autoCloseProxy = autoCloseProxy ;
199+ }
200+
201+ /**
202+ * Closes the proxy.
203+ *
204+ * @since 48.9.0
205+ * @see #setAutoCloseProxy(boolean)
206+ */
207+ public void closeProxy () {
208+ if (proxyServer != null ) {
209+ try {
210+ proxyServer .close ();
211+ } catch (IOException e ) {
212+ LOGGER .debug ("An error occurred while stopping the proxy." , e );
183213 }
214+ proxyServer = null ;
184215 }
185216 }
186217
0 commit comments