Print this page


Split Close
Expand all
Collapse all
          --- old/src/windows/classes/sun/net/www/protocol/http/NTLMAuthentication.java
          +++ new/src/windows/classes/sun/net/www/protocol/http/ntlm/NTLMAuthentication.java
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16   *
  17   17   * You should have received a copy of the GNU General Public License version
  18   18   * 2 along with this work; if not, write to the Free Software Foundation,
  19   19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20   20   *
  21   21   * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22   22   * CA 95054 USA or visit www.sun.com if you need additional information or
  23   23   * have any questions.
  24   24   */
  25   25  
  26      -package sun.net.www.protocol.http;
       26 +package sun.net.www.protocol.http.ntlm;
  27   27  
  28   28  import java.io.IOException;
  29   29  import java.net.InetAddress;
  30   30  import java.net.PasswordAuthentication;
  31   31  import java.net.UnknownHostException;
  32   32  import java.net.URL;
  33   33  import sun.net.www.HeaderParser;
       34 +import sun.net.www.protocol.http.AuthenticationInfo;
       35 +import sun.net.www.protocol.http.AuthScheme;
       36 +import sun.net.www.protocol.http.HttpURLConnection;
  34   37  
  35   38  /**
  36   39   * NTLMAuthentication:
  37   40   *
  38   41   * @author Michael McMahon
  39   42   */
  40   43  
  41      -class NTLMAuthentication extends AuthenticationInfo {
       44 +public class NTLMAuthentication extends AuthenticationInfo {
  42   45  
  43   46      private static final long serialVersionUID = 100L;
  44   47  
  45   48      private String hostname;
  46   49      private static String defaultDomain; /* Domain to use if not specified by user */
  47   50  
  48   51      static {
  49   52          defaultDomain = java.security.AccessController.doPrivileged(
  50   53              new sun.security.action.GetPropertyAction("http.auth.ntlm.domain",
  51   54                                                        "domain"));
↓ open down ↓ 68 lines elided ↑ open up ↑
 120  123                AuthScheme.NTLM,
 121  124                host,
 122  125                port,
 123  126                "");
 124  127          init (pw);
 125  128      }
 126  129  
 127  130      /**
 128  131       * @return true if this authentication supports preemptive authorization
 129  132       */
 130      -    boolean supportsPreemptiveAuthorization() {
      133 +    @Override
      134 +    public boolean supportsPreemptiveAuthorization() {
 131  135          return false;
 132  136      }
 133  137  
 134  138      /**
 135  139       * @return true if NTLM supported transparently (no password needed, SSO)
 136  140       */
 137      -    static boolean supportsTransparentAuth() {
      141 +    public static boolean supportsTransparentAuth() {
 138  142          return true;
 139  143      }
 140  144  
 141  145      /**
 142      -     * @return the name of the HTTP header this authentication wants set
 143      -     */
 144      -    String getHeaderName() {
 145      -        if (type == SERVER_AUTHENTICATION) {
 146      -            return "Authorization";
 147      -        } else {
 148      -            return "Proxy-authorization";
 149      -        }
 150      -    }
 151      -
 152      -    /**
 153  146       * Not supported. Must use the setHeaders() method
 154  147       */
 155      -    String getHeaderValue(URL url, String method) {
      148 +    @Override
      149 +    public String getHeaderValue(URL url, String method) {
 156  150          throw new RuntimeException ("getHeaderValue not supported");
 157  151      }
 158  152  
 159  153      /**
 160  154       * Check if the header indicates that the current auth. parameters are stale.
 161  155       * If so, then replace the relevant field with the new value
 162  156       * and return true. Otherwise return false.
 163  157       * returning true means the request can be retried with the same userid/password
 164  158       * returning false means we have to go back to the user to ask for a new
 165  159       * username password.
 166  160       */
 167      -    boolean isAuthorizationStale (String header) {
      161 +    @Override
      162 +    public boolean isAuthorizationStale (String header) {
 168  163          return false; /* should not be called for ntlm */
 169  164      }
 170  165  
 171  166      /**
 172  167       * Set header(s) on the given connection.
 173  168       * @param conn The connection to apply the header(s) to
 174  169       * @param p A source of header values for this connection, not used because
 175  170       *          HeaderParser converts the fields to lower case, use raw instead
 176  171       * @param raw The raw header field.
 177  172       * @return true if all goes well, false if no headers were set.
 178  173       */
 179      -    synchronized boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw) {
      174 +    @Override
      175 +    public synchronized boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw) {
 180  176  
 181  177          try {
 182      -            NTLMAuthSequence seq = (NTLMAuthSequence)conn.authObj;
      178 +            NTLMAuthSequence seq = (NTLMAuthSequence)conn.authObj();
 183  179              if (seq == null) {
 184  180                  seq = new NTLMAuthSequence (username, password, ntdomain);
 185      -                conn.authObj = seq;
      181 +                conn.authObj(seq);
 186  182              }
 187  183              String response = "NTLM " + seq.getAuthHeader (raw.length()>6?raw.substring(5):null);
 188  184              conn.setAuthenticationProperty(getHeaderName(), response);
 189  185              return true;
 190  186          } catch (IOException e) {
 191  187              return false;
 192  188          }
 193  189      }
 194  190  
 195  191  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX