• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/BasicUserPrincipal.java $
3  * $Revision: 658430 $
4  * $Date: 2008-05-20 14:04:27 -0700 (Tue, 20 May 2008) $
5  *
6  * ====================================================================
7  *
8  *  Licensed to the Apache Software Foundation (ASF) under one or more
9  *  contributor license agreements.  See the NOTICE file distributed with
10  *  this work for additional information regarding copyright ownership.
11  *  The ASF licenses this file to You under the Apache License, Version 2.0
12  *  (the "License"); you may not use this file except in compliance with
13  *  the License.  You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  *  Unless required by applicable law or agreed to in writing, software
18  *  distributed under the License is distributed on an "AS IS" BASIS,
19  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  *  See the License for the specific language governing permissions and
21  *  limitations under the License.
22  * ====================================================================
23  *
24  * This software consists of voluntary contributions made by many
25  * individuals on behalf of the Apache Software Foundation.  For more
26  * information on the Apache Software Foundation, please see
27  * <http://www.apache.org/>.
28  *
29  */
30 
31 package org.apache.http.auth;
32 
33 import java.security.Principal;
34 
35 import org.apache.http.util.LangUtils;
36 
37 /**
38  * Basic user principal used for HTTP authentication
39  *
40  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
41  *
42  * @since 4.0
43  *
44  * @deprecated Please use {@link java.net.URL#openConnection} instead.
45  *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
46  *     for further details.
47  */
48 @Deprecated
49 public final class BasicUserPrincipal implements Principal {
50 
51     private final String username;
52 
BasicUserPrincipal(final String username)53     public BasicUserPrincipal(final String username) {
54         super();
55         if (username == null) {
56             throw new IllegalArgumentException("User name may not be null");
57         }
58         this.username = username;
59     }
60 
getName()61     public String getName() {
62         return this.username;
63     }
64 
65     @Override
hashCode()66     public int hashCode() {
67         int hash = LangUtils.HASH_SEED;
68         hash = LangUtils.hashCode(hash, this.username);
69         return hash;
70     }
71 
72     @Override
equals(Object o)73     public boolean equals(Object o) {
74         if (o == null) return false;
75         if (this == o) return true;
76         if (o instanceof BasicUserPrincipal) {
77             BasicUserPrincipal that = (BasicUserPrincipal) o;
78             if (LangUtils.equals(this.username, that.username)) {
79                 return true;
80             }
81         }
82         return false;
83     }
84 
85     @Override
toString()86     public String toString() {
87         StringBuilder buffer = new StringBuilder();
88         buffer.append("[principal: ");
89         buffer.append(this.username);
90         buffer.append("]");
91         return buffer.toString();
92     }
93 
94 }
95 
96