1212import java .util .ArrayList ;
1313import java .util .List ;
1414import jenkins .model .IdStrategy ;
15+ import org .jenkinsci .plugins .oic .properties .DisableNonce ;
1516import org .jenkinsci .plugins .oic .properties .DisableTokenVerification ;
17+ import org .jenkinsci .plugins .oic .properties .EscapeHatch ;
1618import org .jenkinsci .plugins .oic .properties .LoginQueryParameters ;
1719import org .jenkinsci .plugins .oic .properties .LogoutQueryParameters ;
1820import org .kohsuke .stapler .StaplerRequest2 ;
@@ -54,10 +56,6 @@ public static class Builder {
5456 public Boolean logoutFromOpenidProvider = false ;
5557 public String endSessionEndpoint = null ;
5658 public String postLogoutRedirectUrl = null ;
57- public boolean escapeHatchEnabled = false ;
58- public String escapeHatchUsername = null ;
59- public Secret escapeHatchSecret = null ;
60- public String escapeHatchGroup = null ;
6159 public boolean automanualconfigure = false ;
6260 public IdStrategy userIdStrategy ;
6361 public IdStrategy groupIdStrategy ;
@@ -151,11 +149,14 @@ public Builder WithEscapeHatch(
151149 boolean escapeHatchEnabled ,
152150 String escapeHatchUsername ,
153151 String escapeHatchSecret ,
154- String escapeHatchGroup ) {
155- this .escapeHatchEnabled = escapeHatchEnabled ;
156- this .escapeHatchUsername = escapeHatchUsername ;
157- this .escapeHatchSecret = escapeHatchSecret == null ? null : Secret .fromString (escapeHatchSecret );
158- this .escapeHatchGroup = escapeHatchGroup ;
152+ String escapeHatchGroup )
153+ throws Descriptor .FormException {
154+ if (escapeHatchEnabled ) {
155+ this .properties .add (
156+ new EscapeHatch (escapeHatchUsername , escapeHatchGroup , Secret .fromString (escapeHatchSecret )));
157+ } else {
158+ this .properties .removeIf (EscapeHatch .class ::isInstance );
159+ }
159160 return this ;
160161 }
161162
@@ -234,10 +235,6 @@ public TestRealm(Builder builder) throws Exception {
234235 this .setGroupsFieldName (builder .groupsFieldName );
235236 this .setLogoutFromOpenidProvider (builder .logoutFromOpenidProvider );
236237 this .setPostLogoutRedirectUrl (builder .postLogoutRedirectUrl );
237- this .setEscapeHatchEnabled (builder .escapeHatchEnabled );
238- this .setEscapeHatchUsername (builder .escapeHatchUsername );
239- this .setEscapeHatchSecret (builder .escapeHatchSecret );
240- this .setEscapeHatchGroup (builder .escapeHatchGroup );
241238 this .setProperties (builder .properties );
242239 // need to call the following method annotated with @PostConstruct and called
243240 // from readResolve and as such
@@ -307,7 +304,8 @@ public void doFinishLogin(StaplerRequest2 request, StaplerResponse2 response) th
307304 /*
308305 * PluginTest uses a hardCoded nonce "nonce"
309306 */
310- if (!isNonceDisabled ()) {
307+
308+ if (getProperties ().get (DisableNonce .class ) == null ) {
311309 // only hack the nonce if the nonce is enabled
312310 FrameworkParameters parameters = new JEEFrameworkParameters (request , response );
313311 WebContext webContext = JEEContextFactory .INSTANCE .newContext (parameters );
@@ -331,8 +329,4 @@ public String getStringFieldFromJMESPath(Object object, String jmespathField) {
331329 public Object readResolve () throws ObjectStreamException {
332330 return super .readResolve ();
333331 }
334-
335- public boolean doCheckEscapeHatch (String username , String password ) {
336- return super .checkEscapeHatch (username , password );
337- }
338332}
0 commit comments