001: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
002: *
003: * Licensed under the Apache License, Version 2.0 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software
010: * distributed under the License is distributed on an "AS IS" BASIS,
011: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: * See the License for the specific language governing permissions and
013: * limitations under the License.
014: */
015: package org.acegisecurity.acls.domain;
016:
017: import org.acegisecurity.acls.AccessControlEntry;
018: import org.acegisecurity.acls.Acl;
019: import org.acegisecurity.acls.AuditableAccessControlEntry;
020: import org.acegisecurity.acls.Permission;
021: import org.acegisecurity.acls.sid.Sid;
022:
023: import org.springframework.util.Assert;
024:
025: import java.io.Serializable;
026:
027: /**
028: * An immutable default implementation of <code>AccessControlEntry</code>.
029: *
030: * @author Ben Alex
031: * @version $Id: AccessControlEntryImpl.java 1754 2006-11-17 02:01:21Z benalex $
032: */
033: public class AccessControlEntryImpl implements AccessControlEntry,
034: AuditableAccessControlEntry {
035: //~ Instance fields ================================================================================================
036:
037: private Acl acl;
038: private Permission permission;
039: private Serializable id;
040: private Sid sid;
041: private boolean auditFailure = false;
042: private boolean auditSuccess = false;
043: private boolean granting;
044:
045: //~ Constructors ===================================================================================================
046:
047: public AccessControlEntryImpl(Serializable id, Acl acl, Sid sid,
048: Permission permission, boolean granting,
049: boolean auditSuccess, boolean auditFailure) {
050: Assert.notNull(acl, "Acl required");
051: Assert.notNull(sid, "Sid required");
052: Assert.notNull(permission, "Permission required");
053: this .id = id;
054: this .acl = acl; // can be null
055: this .sid = sid;
056: this .permission = permission;
057: this .granting = granting;
058: this .auditSuccess = auditSuccess;
059: this .auditFailure = auditFailure;
060: }
061:
062: //~ Methods ========================================================================================================
063:
064: public boolean equals(Object arg0) {
065: if (!(arg0 instanceof AccessControlEntryImpl)) {
066: return false;
067: }
068:
069: AccessControlEntryImpl rhs = (AccessControlEntryImpl) arg0;
070:
071: if ((this .auditFailure != rhs.isAuditFailure())
072: || (this .auditSuccess != rhs.isAuditSuccess())
073: || (this .granting != rhs.isGranting())
074: || !this .acl.equals(rhs.getAcl())
075: || !this .id.equals(rhs.getId())
076: || !this .permission.equals(rhs.getPermission())
077: || !this .sid.equals(rhs.getSid())) {
078: return false;
079: }
080:
081: return true;
082: }
083:
084: public Acl getAcl() {
085: return acl;
086: }
087:
088: public Serializable getId() {
089: return id;
090: }
091:
092: public Permission getPermission() {
093: return permission;
094: }
095:
096: public Sid getSid() {
097: return sid;
098: }
099:
100: public boolean isAuditFailure() {
101: return auditFailure;
102: }
103:
104: public boolean isAuditSuccess() {
105: return auditSuccess;
106: }
107:
108: public boolean isGranting() {
109: return granting;
110: }
111:
112: void setAuditFailure(boolean auditFailure) {
113: this .auditFailure = auditFailure;
114: }
115:
116: void setAuditSuccess(boolean auditSuccess) {
117: this .auditSuccess = auditSuccess;
118: }
119:
120: void setPermission(Permission permission) {
121: Assert.notNull(permission, "Permission required");
122: this .permission = permission;
123: }
124:
125: public String toString() {
126: StringBuffer sb = new StringBuffer();
127: sb.append("AccessControlEntryImpl[");
128: sb.append("id: ").append(this .id).append("; ");
129: sb.append("granting: ").append(this .granting).append("; ");
130: sb.append("sid: ").append(this .sid).append("; ");
131: sb.append("permission: ").append(this .permission).append("; ");
132: sb.append("auditSuccess: ").append(this .auditSuccess).append(
133: "; ");
134: sb.append("auditFailure: ").append(this .auditFailure);
135: sb.append("]");
136:
137: return sb.toString();
138: }
139: }
|