20
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
* THE SOFTWARE.
23
- *
24
- * This class extends a Waffle class. See https://github.com/dblock/waffle for
25
- * appropriate licenses for Waffle, which are not included here (as I do not
23
+ *
24
+ * This class extends a Waffle class. See https://github.com/dblock/waffle for
25
+ * appropriate licenses for Waffle, which are not included here (as I do not
26
26
* include any source code from Waffle).
27
- *
28
- * Portions of this code are based on the KerberosSSO plugin, also licensed
29
- * under the MIT License. See https://github.com/jenkinsci/kerberos-sso-plugin
27
+ *
28
+ * Portions of this code are based on the KerberosSSO plugin, also licensed
29
+ * under the MIT License. See https://github.com/jenkinsci/kerberos-sso-plugin
30
30
* for license details.
31
31
*/
32
32
@@ -83,7 +83,7 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
83
83
chain .doFilter (request , response );
84
84
return ;
85
85
}
86
-
86
+
87
87
HttpServletRequest httpRequest = (HttpServletRequest )request ;
88
88
String requestUri = httpRequest .getRequestURI ();
89
89
// After Jenkins 1.590:
@@ -93,14 +93,14 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
93
93
chain .doFilter (request , response );
94
94
return ;
95
95
}
96
-
96
+
97
97
if (this .allowLocalhost && httpRequest .getLocalAddr ().equals (httpRequest .getRemoteAddr ())) {
98
98
// User is localhost, and we want to skip authenticating localhost
99
99
LOGGER .log (Level .FINEST , "Bypassing authentication for localhost to {0}" , requestUri );
100
100
chain .doFilter (request , response );
101
101
return ;
102
102
}
103
-
103
+
104
104
if (this .redirectEnabled && !httpRequest .getLocalAddr ().equals (httpRequest .getRemoteAddr ())) {
105
105
// If local and remote addresses are identical, user is localhost and shouldn't be redirected
106
106
try {
@@ -121,7 +121,7 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
121
121
return ;
122
122
}
123
123
}
124
-
124
+
125
125
// A user is "always" authenticated by Jenkins as anonymous when not authenticated in any other way.
126
126
if (SecurityContextHolder .getContext ().getAuthentication () == null
127
127
|| !SecurityContextHolder .getContext ().getAuthentication ().isAuthenticated ()
@@ -135,10 +135,10 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
135
135
LOGGER .log (Level .FINEST , "Bypassing filter - already authenticated: " + requestUri );
136
136
chain .doFilter (request , response ); // just continue down the filter chain
137
137
}
138
-
138
+
139
139
//super.doFilter(request, response, chain); // This will also call the filter chaining
140
140
}
141
-
141
+
142
142
/**
143
143
* Remove the hostname and the query string from a requested URI
144
144
* @param requestURI the requested URI
@@ -150,10 +150,10 @@ static String cleanRequest(String requestURI) {
150
150
// if the request URI has a query string, delete it.
151
151
return requestURI .replaceAll ("^https?://[^/]+/" , "/" ).replaceAll ("\\ ?.*$" , "" );
152
152
}
153
-
153
+
154
154
/**
155
155
* Check a request URI to see if authentication should be attempted
156
- *
156
+ *
157
157
* If a path is unprotected or always readable, don't attempt to authenticate.
158
158
* Attempting to authenticate causes problems with things like the cli and notifyCommit URIs
159
159
* @param jenkins jenkins instance; accessible for testing purposes (for getUnprotectedRootActions())
@@ -169,7 +169,7 @@ static boolean shouldAttemptAuthentication(Jenkins jenkins, ServletRequest reque
169
169
// but we only care about the exceptions to the permissions check.
170
170
// Trying to use jenkins.getTarget() always seemed to test against anonymous or everyone permissions,
171
171
// so the user was never automatically authenticated.
172
-
172
+
173
173
// Code copied from Jenkins.getTarget(); need the rest, but not the permission check.
174
174
String rest = cleanRequest (requestURI ); //Stapler.getCurrentRequest().getRestOfPath() in Jenkins.getTarget()
175
175
@@ -198,14 +198,14 @@ static boolean shouldAttemptAuthentication(Jenkins jenkins, ServletRequest reque
198
198
private static boolean isAgentJnlpPath (String restOfPath , String prefix ) {
199
199
return restOfPath .matches ("(/manage)?/computer/[^/]+/" + prefix + "-agent[.]jnlp" );
200
200
}
201
-
201
+
202
202
private static boolean containsBypassHeader (ServletRequest request ) {
203
203
if (!(request instanceof HttpServletRequest )) {
204
204
return false ;
205
205
}
206
206
return ((HttpServletRequest )request ).getHeader (BYPASS_HEADER ) != null ;
207
207
}
208
-
208
+
209
209
/**
210
210
* @param doEnable if redirect should be enabled
211
211
* @param redirectTo the site to redirect to
@@ -214,7 +214,7 @@ public void setRedirect(boolean doEnable, String redirectTo) {
214
214
this .redirectEnabled = doEnable ;
215
215
this .redirect = redirectTo ;
216
216
}
217
-
217
+
218
218
/**
219
219
* @param allow if localhost should bypass the SSO authentication
220
220
*/
0 commit comments