src/java.security.jgss/share/classes/sun/net/www/protocol/http/spnego/NegotiateCallbackHandler.java
changeset 48579 52449da2c349
parent 47216 71c04702a3d5
equal deleted inserted replaced
48578:2f2d159b03fc 48579:52449da2c349
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    33 import javax.security.auth.callback.CallbackHandler;
    33 import javax.security.auth.callback.CallbackHandler;
    34 import javax.security.auth.callback.NameCallback;
    34 import javax.security.auth.callback.NameCallback;
    35 import javax.security.auth.callback.PasswordCallback;
    35 import javax.security.auth.callback.PasswordCallback;
    36 import javax.security.auth.callback.UnsupportedCallbackException;
    36 import javax.security.auth.callback.UnsupportedCallbackException;
    37 import sun.net.www.protocol.http.HttpCallerInfo;
    37 import sun.net.www.protocol.http.HttpCallerInfo;
       
    38 import sun.security.jgss.LoginConfigImpl;
    38 
    39 
    39 /**
    40 /**
    40  * @since 1.6
    41  * @since 1.6
    41  * Special callback handler used in JGSS for the HttpCaller.
    42  * Special callback handler used in JGSS for the HttpCaller.
    42  */
    43  */
    59     }
    60     }
    60 
    61 
    61     private void getAnswer() {
    62     private void getAnswer() {
    62         if (!answered) {
    63         if (!answered) {
    63             answered = true;
    64             answered = true;
    64             PasswordAuthentication passAuth =
    65             Authenticator auth;
    65                     Authenticator.requestPasswordAuthentication(
    66             if (hci.authenticator != null) {
    66                     hci.authenticator,
    67                 auth = hci.authenticator;
    67                     hci.host, hci.addr, hci.port, hci.protocol,
    68             } else {
    68                     hci.prompt, hci.scheme, hci.url, hci.authType);
    69                 auth = LoginConfigImpl.HTTP_USE_GLOBAL_CREDS ?
    69             /**
    70                         Authenticator.getDefault() : null;
    70              * To be compatible with existing callback handler implementations,
    71             }
    71              * when the underlying Authenticator is canceled, username and
    72 
    72              * password are assigned null. No exception is thrown.
    73             if (auth != null) {
    73              */
    74                 PasswordAuthentication passAuth =
    74             if (passAuth != null) {
    75                         auth.requestPasswordAuthenticationInstance(
    75                 username = passAuth.getUserName();
    76                                 hci.host, hci.addr, hci.port, hci.protocol,
    76                 password = passAuth.getPassword();
    77                                 hci.prompt, hci.scheme, hci.url, hci.authType);
       
    78                 /**
       
    79                  * To be compatible with existing callback handler implementations,
       
    80                  * when the underlying Authenticator is canceled, username and
       
    81                  * password are assigned null. No exception is thrown.
       
    82                  */
       
    83                 if (passAuth != null) {
       
    84                     username = passAuth.getUserName();
       
    85                     password = passAuth.getPassword();
       
    86                 }
    77             }
    87             }
    78         }
    88         }
    79     }
    89     }
    80 
    90 
    81     public void handle(Callback[] callbacks) throws
    91     public void handle(Callback[] callbacks) throws