2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.cms
.internal
.auth
;
18 import java
.security
.Principal
;
20 import javax
.security
.auth
.Subject
;
22 import org
.springframework
.security
.core
.GrantedAuthority
;
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.
28 public final class GrantedAuthorityPrincipal
implements Principal
,
30 private static final long serialVersionUID
= 6768044196343543328L;
31 private final String authority
;
33 public GrantedAuthorityPrincipal(String authority
) {
34 this.authority
= authority
;
38 public String
getAuthority() {
43 public String
getName() {
48 public int hashCode() {
49 return getName().hashCode();
53 public boolean equals(Object obj
) {
54 if (!(obj
instanceof GrantedAuthorityPrincipal
))
56 return getName().equals(((GrantedAuthorityPrincipal
) obj
).getName());
60 public String
toString() {
61 return "Granted Authority " + getName();