< prev index next >

src/java.base/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java

Print this page




 174 
 175         try {
 176             String response;
 177             byte[] incoming = null;
 178             String[] parts = raw.split("\\s+");
 179             if (parts.length > 1) {
 180                 incoming = Base64.getDecoder().decode(parts[1]);
 181             }
 182             response = hci.scheme + " " + Base64.getEncoder().encodeToString(
 183                         incoming==null?firstToken():nextToken(incoming));
 184 
 185             conn.setAuthenticationProperty(getHeaderName(), response);
 186             return true;
 187         } catch (IOException e) {
 188             return false;
 189         }
 190     }
 191 
 192     /**
 193      * return the first token.
 194      * @returns the token
 195      * @throws IOException if <code>Negotiator.getNegotiator()</code> or
 196      *                     <code>Negotiator.firstToken()</code> failed.
 197      */
 198     private byte[] firstToken() throws IOException {
 199         negotiator = null;
 200         if (cache != null) {
 201             synchronized(cache) {
 202                 negotiator = cache.get(getHost());
 203                 if (negotiator != null) {
 204                     cache.remove(getHost()); // so that it is only used once
 205                 }
 206             }
 207         }
 208         if (negotiator == null) {
 209             negotiator = Negotiator.getNegotiator(hci);
 210             if (negotiator == null) {
 211                 IOException ioe = new IOException("Cannot initialize Negotiator");
 212                 throw ioe;
 213             }
 214         }
 215 
 216         return negotiator.firstToken();
 217     }
 218 
 219     /**
 220      * return more tokens
 221      * @param token the token to be fed into <code>negotiator.nextToken()</code>
 222      * @returns the token
 223      * @throws IOException if <code>negotiator.nextToken()</code> throws Exception.
 224      *  May happen if the input token is invalid.
 225      */
 226     private byte[] nextToken(byte[] token) throws IOException {
 227         return negotiator.nextToken(token);
 228     }
 229 
 230     // MS will send a final WWW-Authenticate even if the status is already
 231     // 200 OK. The token can be fed into initSecContext() again to determine
 232     // if the server can be trusted. This is not the same concept as Digest's
 233     // Authentication-Info header.
 234     //
 235     // Currently we ignore this header.
 236 
 237 }


 174 
 175         try {
 176             String response;
 177             byte[] incoming = null;
 178             String[] parts = raw.split("\\s+");
 179             if (parts.length > 1) {
 180                 incoming = Base64.getDecoder().decode(parts[1]);
 181             }
 182             response = hci.scheme + " " + Base64.getEncoder().encodeToString(
 183                         incoming==null?firstToken():nextToken(incoming));
 184 
 185             conn.setAuthenticationProperty(getHeaderName(), response);
 186             return true;
 187         } catch (IOException e) {
 188             return false;
 189         }
 190     }
 191 
 192     /**
 193      * return the first token.
 194      * @return the token
 195      * @throws IOException if <code>Negotiator.getNegotiator()</code> or
 196      *                     <code>Negotiator.firstToken()</code> failed.
 197      */
 198     private byte[] firstToken() throws IOException {
 199         negotiator = null;
 200         if (cache != null) {
 201             synchronized(cache) {
 202                 negotiator = cache.get(getHost());
 203                 if (negotiator != null) {
 204                     cache.remove(getHost()); // so that it is only used once
 205                 }
 206             }
 207         }
 208         if (negotiator == null) {
 209             negotiator = Negotiator.getNegotiator(hci);
 210             if (negotiator == null) {
 211                 IOException ioe = new IOException("Cannot initialize Negotiator");
 212                 throw ioe;
 213             }
 214         }
 215 
 216         return negotiator.firstToken();
 217     }
 218 
 219     /**
 220      * return more tokens
 221      * @param token the token to be fed into <code>negotiator.nextToken()</code>
 222      * @return the token
 223      * @throws IOException if <code>negotiator.nextToken()</code> throws Exception.
 224      *  May happen if the input token is invalid.
 225      */
 226     private byte[] nextToken(byte[] token) throws IOException {
 227         return negotiator.nextToken(token);
 228     }
 229 
 230     // MS will send a final WWW-Authenticate even if the status is already
 231     // 200 OK. The token can be fed into initSecContext() again to determine
 232     // if the server can be trusted. This is not the same concept as Digest's
 233     // Authentication-Info header.
 234     //
 235     // Currently we ignore this header.
 236 
 237 }
< prev index next >