]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.core/src/org/argeo/security/login/GrantedAuthorityPrincipal.java
Move Jackrabbit security model
[lgpl/argeo-commons.git] / org.argeo.security.core / src / org / argeo / security / login / GrantedAuthorityPrincipal.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.security.login;
17
18 import java.security.Principal;
19
20 import javax.security.auth.Subject;
21
22 import org.springframework.security.core.GrantedAuthority;
23
24 /**
25 * A {@link Principal} which is also a {@link GrantedAuthority}, so that the
26 * Spring Security can be used to quickly populate a {@link Subject} principals.
27 */
28 public final class GrantedAuthorityPrincipal implements Principal,
29 GrantedAuthority {
30 private static final long serialVersionUID = 6768044196343543328L;
31 private final String authority;
32
33 public GrantedAuthorityPrincipal(String authority) {
34 this.authority = authority;
35 }
36
37 @Override
38 public String getAuthority() {
39 return authority;
40 }
41
42 @Override
43 public String getName() {
44 return authority;
45 }
46
47 @Override
48 public int hashCode() {
49 return getName().hashCode();
50 }
51
52 @Override
53 public boolean equals(Object obj) {
54 if (!(obj instanceof GrantedAuthorityPrincipal))
55 return false;
56 return getName().equals(((GrantedAuthorityPrincipal) obj).getName());
57 }
58
59 @Override
60 public String toString() {
61 return "Granted Authority " + getName();
62 }
63
64 }