[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model ...

Christian Bauer christian at hibernate.org
Sun Mar 18 11:44:37 EDT 2007


  User: cbauer  
  Date: 07/03/18 11:44:37

  Modified:    examples/wiki/src/main/org/jboss/seam/wiki/core/model       
                        Document.java Node.java User.java Directory.java
                        Role.java HistoricalNode.hbm.xml
                        GlobalPreferences.java
  Log:
  Basic access level/role security, automatic home page for activated users
  
  Revision  Changes    Path
  1.2       +2 -0      jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Document.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Document.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Document.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- Document.java	7 Mar 2007 18:37:35 -0000	1.1
  +++ Document.java	18 Mar 2007 15:44:37 -0000	1.2
  @@ -1,11 +1,13 @@
   package org.jboss.seam.wiki.core.model;
   
   import org.hibernate.validator.Length;
  +import org.jboss.seam.annotations.security.Restrict;
   
   import javax.persistence.*;
   
   @Entity
   @DiscriminatorValue("DOCUMENT")
  + at Restrict
   public class Document extends Node {
   
       @Column(name = "CONTENT")
  
  
  
  1.4       +27 -5     jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Node.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Node.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Node.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- Node.java	8 Mar 2007 17:50:59 -0000	1.3
  +++ Node.java	18 Mar 2007 15:44:37 -0000	1.4
  @@ -2,6 +2,7 @@
   
   import org.hibernate.validator.Length;
   import org.hibernate.validator.Pattern;
  +import org.jboss.seam.annotations.security.Restrict;
   
   import javax.persistence.*;
   import java.util.List;
  @@ -24,6 +25,15 @@
       name = "NODE_TYPE",
       length = 255
   )
  + at Restrict
  + at org.hibernate.annotations.FilterDef(
  +    name = "accessLevelFilter",
  +    parameters = {@org.hibernate.annotations.ParamDef(name = "currentAccessLevel", type="integer")}
  +)
  + at org.hibernate.annotations.Filter(
  +    name = "accessLevelFilter",
  +    condition = "READ_ACCESS_LEVEL <= :currentAccessLevel"
  +)
   public abstract class Node implements Serializable {
   
       // Uses Hibernates ability to map the same class twice, see HistoricalNode.hbm.xml
  @@ -60,11 +70,15 @@
       @JoinColumn(name = "PARENT_NODE_ID", nullable = true, insertable = false, updatable = false)
       protected Node parent;
   
  -    @OneToMany(cascade = CascadeType.PERSIST)
  +    @OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
       @JoinColumn(name = "PARENT_NODE_ID", nullable = true)
       @org.hibernate.annotations.IndexColumn(name = "NODE_POSITION")
  -    // TODO: We are not really using this: @org.hibernate.annotations.Filter(name = "Node.onlyMenuItems")
  -    @org.hibernate.annotations.BatchSize(size = 5)
  +    /* Filtering fucks up the list index... big issue to work around
  +    @org.hibernate.annotations.Filter(
  +        name = "accessLevelFilter",
  +        condition = "READ_ACCESS_LEVEL <= :currentAccessLevel"
  +    )
  +    */
       private List<Node> children = new ArrayList<Node>();
   
       @Column(name = "CREATED_ON", nullable = false, updatable = false)
  @@ -81,11 +95,14 @@
       @JoinColumn(name = "LAST_MODIFIED_BY_USER_ID")
       protected User lastModifiedBy;
   
  +    @Transient
  +    protected String lastModifiedByUsername;
  +
       @Column(name = "WRITE_ACCESS_LEVEL", nullable = false)
  -    protected int writeAccessLevel = 1000;
  +    protected int writeAccessLevel;
   
       @Column(name = "READ_ACCESS_LEVEL", nullable = false)
  -    protected int readAccessLevel = 1000;
  +    protected int readAccessLevel;
   
       public Node() {}
   
  @@ -104,6 +121,7 @@
           this.name = original.name;
           this.wikiname = original.wikiname;
           this.lastModifiedOn = original.lastModifiedOn;
  +        this.lastModifiedByUsername = original.lastModifiedBy != null ? original.lastModifiedBy.getUsername() : null;
       }
   
       // Immutable properties
  @@ -197,6 +215,10 @@
           this.lastModifiedBy = lastModifiedBy;
       }
   
  +    public String getLastModifiedByUsername() {
  +        return lastModifiedByUsername;
  +    }
  +
       public int getWriteAccessLevel() {
           return writeAccessLevel;
       }
  
  
  
  1.2       +17 -20    jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/User.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: User.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/User.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- User.java	7 Mar 2007 18:37:35 -0000	1.1
  +++ User.java	18 Mar 2007 15:44:37 -0000	1.2
  @@ -4,6 +4,7 @@
   import org.hibernate.validator.Pattern;
   import org.hibernate.validator.Length;
   import org.hibernate.validator.Email;
  +import org.jboss.seam.annotations.security.Restrict;
   
   import javax.persistence.*;
   import java.io.Serializable;
  @@ -36,8 +37,8 @@
       @Column(name = "USERNAME", length = 16, nullable = false, unique = true)
       @NotNull
       @Length(min = 3, max = 16)
  -    @Pattern(regex="[a-zA-Z]?[a-zA-Z0-9_]+",
  -          message="Member name must start with a letter, and only contain letters, numbers or underscores")
  +    @Pattern(regex="[a-zA-Z]?[a-zA-Z0-9]+",
  +          message="Member name must start with a letter, and only contain letters and numbers")
       private String username; // Unique and immutable
   
       @Column(name = "PASSWORDHASH", length = 255, nullable = false)
  @@ -56,14 +57,18 @@
       @Column(name = "CREATED_ON", nullable = false, updatable = false)
       private Date createdOn = new Date();
   
  -    @ManyToMany(fetch = FetchType.EAGER)
  +    @ManyToMany(fetch = FetchType.LAZY) // Lazy so our @OrderBy works
       @JoinTable(
           name = "USER_ROLE",
           joinColumns = @JoinColumn(name = "USER_ID"),
           inverseJoinColumns = @JoinColumn(name = "ROLE_ID")
       )
  -    @org.hibernate.annotations.Sort(type = org.hibernate.annotations.SortType.NATURAL)
  -    private SortedSet<Role> roles = new TreeSet<Role>();
  +    @OrderBy("accessLevel desc, displayName asc")
  +    private List<Role> roles = new ArrayList<Role>();
  +
  +    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
  +    @JoinColumn(name = "MEMBER_HOME_NODE_ID")
  +    private Directory memberHome;
   
       public User() {}
   
  @@ -105,16 +110,15 @@
       public String getActivationCode() { return activationCode; }
       public void setActivationCode(String activationCode) { this.activationCode = activationCode; }
   
  -    public SortedSet<Role> getRoles() {
  -        return Collections.unmodifiableSortedSet(roles);
  -    }
  +    public Directory getMemberHome() { return memberHome; }
  +    public void setMemberHome(Directory memberHome) { this.memberHome = memberHome; }
   
  -    public void addRole(Role role) {
  -        this.roles.add(role);
  +    public List<Role> getRoles() {
  +        return roles;
       }
   
  -    public void removeRole(Role role) {
  -        this.roles.remove(role);
  +    public void setRoles(List<Role> roles) {
  +        this.roles = roles;
       }
   
       // Misc methods
  @@ -124,13 +128,6 @@
                   "Username: '" + getUsername() + "'";
       }
   
  -    public Role getHighestRole() {
  -        Role highestRole = roles.iterator().next();
  -        for (Role role : roles)
  -            if (role.getAccessLevel() > highestRole.getAccessLevel()) highestRole = role;
  -        return highestRole;
  -    }
  -
   }
   
   
  
  
  
  1.2       +8 -1      jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Directory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Directory.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Directory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- Directory.java	7 Mar 2007 18:37:35 -0000	1.1
  +++ Directory.java	18 Mar 2007 15:44:37 -0000	1.2
  @@ -6,7 +6,7 @@
   @DiscriminatorValue("DIRECTORY")
   public class Directory extends Node {
   
  -    @ManyToOne(fetch = FetchType.LAZY)
  +    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
       @JoinColumn(name = "DEFAULT_DOCUMENT_ID", nullable = true)
       private Document defaultDocument;
   
  @@ -18,6 +18,13 @@
   
       // Mutable properties
   
  +    /**
  +     * Careful calling this, it always returns the assigned Document, even if
  +     * the user has a lower access level. Hibernate filters don't filter many-to-one
  +     * because if we have the id, we get the instance.
  +     *
  +     * @return Document The assigned default starting document of this directory
  +     */
       public Document getDefaultDocument() {
           return defaultDocument;
       }
  
  
  
  1.3       +44 -2     jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Role.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Role.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/Role.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- Role.java	8 Mar 2007 10:44:16 -0000	1.2
  +++ Role.java	18 Mar 2007 15:44:37 -0000	1.3
  @@ -26,10 +26,18 @@
       @Length(min = 3, max = 40)
       private String displayName;
   
  -    @Column(name = "ACCESS_LEVEL", nullable = false, unique = true)
  +    @Column(name = "ACCESS_LEVEL", nullable = false)
       @org.hibernate.annotations.Check(
           constraints = "ACCESS_LEVEL <= 1000"
       )
  +
  +    // TODO: WTF?
  +    /*
  +    Caused by: java.lang.annotation.AnnotationTypeMismatchException:
  +    Incorrectly typed data found for annotation element
  +    public abstract long org.hibernate.validator.Max.value() (Found data of type class java.lang.Integer[1000])
  +     */
  +    //@org.hibernate.validator.Max(1000)
       private int accessLevel;
   
       @Column(name = "CREATED_ON", nullable = false, updatable = false)
  @@ -62,10 +70,44 @@
   
       public String toString() {
           return  "Role ('" + getId() + "'), " +
  +                "Access Level: '" + getAccessLevel() + "' " +
                   "Name: '" + getName() + "'";
       }
   
       public int compareTo(Object o) {
  -        return getDisplayName().compareTo(((Role)o).getDisplayName());
  +        return Integer.valueOf(getAccessLevel()).compareTo(((Role)o).getAccessLevel());
  +    }
  +
  +    /**
  +     * Used for aggregation of Role objects, by access level.
  +     * Also used in security checks as a handle passed into working memory.
  +     */
  +    public static class AccessLevel implements Serializable {
  +        private Integer accessLevel;
  +        private String roleNames;
  +        public AccessLevel(Integer accessLevel) {
  +            this.accessLevel = accessLevel;
  +        }
  +        public AccessLevel(Integer accessLevel, String roleNames) {
  +            this.accessLevel = accessLevel;
  +            this.roleNames = roleNames;
       }
  +        public Integer getAccessLevel() { return accessLevel; }
  +        public String getRoleNames() { return roleNames; }
  +        public void setRoleNames(String roleNames) { this.roleNames = roleNames; }
  +
  +        public boolean equals(Object o) {
  +            if (this == o) return true;
  +            if (o == null || getClass() != o.getClass()) return false;
  +            AccessLevel that = (AccessLevel) o;
  +            return accessLevel.equals(that.accessLevel);
  +        }
  +        public int hashCode() {
  +            return accessLevel.hashCode();
  +        }
  +        public void appendRoleName(String roleName) {
  +            roleNames = roleNames + ", " + roleName;
  +        }
  +    }
  +
   }
  
  
  
  1.2       +1 -0      jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/HistoricalNode.hbm.xml
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HistoricalNode.hbm.xml
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/HistoricalNode.hbm.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- HistoricalNode.hbm.xml	7 Mar 2007 18:37:35 -0000	1.1
  +++ HistoricalNode.hbm.xml	18 Mar 2007 15:44:37 -0000	1.2
  @@ -24,6 +24,7 @@
           <property name="name" length="255" not-null="true" column="NAME"/>
           <property name="wikiname" length="255" not-null="true" column="WIKINAME"/>
           <property name="lastModifiedOn" column="LAST_MODIFIED_ON" type="timestamp" not-null="true"/>
  +        <property name="lastModifiedByUsername" column="LAST_MODIFIED_BY_USERNAME" not-null="false"/>
   
           <subclass name="Document" entity-name="HistoricalDocument" discriminator-value="DOCUMENT">
               <property name="content" column="CONTENT" length="32768"/>
  
  
  
  1.2       +18 -0     jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/GlobalPreferences.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: GlobalPreferences.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/model/GlobalPreferences.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- GlobalPreferences.java	7 Mar 2007 18:37:35 -0000	1.1
  +++ GlobalPreferences.java	18 Mar 2007 15:44:37 -0000	1.2
  @@ -6,6 +6,8 @@
       private String baseURL;
       private URLRendering defaultURLRendering;
       private String permlinkSuffix;
  +    private Long defaultDocumentId;
  +    private Long memberAreaId;
       private String themeName;
       private String newUserInRole;
       private String passwordRegex;
  @@ -36,6 +38,22 @@
           this.permlinkSuffix = permlinkSuffix;
       }
   
  +    public Long getDefaultDocumentId() {
  +        return defaultDocumentId;
  +    }
  +
  +    public void setDefaultDocumentId(Long defaultDocumentId) {
  +        this.defaultDocumentId = defaultDocumentId;
  +    }
  +
  +    public Long getMemberAreaId() {
  +        return memberAreaId;
  +    }
  +
  +    public void setMemberAreaId(Long memberAreaId) {
  +        this.memberAreaId = memberAreaId;
  +    }
  +
       public String getThemeName() {
           return themeName;
       }
  
  
  



More information about the jboss-cvs-commits mailing list