1 /* 2 * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/NTUserPrincipal.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 import java.util.Locale; 35 36 import org.apache.http.util.LangUtils; 37 38 /** NT (MS Windows specific) 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 class NTUserPrincipal implements Principal { 45 46 private final String username; 47 private final String domain; 48 private final String ntname; 49 NTUserPrincipal( final String domain, final String username)50 public NTUserPrincipal( 51 final String domain, 52 final String username) { 53 super(); 54 if (username == null) { 55 throw new IllegalArgumentException("User name may not be null"); 56 } 57 this.username = username; 58 if (domain != null) { 59 this.domain = domain.toUpperCase(Locale.ENGLISH); 60 } else { 61 this.domain = null; 62 } 63 if (this.domain != null && this.domain.length() > 0) { 64 StringBuilder buffer = new StringBuilder(); 65 buffer.append(this.domain); 66 buffer.append('/'); 67 buffer.append(this.username); 68 this.ntname = buffer.toString(); 69 } else { 70 this.ntname = this.username; 71 } 72 } 73 getName()74 public String getName() { 75 return this.ntname; 76 } 77 getDomain()78 public String getDomain() { 79 return this.domain; 80 } 81 getUsername()82 public String getUsername() { 83 return this.username; 84 } 85 86 @Override hashCode()87 public int hashCode() { 88 int hash = LangUtils.HASH_SEED; 89 hash = LangUtils.hashCode(hash, this.username); 90 hash = LangUtils.hashCode(hash, this.domain); 91 return hash; 92 } 93 94 @Override equals(Object o)95 public boolean equals(Object o) { 96 if (o == null) return false; 97 if (this == o) return true; 98 if (o instanceof NTUserPrincipal) { 99 NTUserPrincipal that = (NTUserPrincipal) o; 100 if (LangUtils.equals(this.username, that.username) 101 && LangUtils.equals(this.domain, that.domain)) { 102 return true; 103 } 104 } 105 return false; 106 } 107 108 @Override toString()109 public String toString() { 110 return this.ntname; 111 } 112 113 } 114