Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
108 additions
and
133 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
api/src/main/java/org/asynchttpclient/netty/request/NettyRequestFactoryBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,98 @@ | |||
/* | |||
* Copyright (c) 2015 AsyncHttpClient Project. All rights reserved. | |||
* | |||
* This program is licensed to you under the Apache License Version 2.0, | |||
* and you may not use this file except in compliance with the Apache License Version 2.0. | |||
* You may obtain a copy of the Apache License Version 2.0 at | |||
* http://www.apache.org/licenses/LICENSE-2.0. | |||
* | |||
* Unless required by applicable law or agreed to in writing, | |||
* software distributed under the Apache License Version 2.0 is distributed on an | |||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | |||
*/ | |||
package org.asynchttpclient.netty.request; | |||
|
|||
import static org.asynchttpclient.util.AuthenticatorUtils.computeBasicAuthentication; | |||
import static org.asynchttpclient.util.AuthenticatorUtils.computeDigestAuthentication; | |||
import static org.asynchttpclient.util.MiscUtils.isNonEmpty; | |||
|
|||
import java.io.IOException; | |||
|
|||
import org.asynchttpclient.AsyncHttpClientConfig; | |||
import org.asynchttpclient.Realm; | |||
import org.asynchttpclient.Request; | |||
import org.asynchttpclient.ntlm.NtlmEngine; | |||
import org.asynchttpclient.proxy.ProxyServer; | |||
import org.asynchttpclient.spnego.SpnegoEngine; | |||
import org.asynchttpclient.uri.Uri; | |||
|
|||
public abstract class NettyRequestFactoryBase { | |||
|
|||
protected final AsyncHttpClientConfig config; | |||
|
|||
public NettyRequestFactoryBase(AsyncHttpClientConfig config) { | |||
this.config = config; | |||
} | |||
|
|||
protected String firstRequestOnlyAuthorizationHeader(Request request, Uri uri, ProxyServer proxyServer, Realm realm) throws IOException { | |||
String authorizationHeader = null; | |||
|
|||
if (realm != null && realm.getUsePreemptiveAuth()) { | |||
switch (realm.getScheme()) { | |||
case NTLM: | |||
String msg = NtlmEngine.INSTANCE.generateType1Msg(); | |||
authorizationHeader = "NTLM " + msg; | |||
break; | |||
case KERBEROS: | |||
case SPNEGO: | |||
String host; | |||
if (proxyServer != null) | |||
host = proxyServer.getHost(); | |||
else if (request.getVirtualHost() != null) | |||
host = request.getVirtualHost(); | |||
else | |||
host = uri.getHost(); | |||
|
|||
try { | |||
authorizationHeader = "Negotiate " + SpnegoEngine.instance().generateToken(host); | |||
} catch (Throwable e) { | |||
throw new IOException(e); | |||
} | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
|
|||
return authorizationHeader; | |||
} | |||
|
|||
protected String systematicAuthorizationHeader(Request request, Uri uri, Realm realm) { | |||
|
|||
String authorizationHeader = null; | |||
|
|||
if (realm != null && realm.getUsePreemptiveAuth()) { | |||
|
|||
switch (realm.getScheme()) { | |||
case BASIC: | |||
authorizationHeader = computeBasicAuthentication(realm); | |||
break; | |||
case DIGEST: | |||
if (isNonEmpty(realm.getNonce())) | |||
authorizationHeader = computeDigestAuthentication(realm); | |||
break; | |||
case NTLM: | |||
case KERBEROS: | |||
case SPNEGO: | |||
// NTLM, KERBEROS and SPNEGO are only set on the first request, see firstRequestOnlyAuthorizationHeader | |||
case NONE: | |||
break; | |||
default: | |||
throw new IllegalStateException("Invalid Authentication " + realm); | |||
} | |||
} | |||
|
|||
return authorizationHeader; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters