@@ -168,7 +168,6 @@ public class GrizzlyAsyncHttpProvider implements AsyncHttpProvider {
168
168
169
169
private final static NTLMEngine ntlmEngine = new NTLMEngine ();
170
170
171
-
172
171
// ------------------------------------------------------------ Constructors
173
172
174
173
@@ -916,12 +915,16 @@ private boolean sendAsGrizzlyRequest(final Request request,
916
915
requestPacket .setHeader (Header .ProxyConnection , "keep-alive" );
917
916
}
918
917
919
- if (proxy .getNtlmDomain () != null && proxy .getNtlmDomain ().length () > 0 )
918
+ if (null == requestPacket .getHeader (Header .ProxyAuthorization ) )
919
+ {
920
+ requestPacket .setHeader (Header .ProxyAuthorization , AuthenticatorUtils .computeBasicAuthentication (proxy ));
921
+ }
922
+ /*if(proxy.getNtlmDomain() != null && proxy.getNtlmDomain().length() > 0)
920
923
{
921
924
LOGGER.debug("probably ntlm.. not adding header..");
922
925
}else if (proxy.getPrincipal() != null && proxy.isBasic()) {
923
926
requestPacket.setHeader(Header.ProxyAuthorization, AuthenticatorUtils.computeBasicAuthentication(proxy));
924
- }
927
+ }*/
925
928
926
929
}
927
930
}
@@ -1393,7 +1396,7 @@ protected boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext c
1393
1396
final String proxy_auth = httpHeader .getHeader (Header .ProxyAuthenticate );
1394
1397
1395
1398
if (httpHeader .isSkipRemainder () ) {
1396
- if (!ProxyAuthorizationHandler .isSecondHandShake (proxy_auth ))
1399
+ if (!ProxyAuthorizationHandler .isNTLMSecondHandShake (proxy_auth ))
1397
1400
{
1398
1401
clearResponse (ctx .getConnection ());
1399
1402
cleanup (ctx , provider );
@@ -1653,7 +1656,7 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
1653
1656
String msg = null ;
1654
1657
try {
1655
1658
1656
- if (isFirstHandShake (proxy_auth ))
1659
+ if (isNTLMFirstHandShake (proxy_auth ))
1657
1660
{
1658
1661
msg = ntlmEngine .generateType1Msg (proxyServer .getNtlmDomain (), "" );
1659
1662
}else {
@@ -1665,21 +1668,46 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
1665
1668
} catch (Exception e1 ) {
1666
1669
e1 .printStackTrace ();
1667
1670
}
1668
- } else {
1671
+ } else if (proxy_auth .toLowerCase ().startsWith ("negotiate" )){
1672
+ //this is for kerberos
1673
+ req .getHeaders ().remove (Header .ProxyAuthenticate .toString ());
1674
+ req .getHeaders ().remove (Header .ProxyAuthorization .toString ());
1675
+
1676
+ }else {
1669
1677
throw new IllegalStateException ("Unsupported authorization method: " + proxy_auth );
1670
1678
}
1671
1679
1672
1680
final ConnectionManager m = httpTransactionContext .provider .connectionManager ;
1673
1681
InvocationStatus tempInvocationStatus = InvocationStatus .STOP ;
1674
1682
1675
1683
try {
1676
- if (isFirstHandShake (proxy_auth ))
1684
+
1685
+ if (isNTLMFirstHandShake (proxy_auth ))
1677
1686
{
1678
1687
tempInvocationStatus = InvocationStatus .CONTINUE ;
1679
1688
1680
1689
}
1681
1690
1682
- if (isSecondHandShake (proxy_auth ))
1691
+ if (proxy_auth .toLowerCase ().startsWith ("negotiate" ))
1692
+ {
1693
+ final Connection c = m .obtainConnection (req , httpTransactionContext .future );
1694
+ final HttpTransactionContext newContext = httpTransactionContext .copy ();
1695
+ httpTransactionContext .future = null ;
1696
+ httpTransactionContext .provider .setHttpTransactionContext (c , newContext );
1697
+
1698
+ newContext .invocationStatus = tempInvocationStatus ;
1699
+
1700
+ String challengeHeader = null ;
1701
+ String server = proxyServer .getHost ();
1702
+
1703
+ challengeHeader = GSSSPNEGOWrapper .generateToken (server );
1704
+
1705
+ req .getHeaders ().add (Header .ProxyAuthorization .toString (), "Negotiate " + challengeHeader );
1706
+
1707
+
1708
+ return exceuteRequest (httpTransactionContext , req , c ,
1709
+ newContext );
1710
+ }else if (isNTLMSecondHandShake (proxy_auth ))
1683
1711
{
1684
1712
final Connection c = ctx .getConnection ();
1685
1713
final HttpTransactionContext newContext = httpTransactionContext .copy (); //httpTransactionContext.copy();
@@ -1690,17 +1718,8 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
1690
1718
newContext .invocationStatus = tempInvocationStatus ;
1691
1719
httpTransactionContext .establishingTunnel = true ;
1692
1720
1693
- try {
1694
- httpTransactionContext .provider .execute (c ,
1695
- req ,
1696
- httpTransactionContext .handler ,
1697
- httpTransactionContext .future );
1698
- return false ;
1699
- } catch (IOException ioe ) {
1700
- ioe .printStackTrace ();
1701
- newContext .abort (ioe );
1702
- return false ;
1703
- }
1721
+ return exceuteRequest (httpTransactionContext , req , c ,
1722
+ newContext );
1704
1723
1705
1724
}
1706
1725
else {
@@ -1711,28 +1730,39 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
1711
1730
1712
1731
newContext .invocationStatus = tempInvocationStatus ;
1713
1732
1714
- try {
1715
- httpTransactionContext .provider .execute (c ,
1716
- req ,
1717
- httpTransactionContext .handler ,
1718
- httpTransactionContext .future );
1719
- return false ;
1720
- } catch (IOException ioe ) {
1721
- newContext .abort (ioe );
1722
- return false ;
1723
- }
1733
+ return exceuteRequest (httpTransactionContext , req , c ,
1734
+ newContext );
1724
1735
}
1725
1736
} catch (Exception e ) {
1726
1737
httpTransactionContext .abort (e );
1727
- }
1738
+ } catch (Throwable e ) {
1739
+ e .printStackTrace ();
1740
+ httpTransactionContext .abort (e );
1741
+ }
1728
1742
httpTransactionContext .invocationStatus = tempInvocationStatus ;
1729
1743
return false ;
1730
1744
}
1731
1745
1732
- public static boolean isSecondHandShake (final String proxy_auth ) {
1746
+ private boolean exceuteRequest (
1747
+ final HttpTransactionContext httpTransactionContext ,
1748
+ final Request req , final Connection c ,
1749
+ final HttpTransactionContext newContext ) {
1750
+ try {
1751
+ httpTransactionContext .provider .execute (c ,
1752
+ req ,
1753
+ httpTransactionContext .handler ,
1754
+ httpTransactionContext .future );
1755
+ return false ;
1756
+ } catch (IOException ioe ) {
1757
+ newContext .abort (ioe );
1758
+ return false ;
1759
+ }
1760
+ }
1761
+
1762
+ public static boolean isNTLMSecondHandShake (final String proxy_auth ) {
1733
1763
return (proxy_auth .toLowerCase ().startsWith ("ntlm" ) && !proxy_auth .equalsIgnoreCase ("ntlm" ));
1734
1764
}
1735
- public static boolean isFirstHandShake (final String proxy_auth ) {
1765
+ public static boolean isNTLMFirstHandShake (final String proxy_auth ) {
1736
1766
return (proxy_auth .equalsIgnoreCase ("ntlm" ));
1737
1767
}
1738
1768
0 commit comments