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 public final class BasicUserPrincipal implements Principal { 45 46 private final String username; 47 48 public BasicUserPrincipal(final String username) { 49 super(); 50 if (username == null) { 51 throw new IllegalArgumentException("User name may not be null"); 52 } 53 this.username = username; 54 } 55 56 public String getName() { 57 return this.username; 58 } 59 60 @Override 61 public int hashCode() { 62 int hash = LangUtils.HASH_SEED; 63 hash = LangUtils.hashCode(hash, this.username); 64 return hash; 65 } 66 67 @Override 68 public boolean equals(Object o) { 69 if (o == null) return false; 70 if (this == o) return true; 71 if (o instanceof BasicUserPrincipal) { 72 BasicUserPrincipal that = (BasicUserPrincipal) o; 73 if (LangUtils.equals(this.username, that.username)) { 74 return true; 75 } 76 } 77 return false; 78 } 79 80 @Override 81 public String toString() { 82 StringBuilder buffer = new StringBuilder(); 83 buffer.append("[principal: "); 84 buffer.append(this.username); 85 buffer.append("]"); 86 return buffer.toString(); 87 } 88 89 } 90 91