-
-
Notifications
You must be signed in to change notification settings - Fork 88
[selenium-crawler] Fix sitemap transformer to work with basic auth #4658
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
[selenium-crawler] Fix sitemap transformer to work with basic auth #4658
Conversation
e359af7
to
fa3cbe0
Compare
fa3cbe0
to
9581295
Compare
HttpClientContext context = new HttpClientContext(); | ||
HttpResponse response = httpClient.doHttpGet(siteMapUrl, context); | ||
HttpGet request = new HttpGet(siteMapUrl); | ||
URIAuthority currentAuthority = request.getAuthority(); | ||
String authorityUserInfo = currentAuthority.getUserInfo(); | ||
if (authorityUserInfo != null) | ||
{ | ||
URIAuthority newAuthority = new URIAuthority(null, currentAuthority.getHostName(), | ||
currentAuthority.getPort()); | ||
request.setAuthority(newAuthority); | ||
|
||
UriUtils.UserInfo userInfo = UriUtils.parseUserInfo(URLDecoder.decode(authorityUserInfo, | ||
StandardCharsets.UTF_8)); | ||
Credentials credentials = new UsernamePasswordCredentials(userInfo.user(), | ||
userInfo.password().toCharArray()); | ||
BasicScheme scheme = new BasicScheme(); | ||
scheme.initPreemptive(credentials); | ||
AuthCache authCache = new BasicAuthCache(); | ||
try | ||
{ | ||
HttpHost host = HttpHost.create(request.getUri()); | ||
authCache.put(host, scheme); | ||
} | ||
catch (URISyntaxException e) | ||
{ | ||
throw new IllegalArgumentException(e); | ||
} | ||
context.setAuthCache(authCache); | ||
} | ||
HttpResponse response = httpClient.execute(request, context); | ||
URI cleanSiteMapUrl = UriUtils.removeUserInfo(getBaseUri(context, siteMapUrl)); |
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.
ContextBuilder contextBuilder = ContextBuilder.create();
UserInfo userInfo = UriUtils.getUserInfo(siteMapUrl);
URI targetSiteMapUrl;
if (userInfo != null)
{
targetSiteMapUrl = UriUtils.removeUserInfo(siteMapUrl);
contextBuilder.preemptiveBasicAuth(
HttpHost.create(targetSiteMapUrl),
new UsernamePasswordCredentials(userInfo.user(), userInfo.password().toCharArray())
);
}
else
{
targetSiteMapUrl = siteMapUrl;
}
HttpClientContext context = contextBuilder.build();
HttpResponse response = httpClient.doHttpGet(targetSiteMapUrl, context);
URI cleanSiteMapUrl = getBaseUri(context, targetSiteMapUrl);
Credentials credentials = new UsernamePasswordCredentials(userInfo.user(), | ||
userInfo.password().toCharArray()); | ||
BasicScheme scheme = new BasicScheme(); | ||
scheme.initPreemptive(credentials); |
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.
Do you really need preemptive basic auth?
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.
changed to CredentialsProvider
9581295
to
7c0171d
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4658 +/- ##
=========================================
Coverage 97.39% 97.39%
- Complexity 6775 6783 +8
=========================================
Files 914 915 +1
Lines 18818 18843 +25
Branches 1252 1254 +2
=========================================
+ Hits 18327 18352 +25
Misses 384 384
Partials 107 107 ☔ View full report in Codecov by Sentry. |
7c0171d
to
c52bac7
Compare
No description provided.