Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
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 (309)
Collections:
Other Resources:
HttpComponents Core Source Code Files
HttpComponents Core Source Code Files are provided in the source package file, httpcomponents-core-5.2-src.zip.
You can download httpcomponents-core-5.2-src.zip as described in the previous tutorial and go to the "httpcore5/src" sub-folder to view Source Code files.
You can also browse HttpComponents Core Source Code below:
✍: FYIcenter.com
⏎ org/apache/hc/core5/http/nio/support/AbstractAsyncServerAuthFilter.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.core5.http.nio.support; import java.io.IOException; import java.nio.ByteBuffer; import java.util.List; import org.apache.hc.core5.annotation.Contract; import org.apache.hc.core5.annotation.ThreadingBehavior; import org.apache.hc.core5.http.EntityDetails; import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HeaderElements; import org.apache.hc.core5.http.HttpException; import org.apache.hc.core5.http.HttpHeaders; import org.apache.hc.core5.http.HttpRequest; import org.apache.hc.core5.http.HttpResponse; import org.apache.hc.core5.http.HttpStatus; import org.apache.hc.core5.http.message.BasicClassicHttpResponse; import org.apache.hc.core5.http.message.BasicHttpResponse; import org.apache.hc.core5.http.nio.AsyncDataConsumer; import org.apache.hc.core5.http.nio.AsyncEntityProducer; import org.apache.hc.core5.http.nio.AsyncFilterChain; import org.apache.hc.core5.http.nio.AsyncFilterHandler; import org.apache.hc.core5.http.nio.CapacityChannel; import org.apache.hc.core5.http.nio.entity.AsyncEntityProducers; import org.apache.hc.core5.http.protocol.HttpContext; import org.apache.hc.core5.net.URIAuthority; /** * Abstract asynchronous HTTP request filter that implements standard HTTP authentication handshake. * * @param <T> authorization token representation. * * @since 5.0 */ @Contract(threading = ThreadingBehavior.STATELESS) public abstract class AbstractAsyncServerAuthFilter<T> implements AsyncFilterHandler { private final boolean respondImmediately; protected AbstractAsyncServerAuthFilter(final boolean respondImmediately) { this.respondImmediately = respondImmediately; } /** * Parses authorization header value into an authentication token sent by the client * as a response to an authentication challenge. * * @param authorizationValue the authorization header value. * @param context the actual execution context. * @return authorization token */ protected abstract T parseChallengeResponse(String authorizationValue, HttpContext context) throws HttpException; /** * Authenticates the client using the authentication token sent by the client * as a response to an authentication challenge. * * @param challengeResponse the authentication token sent by the client * as a response to an authentication challenge. * @param authority the URI authority. * @param requestUri the request URI. * @param context the actual execution context. * @return {@code true} if the client could be successfully authenticated {@code false} otherwise. */ protected abstract boolean authenticate(T challengeResponse, URIAuthority authority, String requestUri, HttpContext context); /** * Generates an authentication challenge in case of unsuccessful authentication. * * @param challengeResponse the authentication token sent by the client * as a response to an authentication challenge * or {@code null} if the client has not sent any. * @param authority the URI authority. * @param requestUri the request URI. * @param context the actual execution context. * @return an authorization challenge value. */ protected abstract String generateChallenge(T challengeResponse, URIAuthority authority, String requestUri, HttpContext context); /** * Generates response body for UNAUTHORIZED response. * * @param unauthorized the response to return as a result of authentication failure. * @return the response content entity. */ protected AsyncEntityProducer generateResponseContent(final HttpResponse unauthorized) { return AsyncEntityProducers.create("Unauthorized"); } @Override public final AsyncDataConsumer handle( final HttpRequest request, final EntityDetails entityDetails, final HttpContext context, final AsyncFilterChain.ResponseTrigger responseTrigger, final AsyncFilterChain chain) throws HttpException, IOException { final Header h = request.getFirstHeader(HttpHeaders.AUTHORIZATION); final T challengeResponse = h != null ? parseChallengeResponse(h.getValue(), context) : null; final URIAuthority authority = request.getAuthority(); final String requestUri = request.getRequestUri(); final boolean authenticated = authenticate(challengeResponse, authority, requestUri, context); final Header expect = request.getFirstHeader(HttpHeaders.EXPECT); final boolean expectContinue = expect != null && HeaderElements.CONTINUE.equalsIgnoreCase(expect.getValue()); if (authenticated) { if (expectContinue) { responseTrigger.sendInformation(new BasicClassicHttpResponse(HttpStatus.SC_CONTINUE)); } return chain.proceed(request, entityDetails, context, responseTrigger); } final HttpResponse unauthorized = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED); unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, generateChallenge(challengeResponse, authority, requestUri, context)); final AsyncEntityProducer responseContentProducer = generateResponseContent(unauthorized); if (respondImmediately || expectContinue || entityDetails == null) { responseTrigger.submitResponse(unauthorized, responseContentProducer); return null; } return new AsyncDataConsumer() { @Override public void updateCapacity(final CapacityChannel capacityChannel) throws IOException { capacityChannel.update(Integer.MAX_VALUE); } @Override public void consume(final ByteBuffer src) throws IOException { } @Override public void streamEnd(final List<? extends Header> trailers) throws HttpException, IOException { responseTrigger.submitResponse(unauthorized, responseContentProducer); } @Override public void releaseResources() { if (responseContentProducer != null) { responseContentProducer.releaseResources(); } } }; } }
⏎ org/apache/hc/core5/http/nio/support/AbstractAsyncServerAuthFilter.java
Or download all them as a single archive file:
File name: httpcore5-5.2-fyi.zip File size: 812477 bytes Release date: 2022-11-10 Download
⇒ Donwload httpcomponents-client-4.5.3-bin.zip
⇐ Download and Install HttpComponents Core Source Package
2023-03-07, 17665👍, 0💬
Popular Posts:
JDK 11 jdk.jdeps.jmod is the JMOD file for JDK 11 JDeps tool, which can be invoked by the "jdeps" co...
Guava is a suite of core and expanded libraries that include utility classes, google's collections, ...
JDK 11 jdk.rmic.jmod is the JMOD file for JDK 11 RMI (Remote Method Invocation) Compiler Tool tool, ...
ZooKeeper is a centralized service for maintaining configuration information, naming, providing dist...
JRE 8 plugin.jar is the JAR file for JRE 8 Java Control Panel Plugin interface and tools. JRE (Java ...