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