Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
HttpComponents Client Source Code Files
HttpComponents Client Source Code Files are provided in the
source package file, httpcomponents-client-5.2-src.zip.
You can download httpcomponents-client-5.2-src.zip as described in the previous tutorial and go to the "httpclient5/src" sub-folder to view Source Code files.
You can also browse HttpComponents Client Source Code below:
✍: FYIcenter.com
⏎ org/apache/hc/client5/http/impl/cookie/PublicSuffixDomainFilter.java
/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.hc.client5.http.impl.cookie;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.hc.client5.http.cookie.CommonCookieAttributeHandler;
import org.apache.hc.client5.http.cookie.Cookie;
import org.apache.hc.client5.http.cookie.CookieOrigin;
import org.apache.hc.client5.http.cookie.MalformedCookieException;
import org.apache.hc.client5.http.cookie.SetCookie;
import org.apache.hc.client5.http.psl.PublicSuffixList;
import org.apache.hc.client5.http.psl.PublicSuffixMatcher;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.util.Args;
/**
* Wraps a {@link org.apache.hc.client5.http.cookie.CookieAttributeHandler} and leverages
* its match method to never match a suffix from a black list. May be used to provide
* additional security for cross-site attack types by preventing cookies from apparent
* domains that are not publicly available.
*
* @see PublicSuffixList
* @see PublicSuffixMatcher
*
* @since 4.4
*/
@Contract(threading = ThreadingBehavior.STATELESS)
public class PublicSuffixDomainFilter implements CommonCookieAttributeHandler {
private final CommonCookieAttributeHandler handler;
private final PublicSuffixMatcher publicSuffixMatcher;
private final Map<String, Boolean> localDomainMap;
private static Map<String, Boolean> createLocalDomainMap() {
final ConcurrentHashMap<String, Boolean> map = new ConcurrentHashMap<>();
map.put(".localhost.", Boolean.TRUE); // RFC 6761
map.put(".test.", Boolean.TRUE); // RFC 6761
map.put(".local.", Boolean.TRUE); // RFC 6762
map.put(".local", Boolean.TRUE);
map.put(".localdomain", Boolean.TRUE);
return map;
}
public PublicSuffixDomainFilter(
final CommonCookieAttributeHandler handler, final PublicSuffixMatcher publicSuffixMatcher) {
this.handler = Args.notNull(handler, "Cookie handler");
this.publicSuffixMatcher = Args.notNull(publicSuffixMatcher, "Public suffix matcher");
this.localDomainMap = createLocalDomainMap();
}
public PublicSuffixDomainFilter(
final CommonCookieAttributeHandler handler, final PublicSuffixList suffixList) {
Args.notNull(handler, "Cookie handler");
Args.notNull(suffixList, "Public suffix list");
this.handler = handler;
this.publicSuffixMatcher = new PublicSuffixMatcher(suffixList.getRules(), suffixList.getExceptions());
this.localDomainMap = createLocalDomainMap();
}
/**
* Never matches if the cookie's domain is from the blacklist.
*/
@Override
public boolean match(final Cookie cookie, final CookieOrigin origin) {
final String host = cookie.getDomain();
if (host == null) {
return false;
}
final int i = host.indexOf('.');
if (i >= 0) {
final String domain = host.substring(i);
if (!this.localDomainMap.containsKey(domain)) {
if (this.publicSuffixMatcher.matches(host)) {
return false;
}
}
} else {
if (!host.equalsIgnoreCase(origin.getHost())) {
if (this.publicSuffixMatcher.matches(host)) {
return false;
}
}
}
return handler.match(cookie, origin);
}
@Override
public void parse(final SetCookie cookie, final String value) throws MalformedCookieException {
handler.parse(cookie, value);
}
@Override
public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException {
handler.validate(cookie, origin);
}
@Override
public String getAttributeName() {
return handler.getAttributeName();
}
public static CommonCookieAttributeHandler decorate(
final CommonCookieAttributeHandler handler, final PublicSuffixMatcher publicSuffixMatcher) {
Args.notNull(handler, "Cookie attribute handler");
return publicSuffixMatcher != null ? new PublicSuffixDomainFilter(handler, publicSuffixMatcher) : handler;
}
}
⏎ org/apache/hc/client5/http/impl/cookie/PublicSuffixDomainFilter.java
Or download all them as a single archive file:
File name: httpclient5-5.2-fyi.zip File size: 625318 bytes Release date: 2022-11-10 Download
⇒ Download and Install HttpComponents Core Binary Package
⇐ Download and Install HttpComponents Client Source Package
2023-03-26, ≈76🔥, 1💬
Popular Posts:
JDK 11 jdk.crypto.mscapi.jmod is the JMOD file for JDK 11 Crypto MSCAPI module. JDK 11 Crypto MSCAPI...
What Is poi-scratchpad-3.5.jar? poi-scratchpad-3.5.jar is one of the JAR files for Apache POI 3.5, w...
Smack is an Open Source XMPP (Jabber) client library for instant messaging and presence. A pure Java...
Apache Commons CLI Source Code Files are provided in the source package file commons-cli-1.5.0-sourc. ..
What Is poi-ooxml-3.5.jar? poi-ooxml-3.5.jar is one of the JAR files for Apache POI 3.5, which provi...