1 | // Copyright 2004-2007 Jean-Francois Poilpret |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | package net.sourceforge.hivelock; |
16 | |
17 | import java.io.Serializable; |
18 | import java.security.Principal; |
19 | import java.util.Arrays; |
20 | |
21 | public class DefaultPrincipal implements Principal, Serializable |
22 | { |
23 | public DefaultPrincipal(String login, String name, String[] roles) |
24 | { |
25 | _login = login; |
26 | _name = name; |
27 | _roles = roles; |
28 | Arrays.sort(_roles); |
29 | } |
30 | |
31 | public String[] getRoles() |
32 | { |
33 | return _roles; |
34 | } |
35 | |
36 | public String getName() |
37 | { |
38 | return _name; |
39 | } |
40 | |
41 | public String getLogin() |
42 | { |
43 | return _login; |
44 | } |
45 | |
46 | public boolean equals(Object obj) |
47 | { |
48 | if (obj instanceof DefaultPrincipal) |
49 | { |
50 | return getLogin().equals(((DefaultPrincipal) obj).getLogin()); |
51 | } |
52 | return false; |
53 | } |
54 | |
55 | public String toString() |
56 | { |
57 | return getLogin(); |
58 | } |
59 | |
60 | public int hashCode() |
61 | { |
62 | return getLogin().hashCode(); |
63 | } |
64 | |
65 | private String _login; |
66 | private String _name; |
67 | private String[] _roles; |
68 | } |