jdk/src/share/classes/sun/net/www/protocol/http/BasicAuthentication.java
changeset 3859 8b82336dedb3
parent 2 90ce3da70b43
child 3952 dc329398de30
equal deleted inserted replaced
3858:ea9c34fc8590 3859:8b82336dedb3
    42 
    42 
    43 class BasicAuthentication extends AuthenticationInfo {
    43 class BasicAuthentication extends AuthenticationInfo {
    44 
    44 
    45     private static final long serialVersionUID = 100L;
    45     private static final long serialVersionUID = 100L;
    46 
    46 
    47     static final char BASIC_AUTH = 'B';
       
    48 
       
    49     /** The authentication string for this host, port, and realm.  This is
    47     /** The authentication string for this host, port, and realm.  This is
    50         a simple BASE64 encoding of "login:password".    */
    48         a simple BASE64 encoding of "login:password".    */
    51     String auth;
    49     String auth;
    52 
    50 
    53     /**
    51     /**
    54      * Create a BasicAuthentication
    52      * Create a BasicAuthentication
    55      */
    53      */
    56     public BasicAuthentication(boolean isProxy, String host, int port,
    54     public BasicAuthentication(boolean isProxy, String host, int port,
    57                                String realm, PasswordAuthentication pw) {
    55                                String realm, PasswordAuthentication pw) {
    58         super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
    56         super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
    59               BASIC_AUTH, host, port, realm);
    57               AuthScheme.BASIC, host, port, realm);
    60         String plain = pw.getUserName() + ":";
    58         String plain = pw.getUserName() + ":";
    61         byte[] nameBytes = null;
    59         byte[] nameBytes = null;
    62         try {
    60         try {
    63             nameBytes = plain.getBytes("ISO-8859-1");
    61             nameBytes = plain.getBytes("ISO-8859-1");
    64         } catch (java.io.UnsupportedEncodingException uee) {
    62         } catch (java.io.UnsupportedEncodingException uee) {
    84      * Create a BasicAuthentication
    82      * Create a BasicAuthentication
    85      */
    83      */
    86     public BasicAuthentication(boolean isProxy, String host, int port,
    84     public BasicAuthentication(boolean isProxy, String host, int port,
    87                                String realm, String auth) {
    85                                String realm, String auth) {
    88         super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
    86         super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
    89               BASIC_AUTH, host, port, realm);
    87               AuthScheme.BASIC, host, port, realm);
    90         this.auth = "Basic " + auth;
    88         this.auth = "Basic " + auth;
    91     }
    89     }
    92 
    90 
    93     /**
    91     /**
    94      * Create a BasicAuthentication
    92      * Create a BasicAuthentication
    95      */
    93      */
    96     public BasicAuthentication(boolean isProxy, URL url, String realm,
    94     public BasicAuthentication(boolean isProxy, URL url, String realm,
    97                                    PasswordAuthentication pw) {
    95                                    PasswordAuthentication pw) {
    98         super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
    96         super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
    99               BASIC_AUTH, url, realm);
    97               AuthScheme.BASIC, url, realm);
   100         String plain = pw.getUserName() + ":";
    98         String plain = pw.getUserName() + ":";
   101         byte[] nameBytes = null;
    99         byte[] nameBytes = null;
   102         try {
   100         try {
   103             nameBytes = plain.getBytes("ISO-8859-1");
   101             nameBytes = plain.getBytes("ISO-8859-1");
   104         } catch (java.io.UnsupportedEncodingException uee) {
   102         } catch (java.io.UnsupportedEncodingException uee) {
   124      * Create a BasicAuthentication
   122      * Create a BasicAuthentication
   125      */
   123      */
   126     public BasicAuthentication(boolean isProxy, URL url, String realm,
   124     public BasicAuthentication(boolean isProxy, URL url, String realm,
   127                                    String auth) {
   125                                    String auth) {
   128         super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
   126         super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
   129               BASIC_AUTH, url, realm);
   127               AuthScheme.BASIC, url, realm);
   130         this.auth = "Basic " + auth;
   128         this.auth = "Basic " + auth;
   131     }
   129     }
   132 
   130 
   133     /**
   131     /**
   134      * @return true if this authentication supports preemptive authorization
   132      * @return true if this authentication supports preemptive authorization