| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| GrantedAuthoritySid |
|
| 1.4;1.4 |
| 1 | /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited |
|
| 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 org.acegisecurity.acls.sid; |
|
| 16 | ||
| 17 | import org.acegisecurity.GrantedAuthority; |
|
| 18 | ||
| 19 | import org.springframework.util.Assert; |
|
| 20 | ||
| 21 | ||
| 22 | /** |
|
| 23 | * Represents a <code>GrantedAuthority</code> as a <code>Sid</code>.<p>This is a basic implementation that simply |
|
| 24 | * uses the <code>String</code>-based principal for <code>Sid</code> comparison. More complex principal objects may |
|
| 25 | * wish to provide an alternative <code>Sid</code> implementation that uses some other identifier.</p> |
|
| 26 | * |
|
| 27 | * @author Ben Alex |
|
| 28 | * @version $Id: GrantedAuthoritySid.java 1754 2006-11-17 02:01:21Z benalex $ |
|
| 29 | */ |
|
| 30 | public class GrantedAuthoritySid implements Sid { |
|
| 31 | //~ Instance fields ================================================================================================ |
|
| 32 | ||
| 33 | private String grantedAuthority; |
|
| 34 | ||
| 35 | //~ Constructors =================================================================================================== |
|
| 36 | ||
| 37 | 0 | public GrantedAuthoritySid(String grantedAuthority) { |
| 38 | 0 | Assert.hasText(grantedAuthority, "GrantedAuthority required"); |
| 39 | 0 | this.grantedAuthority = grantedAuthority; |
| 40 | 0 | } |
| 41 | ||
| 42 | 0 | public GrantedAuthoritySid(GrantedAuthority grantedAuthority) { |
| 43 | 0 | Assert.notNull(grantedAuthority, "GrantedAuthority required"); |
| 44 | 0 | Assert.notNull(grantedAuthority.getAuthority(), |
| 45 | "This Sid is only compatible with GrantedAuthoritys that provide a non-null getAuthority()"); |
|
| 46 | 0 | this.grantedAuthority = grantedAuthority.getAuthority(); |
| 47 | 0 | } |
| 48 | ||
| 49 | //~ Methods ======================================================================================================== |
|
| 50 | ||
| 51 | public boolean equals(Object object) { |
|
| 52 | 0 | if ((object == null) || !(object instanceof GrantedAuthoritySid)) { |
| 53 | 0 | return false; |
| 54 | } |
|
| 55 | ||
| 56 | // Delegate to getGrantedAuthority() to perform actual comparison (both should be identical) |
|
| 57 | 0 | return ((GrantedAuthoritySid) object).getGrantedAuthority().equals(this.getGrantedAuthority()); |
| 58 | } |
|
| 59 | ||
| 60 | public String getGrantedAuthority() { |
|
| 61 | 0 | return grantedAuthority; |
| 62 | } |
|
| 63 | ||
| 64 | public String toString() { |
|
| 65 | 0 | return "GrantedAuthoritySid[" + this.grantedAuthority + "]"; |
| 66 | } |
|
| 67 | } |