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 user name.
30: */
31: public class NTUserPrincipal implements Serializable, Principal {
32:
33: private static final long serialVersionUID = 7585428904927483501L;
34:
35: // User name
36: private String name;
37:
38: /**
39: * The sole constructor.
40: * @throws NullPointerException is name is null
41: */
42: public NTUserPrincipal(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 user name.
52: */
53: public String getName() {
54: return name;
55: }
56:
57: /**
58: * Returns String representation of this object.
59: */
60: @Override
61: public String toString() {
62: return "NTUserPrincipal: name=" + name; //$NON-NLS-1$
63: }
64:
65: /**
66: * Tests two objects for equality.<br>
67: * Two objects are considered equal if they both represent NTUserPrincipal
68: * and they have the same name.
69: */
70: @Override
71: public boolean equals(Object obj) {
72: if (obj == this ) {
73: return true;
74: }
75: if (obj instanceof NTUserPrincipal) {
76: return name.equals(((NTUserPrincipal) obj).name);
77: }
78: return false;
79: }
80:
81: /**
82: * Returns hashCode for this object.
83: */
84: @Override
85: public int hashCode() {
86: return name.hashCode();
87: }
88: }
|