Results 1 to 5 of 5

Thread: ACL database schema creation

  1. #1
    Join Date
    Jan 2009
    Posts
    2

    Default ACL database schema creation

    Hello,

    I want to create those 4 tables for acl jbbc based authorization in case they are not in db. It's a web application that makes use of acl module.
    There are annotated classes that make up db schema and the schema is get updated on application start if any changes are made to those classes or if db schema itself is different.

    Is it possible to do same thing for acl module tables? Please advise how to do this? (perhaps using some hbm files for this...)

    Any help would be appreciated.
    Thanks!

  2. #2

    Default Part 1

    AclClass.java

    Code:
    package com.x.y.model;
    
    import java.util.List;
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.OneToMany;
    import javax.persistence.OrderBy;
    import org.appfuse.model.BaseObject;
    import org.hibernate.annotations.IndexColumn;
    
    /**
     *
     * @author jvance
     */
    @Entity(name="acl_class")
    public class AclClass extends BaseObject{
        private Long id;
        private String aclClass; //class of course is a reserved word!
        private List<AclObjectIdentity> AclObjectIdentities;
    
        @Column(name="acl_class", length=256, nullable=true)
        public String getAclClass() {
            return aclClass;
        }
    
        public void setAclClass(String aclClass) {
            this.aclClass = aclClass;
        }
    
        @Id @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name="id")
        public Long getId() {
            return id;
        }
    
        public void setId(Long id) {
            this.id = id;
        }
    
        @OneToMany(
            cascade = {CascadeType.ALL},
            fetch = FetchType.EAGER
        )
        @JoinColumn(name="object_id_class")
        @OrderBy("objectIdentity")
        public List<AclObjectIdentity> getAclObjectIdentities() {
            return AclObjectIdentities;
        }
    
        public void setAclObjectIdentities(List<AclObjectIdentity> AclObjectIdentities) {
            this.AclObjectIdentities = AclObjectIdentities;
        }
    
        
        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final AclClass other = (AclClass) obj;
            if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
                return false;
            }
            if (this.aclClass != other.aclClass && (this.aclClass == null || !this.aclClass.equals(other.aclClass))) {
                return false;
            }
            return true;
        }
    
        @Override
        public int hashCode() {
            int hash = 5;
            hash = 59 * hash + (this.id != null ? this.id.hashCode() : 0);
            hash = 59 * hash + (this.aclClass != null ? this.aclClass.hashCode() : 0);
            return hash;
        }
        @Override
        public String toString(){
            return "Class: " + aclClass;
        }
    }
    AclSid.java

    Code:
    package com.x.y.model;
    
    import java.util.List;
    import java.util.Map;
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import org.appfuse.model.BaseObject;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.MapKey;
    import javax.persistence.OneToMany;
    import javax.persistence.OrderBy;
    import org.hibernate.annotations.IndexColumn;
    
    
    /**
     *
     * @author jvance
     */
    @Entity(name="acl_sid")
    public class AclSid extends BaseObject{
        private Long id;
        private Boolean principal;
        private String sid;
        private List<AclObjectIdentity> objectIdentities;
        private List<AclEntry> aclEntries;
    
        @Override
        public String toString() {
            return("ID: " + id + " SID: " + sid);
        }
    
        @Id @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name="id")
        public Long getId() {
            return id;
        }
    
        public void setId(Long id) {
            this.id = id;
        }
    
        @Column(name="principal", nullable=false)
        public Boolean getPrincipal() {
            return principal;
        }
    
        public void setPrincipal(Boolean principal) {
            this.principal = principal;
        }
    
        @Column(name="sid", length=256, nullable=false)
        public String getSid() {
            return sid;
        }
    
        public void setSid(String sid) {
            this.sid = sid;
        }
    
        @OneToMany(
            cascade = {CascadeType.ALL},
            fetch = FetchType.LAZY
        )
        @JoinColumn(name="sid")
        public List<AclEntry> getAclEntries() {
            return aclEntries;
        }
    
        public void setAclEntries(List<AclEntry> aclEntries) {
            this.aclEntries = aclEntries;
        }
    
        @OneToMany(
            cascade = {CascadeType.ALL},
            fetch = FetchType.LAZY
        )
        @JoinColumn(name="owner_sid")
        public List<AclObjectIdentity> getObjectIdentities() {
            return objectIdentities;
        }
    
        public void setObjectIdentities(List<AclObjectIdentity> objectIdentities) {
            this.objectIdentities = objectIdentities;
        }
    
        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final AclSid other = (AclSid) obj;
            if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
                return false;
            }
            if (this.principal != other.principal && (this.principal == null || !this.principal.equals(other.principal))) {
                return false;
            }
            if (this.sid != other.sid && (this.sid == null || !this.sid.equals(other.sid))) {
                return false;
            }
            return true;
        }
    
        @Override
        public int hashCode() {
            int hash = 7;
            hash = 17 * hash + (this.id != null ? this.id.hashCode() : 0);
            hash = 17 * hash + (this.principal != null ? this.principal.hashCode() : 0);
            hash = 17 * hash + (this.sid != null ? this.sid.hashCode() : 0);
            return hash;
        }
    Last edited by John Vance; Jan 9th, 2009 at 05:07 PM. Reason: Paste error - missed most of AclClass

  3. #3

    Default Part 2

    AclObjectIdentity.java

    Code:
    /*
     * This object is not intended to replace org.springframework.security.acls.objectidentity
     * It is used for Hibernate access to the ACL tables to allow "hand" administration of
     * ACLs
     */
    
    package com.x.y.model;
    
    import com.pnm.ERM.model.AclClass;
    import java.util.List;
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.FetchType;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.OneToMany;
    import javax.persistence.OrderBy;
    import org.appfuse.model.BaseObject;
    import org.hibernate.annotations.IndexColumn;
    
    
    
    
    /**
     *
     * @author jvance
     */
    @Entity(name="acl_object_identity")
    public class AclObjectIdentity extends BaseObject{
        private Long id;
        private Long objectIdentity;
        private Long objectClassId;
        private Long parentObject;
        private Boolean inheriting;
        private List<AclEntry> AclEntries;
        private Long ownerSidId;
        private AclSid ownerSid;
        private AclClass objectClass;
        
        @Override
        public String toString(){
            return "ID: " + id + " Class: " + objectClass.toString() + " ID: " + objectIdentity.toString();
        }
        
        @Id @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name="id")
        public Long getId() {
            return id;
        }
    
        public void setId(Long id) {
            this.id = id;
        }
    
        @Column(name="inheriting", nullable=false)
        public Boolean getInheriting() {
            return inheriting;
        }
    
        public void setInheriting(Boolean inheriting) {
            this.inheriting = inheriting;
        }
    
        @Column(name="object_id_class", nullable=false)
        public Long getObjectClassId() {
            return objectClassId;
        }
    
        public void setObjectClassId(Long objectClassId) {
            this.objectClassId = objectClassId;
        }
    
    
        @ManyToOne
        @JoinColumn(name="object_id_class", nullable=false, updatable=false, insertable=false)
        public AclClass getObjectClass(){
            return objectClass;
        }
        
        public void setObjectClass(AclClass objectClass){
            this.objectClass = objectClass;
        }
    
        @Column(name="object_id_identity", nullable=false)
        public Long getObjectIdentity() {
            return objectIdentity;
        }
    
        public void setObjectIdentity(Long objectIdentity) {
            this.objectIdentity = objectIdentity;
        }
    
        @Column(name="owner_sid", nullable=false)
        public Long getOwnerSidId() {
            return ownerSidId;
        }
    
        public void setOwnerSidId(Long ownerSidId) {
            this.ownerSidId = ownerSidId;
        }
    
        
        @ManyToOne
        @JoinColumn(name="owner_sid", nullable=false, updatable=false, insertable=false)
        public AclSid getOwnerSid(){
            return ownerSid;
        }
        
        public void setOwnerSid(AclSid ownerSid){
            this.ownerSid = ownerSid;
        }
    
        @Column(name="parent_object")
        public Long getParentObject() {
            return parentObject;
        }
    
        public void setParentObject(Long parentObject) {
            this.parentObject = parentObject;
        }
    
        @OneToMany(
            cascade = {CascadeType.ALL},
            fetch = FetchType.LAZY
        )
        @JoinColumn(name="acl_object_identity")
        @OrderBy("order")
        public List<AclEntry> getAclEntries() {
            return AclEntries;
        }
    
        public void setAclEntries(List<AclEntry> AclEntries) {
            this.AclEntries = AclEntries;
        }
    
        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final AclObjectIdentity other = (AclObjectIdentity) obj;
            if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
                return false;
            }
            if (this.objectIdentity != other.objectIdentity && (this.objectIdentity == null || !this.objectIdentity.equals(other.objectIdentity))) {
                return false;
            }
            if (this.parentObject != other.parentObject && (this.parentObject == null || !this.parentObject.equals(other.parentObject))) {
                return false;
            }
            if (this.ownerSid != other.ownerSid && (this.ownerSid == null || !this.ownerSid.equals(other.ownerSid))) {
                return false;
            }
            if (this.objectClass != other.objectClass && (this.objectClass == null || !this.objectClass.equals(other.objectClass))) {
                return false;
            }
            return true;
        }
    
        @Override
        public int hashCode() {
            int hash = 5;
            hash = 61 * hash + (this.id != null ? this.id.hashCode() : 0);
            hash = 61 * hash + (this.objectIdentity != null ? this.objectIdentity.hashCode() : 0);
            hash = 61 * hash + (this.parentObject != null ? this.parentObject.hashCode() : 0);
            hash = 61 * hash + (this.ownerSid != null ? this.ownerSid.hashCode() : 0);
            hash = 61 * hash + (this.objectClass != null ? this.objectClass.hashCode() : 0);
            return hash;
        }
    
        
    
        
    }
    AclEntry.java

    Code:
    package com.x.y.model;
    
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import org.appfuse.model.BaseObject;
    
    /**
     *
     * @author jvance
     */
    @Entity(name="acl_entry")
    public class AclEntry extends BaseObject{
        
        private Long id;
        private Long order;
        private Long mask;
        private Boolean auditFailure;
        private Boolean auditSuccess;
        private Boolean granting;
        private Long objectIdentityId;
        private AclObjectIdentity objectIdentity;
        private Long sidId;
        private AclSid sid;
    
        @Id @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name="id")
        public Long getId() {
            return id;
        }
    
        public void setId(Long id) {
            this.id = id;
        }
    
    
        @Column(name="audit_failure", nullable=false)
        public Boolean getAuditFailure() {
            return auditFailure;
        }
    
        public void setAuditFailure(Boolean auditFailure) {
            this.auditFailure = auditFailure;
        }
    
        @Column(name="audit_success", nullable=false)
        public Boolean getAuditSuccess() {
            return auditSuccess;
        }
    
        public void setAuditSuccess(Boolean auditSuccess) {
            this.auditSuccess = auditSuccess;
        }
    
        @Column(name="granting", nullable=false)
        public Boolean getGranting() {
            return granting;
        }
    
        public void setGranting(Boolean granting) {
            this.granting = granting;
        }
    
        @Column(name="mask", nullable=false)
        public Long getMask() {
            return mask;
        }
    
        public void setMask(Long mask) {
            this.mask = mask;
        }
    
        @ManyToOne
        @JoinColumn(name="acl_object_identity", nullable=false, insertable=false, updatable=false)
        public AclObjectIdentity getObjectIdentity() {
            return objectIdentity;
        }
        
        public void setObjectIdentity(AclObjectIdentity objectIdentity) {
            this.objectIdentity = objectIdentity;
        }
        
        // This field is needed to allow postback
        @Column(name="acl_object_identity", nullable=false)
        public Long getObjectIdentityId() {
            return objectIdentityId;
        }
    
        public void setObjectIdentityId(Long objectIdentityId) {
            this.objectIdentityId = objectIdentityId;
        }
    
        @ManyToOne
        @JoinColumn(name="sid", nullable=false, updatable=false, insertable=false)
        public AclSid getSid() {
            return sid;
        }
        
        public void setSid(AclSid sid){
            this.sid = sid;
        }
    
        @Column(name="sid", nullable=false)
        public Long getSidId() {
            return sidId;
        }
    
        public void setSidId(Long sidId) {
            this.sidId = sidId;
        }
        
        @Column(name="ace_order", nullable=false)
        public Long getOrder() {
            return order;
        }
    
        public void setOrder(Long order) {
            this.order = order;
    
        }
    
        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final AclEntry other = (AclEntry) obj;
            if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
                return false;
            }
            if (this.order != other.order && (this.order == null || !this.order.equals(other.order))) {
                return false;
            }
            if (this.mask != other.mask && (this.mask == null || !this.mask.equals(other.mask))) {
                return false;
            }
            return true;
        }
    
        @Override
        public int hashCode() {
            int hash = 7;
            hash = 79 * hash + (this.id != null ? this.id.hashCode() : 0);
            hash = 79 * hash + (this.order != null ? this.order.hashCode() : 0);
            hash = 79 * hash + (this.mask != null ? this.mask.hashCode() : 0);
            return hash;
        }
    
    
        public String toString(){
            return "Object: " + objectIdentity.getId().toString() + " Owner: " + sid.getSid();
        }
    
    }

  4. #4

    Default Part 3

    And of course the Appfuse BaseObject:

    Code:
    package org.appfuse.model;
    
    import java.io.Serializable;
    
    
    /**
     * Base class for Model objects. Child objects should implement toString(),
     * equals() and hashCode().
     * 
     * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
     */
    public abstract class BaseObject implements Serializable {    
    
        /**
         * Returns a multi-line String with key=value pairs.
         * @return a String representation of this class.
         */
        public abstract String toString();
    
        /**
         * Compares object equality. When using Hibernate, the primary key should
         * not be a part of this comparison.
         * @param o object to compare to
         * @return true/false based on equality tests
         */
        public abstract boolean equals(Object o);
    
        /**
         * When you override equals, you should override hashCode. See "Why are
         * equals() and hashCode() importation" for more information:
         * http://www.hibernate.org/109.html
         * @return hashCode
         */
        public abstract int hashCode();
    }
    I'm not placing any copyright on this code - BaseObject isn't mine, and the other objects structure is finely constrained by Spring Security and Hibernate and thus likely not copyrightable anyway. Have at it!

  5. #5
    Join Date
    Jan 2009
    Posts
    2

    Default

    Hi,

    Thank you for your reply, it was very helpful!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •