⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aclimpl.java

📁 acegi构造安全的java系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.acegisecurity.acls.domain;import org.acegisecurity.acls.AccessControlEntry;import org.acegisecurity.acls.Acl;import org.acegisecurity.acls.AuditableAcl;import org.acegisecurity.acls.MutableAcl;import org.acegisecurity.acls.NotFoundException;import org.acegisecurity.acls.OwnershipAcl;import org.acegisecurity.acls.Permission;import org.acegisecurity.acls.UnloadedSidException;import org.acegisecurity.acls.objectidentity.ObjectIdentity;import org.acegisecurity.acls.sid.Sid;import org.springframework.util.Assert;import java.io.Serializable;import java.util.Iterator;import java.util.List;import java.util.Vector;/** * Base implementation of <code>Acl</code>. * * @author Ben Alex * @version $Id */public class AclImpl implements Acl, MutableAcl, AuditableAcl, OwnershipAcl {    //~ Instance fields ================================================================================================    private Acl parentAcl;    private AclAuthorizationStrategy aclAuthorizationStrategy;    private AuditLogger auditLogger;    private List aces = new Vector();    private ObjectIdentity objectIdentity;    private Serializable id;    private Sid owner; // OwnershipAcl    private Sid[] loadedSids = null; // includes all SIDs the WHERE clause covered, even if there was no ACE for a SID    private boolean entriesInheriting = true;    //~ Constructors ===================================================================================================/**     * Minimal constructor, which should be used {@link     * org.acegisecurity.acls.MutableAclService#createAcl(ObjectIdentity)}.     *     * @param objectIdentity the object identity this ACL relates to (required)     * @param id the primary key assigned to this ACL (required)     * @param aclAuthorizationStrategy authorization strategy (required)     * @param auditLogger audit logger (required)     */    public AclImpl(ObjectIdentity objectIdentity, Serializable id, AclAuthorizationStrategy aclAuthorizationStrategy,        AuditLogger auditLogger) {        Assert.notNull(objectIdentity, "Object Identity required");        Assert.notNull(id, "Id required");        Assert.notNull(aclAuthorizationStrategy, "AclAuthorizationStrategy required");        Assert.notNull(auditLogger, "AuditLogger required");        this.objectIdentity = objectIdentity;        this.id = id;        this.aclAuthorizationStrategy = aclAuthorizationStrategy;        this.auditLogger = auditLogger;    }/**     * Full constructor, which should be used by persistence tools that do not     * provide field-level access features.     *     * @param objectIdentity the object identity this ACL relates to (required)     * @param id the primary key assigned to this ACL (required)     * @param aclAuthorizationStrategy authorization strategy (required)     * @param auditLogger audit logger (required)     * @param parentAcl the parent (may be <code>null</code>)     * @param loadedSids the loaded SIDs if only a subset were loaded (may be     *        <code>null</code>)     * @param entriesInheriting if ACEs from the parent should inherit into     *        this ACL     * @param owner the owner (required)     */    public AclImpl(ObjectIdentity objectIdentity, Serializable id, AclAuthorizationStrategy aclAuthorizationStrategy,        AuditLogger auditLogger, Acl parentAcl, Sid[] loadedSids, boolean entriesInheriting, Sid owner) {        Assert.notNull(objectIdentity, "Object Identity required");        Assert.notNull(id, "Id required");        Assert.notNull(aclAuthorizationStrategy, "AclAuthorizationStrategy required");        Assert.notNull(owner, "Owner required");        Assert.notNull(auditLogger, "AuditLogger required");        this.objectIdentity = objectIdentity;        this.id = id;        this.aclAuthorizationStrategy = aclAuthorizationStrategy;        this.auditLogger = auditLogger;        this.parentAcl = parentAcl; // may be null        this.loadedSids = loadedSids; // may be null        this.entriesInheriting = entriesInheriting;        this.owner = owner;    }/**     * Private no-argument constructor for use by reflection-based persistence     * tools along with field-level access.     */    private AclImpl() {}    //~ Methods ========================================================================================================    public void deleteAce(Serializable aceId) throws NotFoundException {        aclAuthorizationStrategy.securityCheck(this, AclAuthorizationStrategy.CHANGE_GENERAL);        synchronized (aces) {            int offset = findAceOffset(aceId);            if (offset == -1) {                throw new NotFoundException("Requested ACE ID not found");            }            this.aces.remove(offset);        }    }    private int findAceOffset(Serializable aceId) {        Assert.notNull(aceId, "ACE ID is required");        synchronized (aces) {            for (int i = 0; i < aces.size(); i++) {                AccessControlEntry ace = (AccessControlEntry) aces.get(i);                if (ace.getId().equals(aceId)) {                    return i;                }            }        }        return -1;    }    public AccessControlEntry[] getEntries() {        // Can safely return AccessControlEntry directly, as they're immutable outside the ACL package        return (AccessControlEntry[]) aces.toArray(new AccessControlEntry[] {});    }    public Serializable getId() {        return this.id;    }    public ObjectIdentity getObjectIdentity() {        return objectIdentity;    }    public Sid getOwner() {        return this.owner;    }    public Acl getParentAcl() {        return parentAcl;    }    public void insertAce(Serializable afterAceId, Permission permission, Sid sid, boolean granting)        throws NotFoundException {        aclAuthorizationStrategy.securityCheck(this, AclAuthorizationStrategy.CHANGE_GENERAL);        Assert.notNull(permission, "Permission required");        Assert.notNull(sid, "Sid required");        AccessControlEntryImpl ace = new AccessControlEntryImpl(null, this, sid, permission, granting, false, false);        synchronized (aces) {            if (afterAceId != null) {                int offset = findAceOffset(afterAceId);                if (offset == -1) {                    throw new NotFoundException("Requested ACE ID not found");                }                this.aces.add(offset + 1, ace);            } else {                this.aces.add(ace);            }        }    }    public boolean isEntriesInheriting() {        return entriesInheriting;    }    /**     * Determines authorization.  The order of the <code>permission</code> and <code>sid</code> arguments is     * <em>extremely important</em>! The method will iterate through each of the <code>permission</code>s in the order     * specified. For each iteration, all of the <code>sid</code>s will be considered, again in the order they are     * presented. A search will then be performed for the first {@link AccessControlEntry} object that directly     * matches that <code>permission:sid</code> combination. When the <em>first full match</em> is found (ie an ACE     * that has the SID currently being searched for and the exact permission bit mask being search for), the grant or     * deny flag for that ACE will prevail. If the ACE specifies to grant access, the method will return

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -