-
-
Notifications
You must be signed in to change notification settings - Fork 88
[plugin-web-app] Move credentials from user info to http context in page steps #4161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[plugin-web-app] Move credentials from user info to http context in page steps #4161
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4161 +/- ##
============================================
+ Coverage 88.79% 97.19% +8.40%
+ Complexity 6672 6449 -223
============================================
Files 899 899
Lines 18555 18570 +15
Branches 1220 1223 +3
============================================
+ Hits 16475 18050 +1575
+ Misses 1951 411 -1540
+ Partials 129 109 -20
... and 74 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
URI uriToRequest = pageUrl; | ||
if (uriToRequest.getUserInfo() != null) | ||
{ | ||
uriToRequest = moveUserInfoCredentialsToHttpContext(uriToRequest, context); | ||
} | ||
httpClient.doHttpHead(uriToRequest, context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URI uriToRequest = pageUrl; | |
if (uriToRequest.getUserInfo() != null) | |
{ | |
uriToRequest = moveUserInfoCredentialsToHttpContext(uriToRequest, context); | |
} | |
httpClient.doHttpHead(uriToRequest, context); | |
URI pageUriToCheck = pageUrl; | |
UserInfo userInfo = UriUtils.getUserInfo(pageUriToCheck); | |
if (userInfo != null) | |
{ | |
addBasicAuthToContext(userInfo, context); | |
pageUriToCheck = UriUtils.removeUserInfo(pageUriToCheck); | |
} | |
httpClient.doHttpHead(pageUriToCheck, context); |
private URI moveUserInfoCredentialsToHttpContext(URI pageUrl, HttpClientContext httpContext) | ||
{ | ||
UserInfo userInfo = UriUtils.getUserInfo(pageUrl); | ||
Credentials credentials = new UsernamePasswordCredentials(userInfo.getUser(), | ||
userInfo.getPassword().toCharArray()); | ||
BasicScheme scheme = new BasicScheme(); | ||
scheme.initPreemptive(credentials); | ||
AuthCache authCache = new BasicAuthCache(); | ||
HttpHost host = HttpHost.create(pageUrl); | ||
authCache.put(host, scheme); | ||
httpContext.setAuthCache(authCache); | ||
return UriUtils.removeUserInfo(pageUrl); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private URI moveUserInfoCredentialsToHttpContext(URI pageUrl, HttpClientContext httpContext) | |
{ | |
UserInfo userInfo = UriUtils.getUserInfo(pageUrl); | |
Credentials credentials = new UsernamePasswordCredentials(userInfo.getUser(), | |
userInfo.getPassword().toCharArray()); | |
BasicScheme scheme = new BasicScheme(); | |
scheme.initPreemptive(credentials); | |
AuthCache authCache = new BasicAuthCache(); | |
HttpHost host = HttpHost.create(pageUrl); | |
authCache.put(host, scheme); | |
httpContext.setAuthCache(authCache); | |
return UriUtils.removeUserInfo(pageUrl); | |
} | |
private void addBasicAuthToContext(UserInfo userInfo, HttpClientContext httpContext) | |
{ | |
Credentials credentials = new UsernamePasswordCredentials(userInfo.getUser(), | |
userInfo.getPassword().toCharArray()); | |
BasicScheme scheme = new BasicScheme(); | |
scheme.initPreemptive(credentials); | |
AuthCache authCache = new BasicAuthCache(); | |
HttpHost host = HttpHost.create(pageUrl); | |
authCache.put(host, scheme); | |
httpContext.setAuthCache(authCache); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also does it make sense to use org.apache.hc.client5.http.ContextBuilder#preemptiveBasicAuth
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also does it make sense to use
org.apache.hc.client5.http.ContextBuilder#preemptiveBasicAuth
?
Yep, this way looks pretty easier.
899ff3b
to
169a5a8
Compare
169a5a8
to
f07974b
Compare
Fixes #4134