01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author Alexander V. Astapchuk
20: * @version $Revision$
21: */package org.apache.harmony.auth;
22:
23: import java.security.Principal;
24: import java.io.Serializable;
25:
26: import org.apache.harmony.auth.internal.nls.Messages;
27:
28: /**
29: * A Principal which stores information NT domain name
30: */
31: public class NTDomainPrincipal implements Principal, Serializable {
32:
33: private static final long serialVersionUID = 7574453578624887003L;
34:
35: // Domain name
36: private String name;
37:
38: /**
39: * Construct an instance with the given domain name.
40: * @throws NullPointerException is name is null
41: */
42: public NTDomainPrincipal(String name) {
43: if (name == null) {
44: throw new NullPointerException(Messages
45: .getString("auth.00")); //$NON-NLS-1$
46: }
47: this .name = name;
48: }
49:
50: /**
51: * Returns domain name
52: */
53: public String getName() {
54: return name;
55: }
56:
57: /**
58: * Tests two objects for equality.<br>
59: * Two objects are considered equal if they both represent NTDomainPrincipal
60: * and they have the same domain name.
61: */
62: @Override
63: public boolean equals(Object obj) {
64: if (obj == this ) {
65: return true;
66: }
67: if (obj instanceof NTDomainPrincipal) {
68: return name.equals(((NTDomainPrincipal) obj).name);
69: }
70: return false;
71: }
72:
73: /**
74: * Returns hashCode that value is equal to getName().hashCode();
75: */
76: @Override
77: public int hashCode() {
78: return name.hashCode();
79: }
80:
81: /**
82: * Returns String representation of this object.
83: */
84: @Override
85: public String toString() {
86: return "NTDomainPrincipal: " + name; //$NON-NLS-1$
87: }
88: }
|