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: package org.apache.harmony.auth;
19:
20: import java.io.Serializable;
21: import java.security.Principal;
22:
23: import org.apache.harmony.auth.internal.nls.Messages;
24:
25: /**
26: * This class represents a unix user by its name.
27: */
28: public class UnixPrincipal implements Serializable, Principal {
29:
30: /**
31: * @serial
32: */
33: private static final long serialVersionUID = -4145806951495625642L;
34:
35: // User name
36: private String name;
37:
38: /**
39: * Sole constructor.
40: * @param name user name
41: * @throws NullPointerException if name is null
42: */
43: public UnixPrincipal(String name) {
44: if (name == null) {
45: throw new NullPointerException(Messages
46: .getString("auth.00")); //$NON-NLS-1$
47: }
48: this .name = name;
49: }
50:
51: /**
52: * @return user name
53: */
54: public String getName() {
55: return name;
56: }
57:
58: /**
59: * Returns string representation of this object
60: */
61: @Override
62: public String toString() {
63: return "UnixPrincipal, name=" + name; //$NON-NLS-1$
64: }
65:
66: /**
67: * Compares two UnixPrincipal objects.<br>
68: * Two principal objects are considered equal if they are both of type
69: * UnixPrincipal and their names are equal.
70: */
71: @Override
72: public boolean equals(Object o) {
73: if (o instanceof UnixPrincipal) {
74: return name.equals(((UnixPrincipal) o).name);
75: }
76: return false;
77: }
78:
79: /**
80: * Return hash code of this object.
81: */
82: @Override
83: public int hashCode() {
84: return name.hashCode();
85: }
86: }
|