< prev index next >

src/java.net.http/share/classes/jdk/internal/net/http/AuthenticationFilter.java

Print this page
rev 54081 : 8265099: Revert backport to 11u of 8236859: WebSocket over authenticating proxy fails with NPE
Summary: Revert https://hg.openjdk.java.net/jdk-updates/jdk11u-dev/rev/57e3fa3574ec
Reviewed-by:
   1 /*
   2  * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 223 
 224         AuthInfo retryWithCredentials(PasswordAuthentication pw) {
 225             // If the info was already in the cache we need to create a new
 226             // instance with fromCache==false so that it's put back in the
 227             // cache if authentication succeeds
 228             AuthInfo res = fromcache ? new AuthInfo(false, scheme, pw) : this;
 229             res.credentials = Objects.requireNonNull(pw);
 230             res.retries = retries;
 231             return res;
 232         }
 233 
 234     }
 235 
 236     @Override
 237     public HttpRequestImpl response(Response r) throws IOException {
 238         Cache cache = getCache(exchange);
 239         int status = r.statusCode();
 240         HttpHeaders hdrs = r.headers();
 241         HttpRequestImpl req = r.request();
 242 
 243         if (status != PROXY_UNAUTHORIZED){





 244             if (exchange.proxyauth != null && !exchange.proxyauth.fromcache) {
 245                 AuthInfo au = exchange.proxyauth;
 246                 URI proxyURI = getProxyURI(req);
 247                 if (proxyURI != null) {
 248                     exchange.proxyauth = null;
 249                     cache.store(au.scheme, proxyURI, true, au.credentials);
 250                 }
 251             }
 252             if (status != UNAUTHORIZED) {
 253             // check if any authentication succeeded for first time
 254                 if (exchange.serverauth != null && !exchange.serverauth.fromcache) {
 255                     AuthInfo au = exchange.serverauth;
 256                     cache.store(au.scheme, req.uri(), false, au.credentials);
 257                 }
 258             }
 259             return null;
 260         }
 261 
 262         boolean proxy = status == PROXY_UNAUTHORIZED;
 263         String authname = proxy ? "Proxy-Authenticate" : "WWW-Authenticate";
 264         String authval = hdrs.firstValue(authname).orElse(null);
 265         if (authval == null) {
 266             if (exchange.client().authenticator().isPresent()) {
 267                 throw new IOException(authname + " header missing for response code " + status);
 268             } else {
 269                 // No authenticator? let the caller deal with this.
 270                 return null;
 271             }
 272         }
 273 
 274         HeaderParser parser = new HeaderParser(authval);
 275         String scheme = parser.findKey(0);
 276 


   1 /*
   2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 223 
 224         AuthInfo retryWithCredentials(PasswordAuthentication pw) {
 225             // If the info was already in the cache we need to create a new
 226             // instance with fromCache==false so that it's put back in the
 227             // cache if authentication succeeds
 228             AuthInfo res = fromcache ? new AuthInfo(false, scheme, pw) : this;
 229             res.credentials = Objects.requireNonNull(pw);
 230             res.retries = retries;
 231             return res;
 232         }
 233 
 234     }
 235 
 236     @Override
 237     public HttpRequestImpl response(Response r) throws IOException {
 238         Cache cache = getCache(exchange);
 239         int status = r.statusCode();
 240         HttpHeaders hdrs = r.headers();
 241         HttpRequestImpl req = r.request();
 242 
 243         if (status != UNAUTHORIZED && status != PROXY_UNAUTHORIZED) {
 244             // check if any authentication succeeded for first time
 245             if (exchange.serverauth != null && !exchange.serverauth.fromcache) {
 246                 AuthInfo au = exchange.serverauth;
 247                 cache.store(au.scheme, req.uri(), false, au.credentials);
 248             }
 249             if (exchange.proxyauth != null && !exchange.proxyauth.fromcache) {
 250                 AuthInfo au = exchange.proxyauth;
 251                 URI proxyURI = getProxyURI(req);
 252                 if (proxyURI != null) {

 253                     cache.store(au.scheme, proxyURI, true, au.credentials);







 254                 }
 255             }
 256             return null;
 257         }
 258 
 259         boolean proxy = status == PROXY_UNAUTHORIZED;
 260         String authname = proxy ? "Proxy-Authenticate" : "WWW-Authenticate";
 261         String authval = hdrs.firstValue(authname).orElse(null);
 262         if (authval == null) {
 263             if (exchange.client().authenticator().isPresent()) {
 264                 throw new IOException(authname + " header missing for response code " + status);
 265             } else {
 266                 // No authenticator? let the caller deal with this.
 267                 return null;
 268             }
 269         }
 270 
 271         HeaderParser parser = new HeaderParser(authval);
 272         String scheme = parser.findKey(0);
 273 


< prev index next >