[seam-commits] Seam SVN: r12269 - in modules/security/trunk/examples/seamspace: src/main/java/org/jboss/seam/security/examples/seamspace and 4 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Mar 25 02:53:42 EDT 2010


Author: shane.bryzak at jboss.com
Date: 2010-03-25 02:53:40 -0400 (Thu, 25 Mar 2010)
New Revision: 12269

Added:
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/BlogAction.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/CommentAction.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/ContentAction.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/FriendAction.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/HashGenerator.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/ImagePermission.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/PictureAction.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/PictureSearch.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/ProfileAction.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/RegisterAction.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/AccountPermission.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/BlogComment.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/FriendComment.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/Member.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberAccount.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberBlog.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberFriend.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberImage.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberRole.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/util/
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/util/AuthenticationEvents.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/util/ContentServlet.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/util/Hash.java
   modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/beans.xml
Removed:
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/AccountPermission.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/AuthenticationEvents.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/BlogAction.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/BlogComment.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/CommentAction.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ContentAction.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ContentServlet.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/FriendAction.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/FriendComment.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/Hash.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/HashGenerator.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ImagePermission.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/Member.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberAccount.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberBlog.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberFriend.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberImage.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberRole.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/PictureAction.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/PictureSearch.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ProfileAction.java
   modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/RegisterAction.java
Modified:
   modules/security/trunk/examples/seamspace/pom.xml
Log:
tidy up project structure, add dependencies, fix some compiler errors


Modified: modules/security/trunk/examples/seamspace/pom.xml
===================================================================
--- modules/security/trunk/examples/seamspace/pom.xml	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/pom.xml	2010-03-25 06:53:40 UTC (rev 12269)
@@ -52,11 +52,21 @@
       <dependency>
          <groupId>javax.validation</groupId>
          <artifactId>validation-api</artifactId>
+         <version>1.0.0.GA</version>
       </dependency>
 
       <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>servlet-api</artifactId>
+         <version>2.5</version>
+         <scope>provided</scope>
+      </dependency> 
+
+      <dependency>
+         <groupId>javax.faces</groupId>
+         <artifactId>jsf-api</artifactId>
+         <version>2.0.2-FCS</version>
+         <scope>provided</scope>
       </dependency>
    </dependencies>
    

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/AccountPermission.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/AccountPermission.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/AccountPermission.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,81 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.io.Serializable;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-
-import org.jboss.seam.security.annotations.permission.PermissionAction;
-import org.jboss.seam.security.annotations.permission.PermissionDiscriminator;
-import org.jboss.seam.security.annotations.permission.PermissionRole;
-import org.jboss.seam.security.annotations.permission.PermissionTarget;
-import org.jboss.seam.security.annotations.permission.PermissionUser;
-
- at Entity
-public class AccountPermission implements Serializable
-{
-   private static final long serialVersionUID = -5628863031792429938L;
-   
-   private Integer permissionId;
-   private String recipient;
-   private String target;
-   private String action;
-   private String discriminator;
-   
-   @Id @GeneratedValue
-   public Integer getPermissionId()
-   {
-      return permissionId;
-   }
-   
-   public void setPermissionId(Integer permissionId)
-   {
-      this.permissionId = permissionId;
-   }
-   
-   @PermissionUser 
-   @PermissionRole
-   public String getRecipient()
-   {
-      return recipient;
-   }
-   
-   public void setRecipient(String recipient)
-   {
-      this.recipient = recipient;
-   }
-   
-   @PermissionTarget
-   public String getTarget()
-   {
-      return target;
-   }
-   
-   public void setTarget(String target)
-   {
-      this.target = target;
-   }
-   
-   @PermissionAction
-   public String getAction()
-   {
-      return action;
-   }
-   
-   public void setAction(String action)
-   {
-      this.action = action;
-   }
-   
-   @PermissionDiscriminator
-   public String getDiscriminator()
-   {
-      return discriminator;
-   }
-   
-   public void setDiscriminator(String discriminator)
-   {
-      this.discriminator = discriminator;
-   }
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/AuthenticationEvents.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/AuthenticationEvents.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/AuthenticationEvents.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,15 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import javax.inject.Named;
-
-import org.jboss.seam.security.management.JpaIdentityStore;
-
- at Named
-public class AuthenticationEvents
-{
-   //@Observer(JpaIdentityStore.EVENT_USER_AUTHENTICATED)
-   public void loginSuccessful(MemberAccount account)
-   {
-     // Contexts.getSessionContext().set("authenticatedMember", account.getMember());
-   }
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/BlogAction.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/BlogAction.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/BlogAction.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,82 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.util.ArrayList;
-import java.util.Date;
-
-import javax.enterprise.context.Conversation;
-import javax.enterprise.context.ConversationScoped;
-import javax.enterprise.inject.Produces;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
-
- at Named("blog")
- at ConversationScoped
-public class BlogAction
-{    
-   private String name;   
-   private Integer blogId;
-   
-   @Inject EntityManager entityManager;
-   
-   @Inject MemberBlog selectedBlog;
-   
-   @Inject Member authenticatedMember;
-   
-   @Inject Conversation conversation;
-   
-   /**
-    * Used to read a single blog entry for a member
-    */   
-   public @Produces @Named("selectedBlog") MemberBlog getBlog()
-   {     
-      conversation.begin();
-      try
-      {
-         return (MemberBlog) entityManager.createQuery(
-           "from MemberBlog b where b.blogId = :blogId and b.member.memberName = :memberName")
-           .setParameter("blogId", blogId)
-           .setParameter("memberName", name)
-           .getSingleResult();
-      }
-      catch (NoResultException ex) { }
-   }   
-   
-   @Begin
-   public void createEntry()
-   {
-      selectedBlog = new MemberBlog();              
-   }
-   
-   public void saveEntry()
-   {
-      selectedBlog.setMember(authenticatedMember);
-      selectedBlog.setEntryDate(new Date());
-      selectedBlog.setComments(new ArrayList<BlogComment>());
-      
-      entityManager.persist(selectedBlog);
-      
-      conversation.end();
-   }
-   
-   public String getName()
-   {
-      return name;
-   }
-   
-   public void setName(String name)
-   {
-      this.name = name;
-   }
-   
-   public Integer getBlogId()
-   {
-      return blogId;
-   }
-   
-   public void setBlogId(Integer blogId)
-   {
-      this.blogId = blogId;
-   }
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/BlogComment.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/BlogComment.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/BlogComment.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,91 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.io.Serializable;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Transient;
-
-
- at Entity
-public class BlogComment implements Serializable
-{
-   private static final long serialVersionUID = 5495139096911872039L;
-
-   private static SimpleDateFormat df = new SimpleDateFormat("EEEE, MMMM d, yyyy 'at' hh:mm a");   
-   
-   private Integer commentId;
-   private MemberBlog blog;
-   private Member commentor;
-   private Date commentDate;
-   private String comment;
-   
-   @Id @GeneratedValue
-   public Integer getCommentId()
-   {
-      return commentId;
-   }
-   
-   public void setCommentId(Integer commentId)
-   {
-      this.commentId = commentId;
-   }   
-   
-   @ManyToOne
-   @JoinColumn(name = "BLOG_ID")
-   public MemberBlog getBlog()
-   {
-      return blog;
-   }
-   
-   public void setBlog(MemberBlog blog)
-   {
-      this.blog = blog;
-   }
-   
-   @NotNull
-   public String getComment()
-   {
-      return comment;
-   }
-   public void setComment(String comment)
-   {
-      this.comment = comment;
-   }
-   
-   @NotNull
-   public Date getCommentDate()
-   {
-      return commentDate;
-   }
-   
-   public void setCommentDate(Date commentDate)
-   {
-      this.commentDate = commentDate;
-   }
-   
-   @Transient
-   public String getFormattedCommentDate()
-   {
-     return df.format(commentDate);  
-   }
-
-   @ManyToOne
-   @JoinColumn(name = "COMMENTOR_ID")
-   public Member getCommentor()
-   {
-      return commentor;
-   }
-   
-   public void setCommentor(Member commentor)
-   {
-      this.commentor = commentor;
-   }
-  
-   
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/CommentAction.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/CommentAction.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/CommentAction.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,55 +0,0 @@
-package org.jboss.seam.example.seamspace;
-
-import static org.jboss.seam.ScopeType.CONVERSATION;
-
-import java.util.Date;
-
-import javax.persistence.EntityManager;
-
-import org.jboss.seam.annotations.Begin;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Transactional;
-import org.jboss.seam.annotations.security.Insert;
-import org.jboss.seam.core.Conversation;
-
- at Scope(CONVERSATION)
- at Name("commentAction")
- at Transactional
-public class CommentAction 
-{
-   @In
-   private EntityManager entityManager;
-   
-   private BlogComment comment;     
-   
-   @In(required = false)
-   private Member authenticatedMember;
-   
-   @In(required = false)
-   private MemberBlog selectedBlog;
-   
-   @Begin(nested = true) @Insert(BlogComment.class) 
-   public void createComment()
-   {            
-      comment = new BlogComment();
-      comment.setCommentor(authenticatedMember);              
-      comment.setBlog(selectedBlog);
-   }
-   
-   public void saveComment()
-   {      
-      comment.setCommentDate(new Date());
-      entityManager.persist(comment);
-            
-      entityManager.refresh(selectedBlog);
-      
-      Conversation.instance().end();
-   }    
-   
-   public BlogComment getComment()
-   {
-      return comment;
-   }
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ContentAction.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ContentAction.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ContentAction.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,24 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.persistence.EntityManager;
-
-import org.jboss.seam.security.Identity;
-
- at Named
-public class ContentAction
-{
-   @Inject EntityManager entityManager;
-   @Inject Identity identity;
-   
-   public MemberImage getImage(int imageId)
-   {
-      MemberImage img = entityManager.find(MemberImage.class, imageId);
-      
-      if (img == null || !identity.hasPermission(img, "view"))
-         return null;
-      else
-         return img;
-   }
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ContentServlet.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ContentServlet.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ContentServlet.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,136 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.imageio.ImageIO;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.swing.ImageIcon;
-
-
-/**
- * Serves images and other member content
- * 
- * @author Shane Bryzak
- */
-public class ContentServlet extends HttpServlet
-{
-   private static final long serialVersionUID = -8461940507242022217L;
-
-   private static final String IMAGES_PATH = "/images";
-
-   /**
-    * The maximum width allowed for image rescaling
-    */
-   private static final int MAX_IMAGE_WIDTH = 1024;
-   
-   private byte[] noImage;
-   
-   public ContentServlet()
-   {
-      InputStream in = getClass().getResourceAsStream("/images/no_image.png");
-      if (in != null)
-      {
-         ByteArrayOutputStream out = new ByteArrayOutputStream();
-         byte[] buffer = new byte[512];
-         try
-         {
-            int read = in.read(buffer);
-            while (read != -1)
-            {
-               out.write(buffer, 0, read);
-               read = in.read(buffer);
-            }
-            
-            noImage = out.toByteArray();
-         } 
-         catch (IOException e) { }
-      }
-      
-   }
-
-   @Override
-   protected void doGet(HttpServletRequest request, HttpServletResponse response)
-         throws ServletException, IOException
-   {
-      if (IMAGES_PATH.equals(request.getPathInfo()))
-      {
-         ContentAction contentAction = (ContentAction) Component.getInstance(ContentAction.class);
-
-         String id = request.getParameter("id");
-         MemberImage mi = (id != null && !"".equals(id)) ? 
-               contentAction.getImage(Integer.parseInt(id)) : null;
-         
-         String contentType = null;
-         byte[] data = null;
-         
-         if (mi != null && mi.getData() != null && mi.getData().length > 0)
-         {
-            contentType = mi.getContentType();
-            data = mi.getData();
-         }
-         else if (noImage != null)
-         {
-            contentType = "image/png";
-            data = noImage;
-         }
-         
-         if (data != null)
-         {
-            response.setContentType(contentType);
-   
-            boolean rescale = false;
-            int width = 0;
-            ImageIcon icon = null;
-   
-            // Check if the image needs to be rescaled
-            if (request.getParameter("width") != null)
-            {
-               width = Math.min(MAX_IMAGE_WIDTH, Integer.parseInt(request
-                     .getParameter("width")));
-               icon = new ImageIcon(data);
-               if (width > 0 && width != icon.getIconWidth())
-                  rescale = true;
-            }
-   
-            // Rescale the image if required
-            if (rescale)
-            {
-               double ratio = (double) width / icon.getIconWidth();
-               int height = (int) (icon.getIconHeight() * ratio);
-               
-               int imageType = "image/png".equals(contentType) ? 
-                     BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;                  
-               BufferedImage bImg = new BufferedImage(width, height, imageType);
-               Graphics2D g2d = bImg.createGraphics();
-               g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
-                     RenderingHints.VALUE_INTERPOLATION_BICUBIC);
-               g2d.drawImage(icon.getImage(), 0, 0, width, height, null);
-               g2d.dispose();
-   
-               String formatName = "";
-               if (contentType != null && contentType.indexOf("png") != -1)
-                  formatName = "png";
-               else if (contentType != null && (contentType.indexOf("jpg") != -1) ||
-                     contentType.indexOf("jpeg") != -1)
-                  formatName = "jpeg";
-   
-               ImageIO.write(bImg, formatName, response.getOutputStream());
-            }
-            else
-            {
-               response.getOutputStream().write(data);
-            }
-         }
-
-         response.getOutputStream().flush();
-      }
-   }
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/FriendAction.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/FriendAction.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/FriendAction.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,98 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.io.Serializable;
-import java.util.Date;
-
-import javax.ejb.Remove;
-import javax.enterprise.context.ConversationScoped;
-import javax.inject.Named;
-import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
-
-import org.jboss.seam.security.Identity;
-
- at Named
- at ConversationScoped
-public class FriendAction implements Serializable
-{
-   private static final long serialVersionUID = 4565339001481077911L;
-
-   @RequestParameter("name")
-   private String name;
-   
-   @Out(required = false)
-   private FriendComment friendComment;
-   
-   @Out(required = false)
-   private MemberFriend friendRequest;
-   
-   @In(required = false)
-   private Member authenticatedMember;
-      
-   @In
-   private EntityManager entityManager;
-      
-   @Factory("friendComment") @Begin
-   public void createComment()
-   {      
-      try
-      {
-         Member member = (Member) entityManager.createQuery(
-         "from Member where memberName = :memberName")
-         .setParameter("memberName", name)
-         .getSingleResult();
-                  
-         Contexts.getMethodContext().set("friends", member.getFriends());
-         Identity.instance().checkPermission(member, "createFriendComment");
-
-         friendComment = new FriendComment();
-         friendComment.setFriend(authenticatedMember);
-         friendComment.setMember(member);
-      }
-      catch (NoResultException ex) 
-      { 
-         FacesMessages.instance().add("Member not found.");
-      }
-   }
-   
-   @End
-   public void saveComment()
-   {
-      friendComment.setCommentDate(new Date());
-      entityManager.persist(friendComment);
-   }
-   
-   @Begin
-   public void createRequest()
-   {
-      try
-      {
-         Member member = (Member) entityManager.createQuery(
-         "from Member where memberName = :memberName")
-         .setParameter("memberName", name)
-         .getSingleResult();
-                  
-         Contexts.getMethodContext().set("friends", member.getFriends());
-         Identity.instance().checkPermission(member, "createFriendRequest");
-
-         friendRequest = new MemberFriend();
-         friendRequest.setFriend(authenticatedMember);
-         friendRequest.setMember(member);
-      }
-      catch (NoResultException ex) 
-      { 
-         FacesMessages.instance().add("Member not found.");
-      }
-   }
-
-   @End
-   public void saveRequest()
-   {
-      friendRequest.getMember().getFriends().add(friendRequest);
-      entityManager.persist(friendRequest);      
-      FacesMessages.instance().add("Friend request sent");      
-   }
-   
-   @Remove @Destroy
-   public void destroy() { }    
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/FriendComment.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/FriendComment.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/FriendComment.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,88 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.io.Serializable;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Transient;
-
- at Entity
-public class FriendComment implements Serializable
-{
-   private static final long serialVersionUID = -288494386341008371L;
-
-   private static SimpleDateFormat df = new SimpleDateFormat("d MMMM yyyy hh:mm a");   
-   
-   private Integer id;
-   private Member member;
-   private Member friend;
-   private Date commentDate;
-   private String comment;
-   
-   @Id @GeneratedValue
-   public Integer getId()
-   {
-      return id;
-   }
-   
-   public void setId(Integer id)
-   {
-      this.id = id;
-   }   
-   
-   public String getComment()
-   {
-      return comment;
-   }
-   
-   public void setComment(String comment)
-   {
-      this.comment = comment;
-   }
-   
-   public Date getCommentDate()
-   {
-      return commentDate;
-   }
-   
-   public void setCommentDate(Date commentDate)
-   {
-      this.commentDate = commentDate;
-   }
-   
-   @Transient
-   public String getFormattedCommentDate()
-   {
-     return df.format(commentDate);  
-   }   
-   
-   @ManyToOne
-   @JoinColumn(name = "FRIEND_ID")
-   public Member getFriend()
-   {
-      return friend;
-   }
-   
-   public void setFriend(Member friend)
-   {
-      this.friend = friend;
-   }
-      
-   @ManyToOne
-   @JoinColumn(name = "MEMBER_ID")
-   public Member getMember()
-   {
-      return member;
-   }
-   
-   public void setMember(Member member)
-   {
-      this.member = member;
-   }
-
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/Hash.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/Hash.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/Hash.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,38 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.security.MessageDigest;
-
-import org.jboss.seam.util.Hex;
-
-public class Hash {
-    String hashFunction = "MD5";
-    String charset      = "UTF-8";
-    
-    public String hash(String password) {
-        try {
-            MessageDigest md = MessageDigest.getInstance(hashFunction);
-            md.update(password.getBytes(charset));
-            byte[] raw = md.digest();
-            return new String(Hex.encodeHex(raw));
-        } 
-        catch (Exception e) {
-            throw new RuntimeException(e);        
-        }
-    }
-
-    public String getCharset() {
-        return charset;
-    }
-
-    public void setCharset(String charset) {
-        this.charset = charset;
-    }
-
-    public String getHashFunction() {
-        return hashFunction;
-    }
-
-    public void setHashFunction(String hashFunction) {
-        this.hashFunction = hashFunction;
-    }    
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/HashGenerator.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/HashGenerator.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/HashGenerator.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,77 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import javax.enterprise.inject.Model;
-import javax.inject.Inject;
-
-import org.jboss.seam.security.crypto.BinTools;
-import org.jboss.seam.security.management.JpaIdentityStore;
-import org.jboss.seam.security.management.PasswordHash;
-
- at Model
-public class HashGenerator
-{
-   @Inject JpaIdentityStore identityStore;
-   @Inject PasswordHash hash;
-   
-   private String password;
-   private String passwordHash;
-   private String passwordSalt;
-   
-   public String getPassword()
-   {
-      return password;
-   }
-   
-   public void setPassword(String password)
-   {
-      this.password = password;
-   }
-   
-   public String getPasswordHash()
-   {
-      return passwordHash;
-   }
-   
-   public void setPasswordHash(String passwordHash)
-   {
-      this.passwordHash = passwordHash;
-   }
-   
-   public String getPasswordSalt()
-   {
-      return passwordSalt;
-   }
-   
-   public void setPasswordSalt(String passwordSalt)
-   {
-      this.passwordSalt = passwordSalt;
-   }
-   
-   public void generate()
-   {
-      byte[] salt;
-      
-      if (passwordSalt == null || "".equals(passwordSalt.trim()))
-      {
-         salt = hash.generateRandomSalt();
-         passwordSalt = BinTools.bin2hex(salt);
-      }
-      else
-      {
-         salt = BinTools.hex2bin(passwordSalt);
-      }
-      
-      passwordHash = identityStore.generatePasswordHash(password, salt);
-   }
-   
-   public String getSql()
-   {
-      StringBuilder sb = new StringBuilder();
-      sb.append("INSERT INTO USER_ACCOUNT (username, password_hash, password_salt) values ('johnsmith', '");
-      sb.append(passwordHash);
-      sb.append("', '");
-      sb.append(passwordSalt);
-      sb.append("');");      
-      return sb.toString();
-   }
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ImagePermission.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ImagePermission.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ImagePermission.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,192 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.io.Serializable;
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.enterprise.inject.Model;
-import javax.persistence.EntityManager;
-
-import org.jboss.seam.security.Role;
-import org.jboss.seam.security.SimplePrincipal;
-import org.jboss.seam.security.management.IdentityManager;
-import org.jboss.seam.security.permission.Permission;
-import org.jboss.seam.security.permission.PermissionManager;
-import org.jboss.seam.security.permission.action.PermissionSearch;
-
- at Model
-public class ImagePermission implements Serializable
-{
-   private static final long serialVersionUID = -4943654157860780587L;
-
-   private List<String> selectedRoles;   
-   private List<Member> selectedFriends;
-   private List<String> selectedActions;
-   
-   private List<String> originalActions;
-   
-   private List<Member> availableFriends;   
-   
-   @In IdentityManager identityManager;
-   @In PermissionManager permissionManager;
-   
-   @In EntityManager entityManager;
-   
-   @In PermissionSearch permissionSearch;   
-   
-   private MemberImage target; 
-   
-   private Principal recipient;
-   
-   @SuppressWarnings("unchecked")
-   @Begin(nested = true)
-   public void createPermission()
-   {
-      target = (MemberImage) permissionSearch.getTarget();
-      
-      selectedFriends = new ArrayList<Member>();
-      
-      availableFriends = entityManager.createQuery(
-            "select f.friend from MemberFriend f where f.member = :member and f.authorized = true")
-            .setParameter("member", target.getMember())
-            .getResultList();      
-   }
-   
-   @Begin(nested = true)
-   public void editPermission()
-   {
-      target = (MemberImage) permissionSearch.getTarget();
-      recipient = permissionSearch.getSelectedRecipient();
-            
-      List<Permission> permissions = permissionManager.listPermissions(target);
-      
-      selectedActions = new ArrayList<String>();      
-      
-      for (Permission permission : permissions)
-      {
-         if (permission.getRecipient().equals(recipient))
-         {
-            if (!selectedActions.contains(permission.getAction()))
-            {
-               selectedActions.add(permission.getAction());
-            }
-         }
-      }
-      
-      originalActions = new ArrayList<String>(selectedActions);
-   }
-
-   public List<String> getSelectedRoles()
-   {
-      return selectedRoles;
-   }
-   
-   public void setSelectedRoles(List<String> selectedRoles)
-   {
-      this.selectedRoles = selectedRoles;
-   }
-   
-   public List<Member> getSelectedFriends()
-   {
-      return selectedFriends;
-   }
-   
-   public void setSelectedFriends(List<Member> selectedFriends)
-   {
-      this.selectedFriends = selectedFriends;
-   }
-   
-   public List<String> getSelectedActions()
-   {
-      return selectedActions;
-   }
-   
-   public void setSelectedActions(List<String> selectedActions)
-   {
-      this.selectedActions = selectedActions;
-   }
-   
-   public String applyPermissions()
-   {
-      // If the recipient isn't null, it means we're editing existing permissions
-      if (recipient != null)
-      {
-         List<Permission> grantedPermissions = new ArrayList<Permission>();
-         List<Permission> revokedPermissions = new ArrayList<Permission>();
-         
-         for (String action : selectedActions)
-         {
-            if (!originalActions.contains(action)) 
-            {
-               grantedPermissions.add(new Permission(target, action, recipient));
-            }
-         }
-         
-         for (String action : originalActions)
-         {
-            if (!selectedActions.contains(action))
-            {
-               revokedPermissions.add(new Permission(target, action, recipient));
-            }
-         }
-         
-         if (!grantedPermissions.isEmpty()) permissionManager.grantPermissions(grantedPermissions);
-         if (!revokedPermissions.isEmpty()) permissionManager.revokePermissions(revokedPermissions);
-      }
-      // otherwise this is a set of new permissions
-      else
-      {
-         if (selectedActions.size() == 0)
-         {
-            FacesMessages.instance().add("You must select at least one action");
-            return "failure";
-         }
-         
-         List<Permission> permissions = new ArrayList<Permission>();
-   
-         for (String role : selectedRoles)
-         {
-            Principal r = new Role(role);
-            for (String action : selectedActions)
-            {            
-               permissions.add(new Permission(target, action, r));
-            }
-         }
-         
-         for (Member friend : selectedFriends)
-         {
-            MemberAccount acct = (MemberAccount) entityManager.createQuery(
-                  "select a from MemberAccount a where a.member = :member")
-                  .setParameter("member", friend)
-                  .getSingleResult();
-            
-            Principal p = new SimplePrincipal(acct.getUsername());
-            
-            for (String action : selectedActions)
-            {
-               permissions.add(new Permission(target, action, p));
-            }
-         }
-         
-         permissionManager.grantPermissions(permissions);
-      }
-      Conversation.instance().endBeforeRedirect();
-      return "success";
-   }
-   
-   public List<Member> getAvailableFriends()
-   {
-      return availableFriends;
-   }
-   
-   public MemberImage getTarget()
-   {
-      return target;
-   }
-   
-   public Principal getRecipient()
-   {
-      return recipient;
-   }
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/Member.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/Member.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/Member.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,251 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.io.Serializable;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.Set;
-
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.OneToMany;
-import javax.persistence.OneToOne;
-import javax.persistence.Table;
-import javax.persistence.Transient;
-import javax.persistence.UniqueConstraint;
-
-import org.hibernate.validator.Email;
-import org.hibernate.validator.Length;
-import org.hibernate.validator.NotNull;
-import org.hibernate.validator.Pattern;
-import org.jboss.seam.annotations.Name;
-
-/**
- * A member account
- * 
- * @author Shane Bryzak
- */
- at Entity
- at Table(uniqueConstraints = @UniqueConstraint(columnNames = "membername"))
-public class Member implements Serializable
-{
-   private static final long serialVersionUID = 5179242727836683375L;
-   
-   public enum Gender {
-      male("Male", "his"), 
-      female("Female", "her");
-      
-     private String descr;
-     private String possessive;
-     
-     Gender(String descr, String possessive) {
-       this.descr = descr;
-       this.possessive = possessive;
-      }
-     public String getDescr() {
-        return descr;
-     }
-     
-     public String getPossessive() {
-        return possessive;
-     }
-   };
-   
-   private Integer memberId;
-   private String memberName;
-   private String firstName;
-   private String lastName;
-   private String email;
-   private MemberImage picture;
-   
-   private String tagline;
-   private Gender gender;
-   private Date dob;
-   private String location;
-   private Date memberSince;
-   
-   private Set<MemberImage> images;   
-   private Set<MemberFriend> friends;
-
-   @Id @GeneratedValue
-   public Integer getMemberId()
-   {
-      return memberId;
-   }
-
-   public void setMemberId(Integer memberId)
-   {
-      this.memberId = memberId;
-   }
-   
-   @NotNull
-   @Length(min = 3, max = 40)
-   @Pattern(regex="[a-zA-Z]?[a-zA-Z0-9_]+", 
-         message="Member name must start with a letter, and only contain letters, numbers or underscores")
-   public String getMemberName()
-   {
-      return memberName;
-   }
-
-   public void setMemberName(String memberName)
-   {
-      this.memberName = memberName;
-   }
-   
-   @NotNull
-   @Length(min = 3, max = 40)
-   @Pattern(regex="[a-zA-Z]+", message="First name must only contain letters")
-   public String getFirstName()
-   {
-      return firstName;
-   }
-   
-   public void setFirstName(String firstName)
-   {
-      this.firstName = firstName;
-   }
-   
-   @NotNull
-   @Length(min = 3, max = 40)
-   @Pattern(regex="[a-zA-Z]+", message="Last name must only contain letters")
-   public String getLastName()
-   {
-      return lastName;
-   }
-   
-   public void setLastName(String lastName)
-   {
-      this.lastName = lastName;
-   }   
-   
-   @NotNull @Email
-   public String getEmail()
-   {
-      return email;
-   }
-   
-   public void setEmail(String email)
-   {
-      this.email = email;
-   }
-
-   @OneToOne(fetch = FetchType.LAZY)
-   @JoinColumn(name = "PICTURE_ID")
-   public MemberImage getPicture()
-   {
-      return picture;
-   }
-
-   public void setPicture(MemberImage picture)
-   {
-      this.picture = picture;
-   }
-
-   @NotNull
-   public Date getDob()
-   {
-      return dob;
-   }
-
-   public void setDob(Date dob)
-   {
-      this.dob = dob;
-   }
-
-   @NotNull
-   public Gender getGender()
-   {
-      return gender;
-   }
-
-   public void setGender(Gender gender)
-   {
-      this.gender = gender;
-   }
-
-   public String getLocation()
-   {
-      return location;
-   }
-
-   public void setLocation(String location)
-   {
-      this.location = location;
-   }
-   
-   @NotNull
-   public Date getMemberSince()
-   {
-      return memberSince;
-   }
-   
-   public void setMemberSince(Date memberSince)
-   {
-      this.memberSince = memberSince;
-   }
-
-   public String getTagline()
-   {
-      return tagline;
-   }
-
-   public void setTagline(String tagline)
-   {
-      this.tagline = tagline;
-   }
-
-   @OneToMany(mappedBy = "member", fetch = FetchType.LAZY)
-   public Set<MemberImage> getImages()
-   {
-      return images;
-   }
-
-   public void setImages(Set<MemberImage> images)
-   {
-      this.images = images;
-   }
-   
-   @OneToMany(mappedBy = "member")
-   public Set<MemberFriend> getFriends()
-   {
-      return friends;
-   }
-   
-   public void setFriends(Set<MemberFriend> friends)
-   {
-      this.friends = friends;   
-   }
-   
-   @Transient
-   public boolean isFriend(Member member)
-   {
-      for (MemberFriend f : friends)
-      {
-         if (f.getFriend().getMemberId().equals(member.getMemberId())) return true;          
-      }
-      
-      return false;
-   }
-   
-   @Transient
-   public String getAge()
-   {
-      Calendar birthday = new GregorianCalendar();
-      birthday.setTime(dob);
-      int by = birthday.get(Calendar.YEAR);
-      int bm = birthday.get(Calendar.MONTH);
-      int bd = birthday.get(Calendar.DATE);
-      
-      Calendar now = new GregorianCalendar();
-      now.setTimeInMillis(System.currentTimeMillis());
-      int ny = now.get(Calendar.YEAR);
-      int nm = now.get(Calendar.MONTH);
-      int nd = now.get(Calendar.DATE);      
-      
-      int age = ny - by + (nm > bm || (nm == bm && nd >= bd) ? 0 : -1);                              
-      return String.format("%d years old", age);                              
-   }
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberAccount.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberAccount.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberAccount.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,120 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.io.Serializable;
-import java.util.Set;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
-import javax.persistence.ManyToMany;
-import javax.persistence.OneToOne;
-import javax.persistence.Table;
-import javax.persistence.UniqueConstraint;
-
-import org.hibernate.validator.NotNull;
-import org.jboss.seam.security.annotations.management.PasswordSalt;
-import org.jboss.seam.security.annotations.management.UserEnabled;
-import org.jboss.seam.security.annotations.management.UserPassword;
-import org.jboss.seam.security.annotations.management.UserPrincipal;
-import org.jboss.seam.security.annotations.management.UserRoles;
-
- at Entity
- at Table(uniqueConstraints = @UniqueConstraint(columnNames = "username"))
-public class MemberAccount implements Serializable
-{
-   private static final long serialVersionUID = 6368734442192368866L;
-   
-   private Integer accountId;
-   private String username;
-   private String passwordHash;
-   private String passwordSalt;
-   private boolean enabled;   
-   
-   private Set<MemberRole> roles;
-   private Member member;   
-   
-   @Id @GeneratedValue
-   public Integer getAccountId()
-   {
-      return accountId;
-   }
-   
-   public void setAccountId(Integer accountId)
-   {
-      this.accountId = accountId;
-   }
-   
-   @NotNull @UserPrincipal
-   public String getUsername()
-   {
-      return username;
-   }
-   
-   public void setUsername(String username)
-   {
-      this.username = username;
-   }
-   
-   @UserPassword
-   public String getPasswordHash()
-   {
-      return passwordHash;
-   }
-   
-   public void setPasswordHash(String passwordHash)
-   {
-      this.passwordHash = passwordHash;      
-   }
-   
-   @PasswordSalt
-   public String getPasswordSalt()
-   {
-      return passwordSalt;
-   }
-   
-   public void setPasswordSalt(String passwordSalt)
-   {
-      this.passwordSalt = passwordSalt;
-   }
-   
-   @UserEnabled
-   public boolean isEnabled()
-   {
-      return enabled;
-   }
-
-   public void setEnabled(boolean enabled)
-   {
-      this.enabled = enabled;      
-   }   
-
-   @UserRoles
-   @ManyToMany(targetEntity = MemberRole.class)
-   @JoinTable(name = "AccountMembership", 
-         joinColumns = @JoinColumn(name = "AccountId"),
-         inverseJoinColumns = @JoinColumn(name = "MemberOf")
-      )
-   public Set<MemberRole> getRoles()
-   {
-      return roles;
-   }
-   
-   public void setRoles(Set<MemberRole> roles)
-   {
-      this.roles = roles;
-   }
-   
-   @OneToOne
-   @JoinColumn(name = "MEMBER_ID")
-   public Member getMember()
-   {
-      return member;
-   }
-   
-   public void setMember(Member member)
-   {
-      this.member = member;
-   }
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberBlog.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberBlog.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberBlog.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,132 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.io.Serializable;
-import java.text.SimpleDateFormat;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.List;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.OneToMany;
-import javax.persistence.PrePersist;
-import javax.persistence.Transient;
-
-import org.jboss.seam.security.annotations.Restrict;
-
- at Entity
-public class MemberBlog implements Serializable
-{
-   private static final long serialVersionUID = 7824113911888715595L;
-   
-   private static SimpleDateFormat df = new SimpleDateFormat("EEEE, MMMM d, yyyy - hh:mm a");
-   
-   private Integer blogId;
-   private Member member;
-   private Date entryDate;
-   private String title;
-   private String text;
-   
-   private List<BlogComment> comments;
-   
-   /**
-    * This is an example of a security restriction.  Any attempts to persist a
-    * new memberBlog instance requires the user to pass a permission check.  In 
-    * this case, because the method is annotated with <code>@PrePersist</code> 
-    * the required permission is memberBlog:insert    
-    */
-   @PrePersist @Restrict
-   public void prePersist() {}
-   
-   @Id @GeneratedValue
-   public Integer getBlogId()
-   {
-      return blogId;
-   }
-   
-   public void setBlogId(Integer blogId)
-   {
-      this.blogId = blogId;
-   }
-
-   public Date getEntryDate()
-   {
-      return entryDate;
-   }
-
-   public void setEntryDate(Date entryDate)
-   {
-      this.entryDate = entryDate;
-   }
-   
-   @Transient
-   public String getFormattedEntryDate()
-   {
-      return df.format(entryDate);
-   }
-
-   @ManyToOne
-   @JoinColumn(name = "MEMBER_ID")   
-   public Member getMember()
-   {
-      return member;
-   }
-
-   public void setMember(Member member)
-   {
-      this.member = member;
-   }
-
-   public String getText()
-   {
-      return text;
-   }
-
-   public void setText(String text)
-   {
-      this.text = text;
-   }
-
-   public String getTitle()
-   {
-      return title;
-   }
-
-   public void setTitle(String title)
-   {
-      this.title = title;
-   }
-   
-   @OneToMany(mappedBy = "blog")
-   public List<BlogComment> getComments()
-   {
-      return comments;
-   }
-   
-   public void setComments(List<BlogComment> comments)
-   {
-      this.comments = comments;
-   }
-   
-   @Transient
-   public List<BlogComment> getSortedComments()
-   {
-      Collections.sort(comments, new Comparator<BlogComment>() {
-         public int compare(BlogComment o1, BlogComment o2) {
-            return (int) (o1.getCommentDate().getTime() - o2.getCommentDate().getTime());
-         }
-      });
-      
-      return comments;
-   }
-   
-   @Transient
-   public int getCommentCount()
-   {
-      return comments.size();
-   }
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberFriend.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberFriend.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberFriend.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,89 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.io.Serializable;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-
- at Entity
-public class MemberFriend implements Serializable
-{
-   private static final long serialVersionUID = -167586088947004386L;
-   
-   private Integer id;
-   private Member member;
-   private Member friend;
-   
-   private String introduction;
-   private String response;
-   
-   private boolean authorized;
-
-   @Id @GeneratedValue
-   public Integer getId()
-   {
-      return id;
-   }
-   
-   public void setId(Integer id)
-   {
-      this.id = id;
-   }   
-   
-   public boolean isAuthorized()
-   {
-      return authorized;
-   }
-   
-   public void setAuthorized(boolean authorized)
-   {
-      this.authorized = authorized;
-   }
-   
-   @ManyToOne
-   @JoinColumn(name = "FRIEND_ID")
-   public Member getFriend()
-   {
-      return friend;
-   }
-   
-   public void setFriend(Member friend)
-   {
-      this.friend = friend;
-   }
-
-   @ManyToOne
-   @JoinColumn(name = "MEMBER_ID")
-   public Member getMember()
-   {
-      return member;
-   }
-   
-   public void setMember(Member member)
-   {
-      this.member = member;
-   }
-
-   public String getIntroduction()
-   {
-      return introduction;
-   }
-
-   public void setIntroduction(String introduction)
-   {
-      this.introduction = introduction;
-   }
-
-   public String getResponse()
-   {
-      return response;
-   }
-
-   public void setResponse(String response)
-   {
-      this.response = response;
-   }      
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberImage.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberImage.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberImage.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,84 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.io.Serializable;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.Lob;
-import javax.persistence.ManyToOne;
-
-import org.jboss.seam.security.annotations.permission.Permission;
-import org.jboss.seam.security.annotations.permission.Permissions;
-
- at Permissions({
-   @Permission(action = "view"),
-   @Permission(action = "comment")
-})
- at Entity
-public class MemberImage implements Serializable
-{
-   private static final long serialVersionUID = -8088455267213832920L;
-   
-   private Integer imageId;
-   private Member member;
-   private byte[] data;
-   private String contentType;
-   private String caption;
-   
-   @Id @GeneratedValue
-   public Integer getImageId()
-   {
-      return imageId;
-   }
-   
-   public void setImageId(Integer imageId)
-   {
-      this.imageId = imageId;
-   }
-   
-   @ManyToOne
-   @JoinColumn(name = "MEMBER_ID")
-   public Member getMember()
-   {
-      return member;
-   }
-   
-   public void setMember(Member member)
-   {
-      this.member = member;
-   }
-
-   public String getContentType()
-   {
-      return contentType;
-   }
-
-   public void setContentType(String contentType)
-   {
-      this.contentType = contentType;
-   }
-   
-   public String getCaption()
-   {
-      return caption;
-   }
-   
-   public void setCaption(String caption)
-   {
-      this.caption = caption;
-   }
-
-   @Lob
-   public byte[] getData()
-   {
-      return data;
-   }
-
-   public void setData(byte[] data)
-   {
-      this.data = data;
-   }
-
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberRole.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberRole.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberRole.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,76 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.io.Serializable;
-import java.util.Set;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
-import javax.persistence.ManyToMany;
-
-import org.jboss.seam.security.annotations.management.RoleConditional;
-import org.jboss.seam.security.annotations.management.RoleGroups;
-import org.jboss.seam.security.annotations.management.RoleName;
-
- at Entity
-public class MemberRole implements Serializable
-{
-   private static final long serialVersionUID = 9177366120789064801L;
-   
-   private Integer roleId;
-   private String name;
-   private boolean conditional;
-   
-   private Set<MemberRole> groups;
-   
-   @Id @GeneratedValue
-   public Integer getRoleId()
-   {
-      return roleId;
-   }
-   
-   public void setRoleId(Integer roleId)
-   {
-      this.roleId = roleId;
-   }
-   
-   @RoleName
-   public String getName()
-   {
-      return name;
-   }
-   
-   public void setName(String name)
-   {
-      this.name = name;
-   }
-   
-   @RoleGroups
-   @ManyToMany(targetEntity = MemberRole.class)
-   @JoinTable(name = "RoleGroup", 
-         joinColumns = @JoinColumn(name = "RoleId"),
-         inverseJoinColumns = @JoinColumn(name = "MemberOf")
-      )
-   public Set<MemberRole> getGroups()
-   {
-      return groups;
-   }
-   
-   public void setGroups(Set<MemberRole> groups)
-   {
-      this.groups = groups;
-   }   
-   
-   @RoleConditional
-   public boolean isConditional()
-   {
-      return conditional;
-   }
-   
-   public void setConditional(boolean conditional)
-   {
-      this.conditional = conditional;
-   }
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/PictureAction.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/PictureAction.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/PictureAction.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,34 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-
-import javax.enterprise.inject.Model;
-import javax.persistence.EntityManager;
-
- at Model
-public class PictureAction
-{
-   private MemberImage memberImage;
-   
-   @In(required = false)
-   private Member authenticatedMember;
-   
-   @In EntityManager entityManager;
-   
-   @Begin
-   public void uploadPicture()
-   {
-      memberImage = new MemberImage();
-   }
-   
-   public void savePicture()
-   {
-      memberImage.setMember(entityManager.find(Member.class, authenticatedMember.getMemberId()));
-      entityManager.persist(memberImage);
-      Conversation.instance().end();
-   }
-
-   public MemberImage getMemberImage()
-   {
-      return memberImage;
-   }
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/PictureSearch.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/PictureSearch.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/PictureSearch.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,59 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-
-import java.io.Serializable;
-import java.util.List;
-
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Named;
-import javax.persistence.EntityManager;
-
-import org.jboss.seam.security.Identity;
-
- at RequestScoped
- at Named
-public class PictureSearch implements Serializable
-{
-   private static final long serialVersionUID = -1868188969326866331L;
-   
-   private String memberName;
-   
-   @In
-   private EntityManager entityManager;
-   
-   @Out(required = false)
-   private List<MemberImage> memberImages;
-   
-   @RequestParameter
-   private Integer imageId;
-   
-   public String getMemberName()
-   {
-      return memberName;
-   }
-
-   public void setMemberName(String memberName)
-   {
-      this.memberName = memberName;
-   }
-   
-   public void delete(@Delete MemberImage image)
-   {
-      entityManager.remove(image);
-   }
-   
-   public MemberImage lookupImage()
-   {
-      return entityManager.find(MemberImage.class, imageId);
-   }
-   
-   @SuppressWarnings("unchecked")
-   public void loadMemberPictures()
-   {
-      memberImages = (List<MemberImage>) entityManager.createQuery(
-            "select i from MemberImage i where i.member.memberName = :name and not i = i.member.picture")
-            .setParameter("name", memberName)
-            .getResultList();      
-      Identity.instance().filterByPermission(memberImages, "view");
-   }
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ProfileAction.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ProfileAction.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ProfileAction.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,124 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-
-import java.util.List;
-import java.util.Random;
-
-import javax.ejb.Remove;
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Named;
-import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
-
- at RequestScoped
- at Named
-public class ProfileAction
-{
-   @RequestParameter
-   private String name;
-
-   @In(required = false) @Out(required = false, scope = CONVERSATION)
-   private Member selectedMember;
-   
-   @In(required = false)
-   private Member authenticatedMember;
-   
-   @Out(required = false)
-   List<Member> newMembers;
-   
-   @Out(required = false)
-   List<MemberBlog> memberBlogs;   
-   
-   @In
-   private EntityManager entityManager;
-
-   @Factory("selectedMember")
-   public void display()
-   {      
-      if (name == null && authenticatedMember != null)
-      {
-         selectedMember = (Member) entityManager.find(Member.class, 
-               authenticatedMember.getMemberId());
-      }
-      else if (name != null)
-      {
-         try
-         {
-            selectedMember = (Member) entityManager.createQuery(
-            "from Member where memberName = :memberName")
-            .setParameter("memberName", name)
-            .getSingleResult(); 
-         }
-         catch (NoResultException ex) { }
-      }
-   }
-   
-   /**
-    * Returns the 5 latest blog entries for a member
-    */
-   @SuppressWarnings("unchecked")
-   public List<MemberBlog> getLatestBlogs()
-   {
-      return entityManager.createQuery(
-           "from MemberBlog b where b.member = :member order by b.entryDate desc")
-           .setParameter("member", selectedMember)
-           .setMaxResults(5)
-           .getResultList();
-   }
-
-   /**
-    * Used to read all blog entries for a member
-    */
-   @SuppressWarnings("unchecked")
-   @Factory("memberBlogs")
-   public void getMemberBlogs()
-   {
-      if (name == null && authenticatedMember != null)
-      {
-         name = authenticatedMember.getMemberName();
-      }      
-      
-      memberBlogs = entityManager.createQuery(
-            "from MemberBlog b where b.member.memberName = :memberName order by b.entryDate desc")
-            .setParameter("memberName", name)
-            .getResultList();
-   }   
-   
-   @SuppressWarnings("unchecked")
-   @Factory("newMembers")
-   public void newMembers()
-   {
-      newMembers = entityManager.createQuery(
-            "from Member order by memberSince desc")
-            .setMaxResults(10)
-            .getResultList();
-      
-      // Randomly select 3 of the latest 10 members
-      Random rnd = new Random(System.currentTimeMillis());
-      while (newMembers.size() > 3)
-      {
-         newMembers.remove(rnd.nextInt(newMembers.size()));
-      }
-   }
-   
-   @SuppressWarnings("unchecked")
-   public List<Member> getFriends()
-   {
-      return entityManager.createQuery(
-            "select f.friend from MemberFriend f where f.member = :member and authorized = true")
-            .setParameter("member", selectedMember)
-            .getResultList();
-   }
-   
-   @SuppressWarnings("unchecked")
-   public List<FriendComment> getFriendComments()
-   {
-      return entityManager.createQuery(
-            "from FriendComment c where c.member = :member order by commentDate desc")
-            .setParameter("member", selectedMember)
-            .getResultList();
-   }
-   
-   @Remove @Destroy
-   public void destroy() { }   
-}

Deleted: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/RegisterAction.java
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/RegisterAction.java	2010-03-25 06:28:52 UTC (rev 12268)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/RegisterAction.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -1,193 +0,0 @@
-package org.jboss.seam.security.examples.seamspace;
-
-import java.util.Date;
-
-import javax.ejb.Remove;
-import javax.enterprise.inject.Model;
-import javax.persistence.EntityManager;
-
-import org.jboss.seam.security.Identity;
-import org.jboss.seam.security.RunAsOperation;
-import org.jboss.seam.security.management.IdentityManager;
-import org.jboss.seam.security.management.JpaIdentityStore;
-
- at Model
-public class RegisterAction
-{
-   private Member member;
-   
-   @In
-   private EntityManager entityManager;
-   
-   @In
-   private Identity identity;
-   
-   @In
-   private IdentityManager identityManager;
-      
-   private MemberAccount newAccount;
-   
-   private String username;   
-   
-   /**
-    * Password confirmation
-    */
-   private String password;
-   private String confirm;   
-   
-   private String gender;
-   
-   private byte[] picture;
-   private String pictureContentType;
-   
-   private boolean verified;
-
-   @Begin
-   public void start()
-   {
-      member = new Member();
-   }
-   
-   public void next()
-   {
-      member.setGender(Member.Gender.valueOf(gender.toLowerCase()));
-      
-      verified = (confirm != null && confirm.equals(password));
-      
-      if (!verified)
-      {
-         FacesMessages.instance().addToControl("confirmPassword", "Passwords do not match");
-      }           
-   }
-   
-   @Observer(JpaIdentityStore.EVENT_USER_CREATED)
-   public void accountCreated(MemberAccount account)
-   {
-      // The user *may* have been created from the user manager screen. In that
-      // case, create a dummy Member record just for the purpose of demonstrating the
-      // identity management API
-      if (member == null)
-      {
-         member = new Member();
-         member.setMemberName(account.getUsername());
-         member.setGender(Member.Gender.male);
-         member.setFirstName("John");
-         member.setLastName("Doe");
-         member.setEmail(account.getUsername() + "@nowhere.com");
-         member.setDob(new Date());
-         member.setMemberSince(new Date());
-         entityManager.persist(member);
-      }
-      
-      account.setMember(member);
-      this.newAccount = account;
-   }
-
-   @End
-   public void uploadPicture() 
-   {  
-      member.setMemberSince(new Date());      
-      entityManager.persist(member);      
-      
-      new RunAsOperation() {
-         public void execute() {
-            identityManager.createUser(username, password);
-            identityManager.grantRole(username, "user");            
-         }         
-      }.addRole("admin")
-       .run();
-            
-      newAccount.setMember(member);
-      newAccount = entityManager.merge(newAccount);
-
-      if (picture != null && picture.length > 0)
-      {
-         MemberImage img = new MemberImage();
-         img.setData(picture);
-         img.setMember(member);
-         img.setContentType(pictureContentType);
-         entityManager.persist(img);
-         member.setPicture(img);
-         
-         member = entityManager.merge(member);
-      }
-      
-      // Login the user
-      identity.getCredentials().setUsername(username);
-      identity.getCredentials().setPassword(password);
-      identity.login();
-   }
-   
-   public Member getMember()
-   {
-      return member;
-   }
-   
-   public String getUsername()
-   {
-      return username;
-   }
-   
-   public void setUsername(String username)
-   {
-      this.username = username;
-   }
-   
-   public String getPassword()
-   {
-      return password;
-   }
-   
-   public void setPassword(String password)
-   {
-      this.password = password;
-   }
-   
-   public String getConfirm()
-   {
-      return confirm;
-   }
-   
-   public void setConfirm(String confirm)
-   {
-      this.confirm = confirm;
-   }
-   
-   public String getGender()
-   {
-      return gender;
-   }
-   
-   public void setGender(String gender)
-   {
-      this.gender = gender;
-   }
-   
-   public void setPicture(byte[] picture)
-   {
-      this.picture = picture;
-   }
-   
-   public byte[] getPicture()
-   {
-      return picture;
-   }
-   
-   public String getPictureContentType()
-   {
-      return pictureContentType;  
-   }
-   
-   public void setPictureContentType(String contentType)
-   {
-      this.pictureContentType = contentType;
-   }
-   
-   public boolean isVerified()
-   {
-      return verified;
-   }
-   
-   @Destroy @Remove
-   public void destroy() {}
-}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/BlogAction.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/BlogAction.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/BlogAction.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/BlogAction.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,82 @@
+package org.jboss.seam.security.examples.seamspace.action;
+
+import java.util.ArrayList;
+import java.util.Date;
+
+import javax.enterprise.context.Conversation;
+import javax.enterprise.context.ConversationScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+
+ at Named("blog")
+ at ConversationScoped
+public class BlogAction
+{    
+   private String name;   
+   private Integer blogId;
+   
+   @Inject EntityManager entityManager;
+   
+   @Inject MemberBlog selectedBlog;
+   
+   @Inject Member authenticatedMember;
+   
+   @Inject Conversation conversation;
+   
+   /**
+    * Used to read a single blog entry for a member
+    */   
+   public @Produces @Named("selectedBlog") MemberBlog getBlog()
+   {     
+      conversation.begin();
+      try
+      {
+         return (MemberBlog) entityManager.createQuery(
+           "from MemberBlog b where b.blogId = :blogId and b.member.memberName = :memberName")
+           .setParameter("blogId", blogId)
+           .setParameter("memberName", name)
+           .getSingleResult();
+      }
+      catch (NoResultException ex) { }
+   }   
+   
+   @Begin
+   public void createEntry()
+   {
+      selectedBlog = new MemberBlog();              
+   }
+   
+   public void saveEntry()
+   {
+      selectedBlog.setMember(authenticatedMember);
+      selectedBlog.setEntryDate(new Date());
+      selectedBlog.setComments(new ArrayList<BlogComment>());
+      
+      entityManager.persist(selectedBlog);
+      
+      conversation.end();
+   }
+   
+   public String getName()
+   {
+      return name;
+   }
+   
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+   
+   public Integer getBlogId()
+   {
+      return blogId;
+   }
+   
+   public void setBlogId(Integer blogId)
+   {
+      this.blogId = blogId;
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/CommentAction.java (from rev 12264, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/CommentAction.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/CommentAction.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/CommentAction.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,52 @@
+package org.jboss.seam.security.examples.seamspace.action;
+
+import java.util.Date;
+
+import javax.enterprise.context.Conversation;
+import javax.enterprise.inject.Model;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+import org.jboss.seam.security.annotations.Insert;
+import org.jboss.seam.security.examples.seamspace.model.BlogComment;
+import org.jboss.seam.security.examples.seamspace.model.Member;
+import org.jboss.seam.security.examples.seamspace.model.MemberBlog;
+
+ at Model
+//@Transactional
+public class CommentAction 
+{
+   @Inject EntityManager entityManager;
+   
+   private BlogComment comment;     
+   
+   @Inject Member authenticatedMember;
+   
+   @Inject MemberBlog selectedBlog;
+   
+   @Inject Conversation conversation;
+   
+   @Insert(BlogComment.class) 
+   public void createComment()
+   {            
+      conversation.begin();
+      comment = new BlogComment();
+      comment.setCommentor(authenticatedMember);              
+      comment.setBlog(selectedBlog);
+   }
+   
+   public void saveComment()
+   {      
+      comment.setCommentDate(new Date());
+      entityManager.persist(comment);
+            
+      entityManager.refresh(selectedBlog);
+      
+      conversation.end();
+   }    
+   
+   public BlogComment getComment()
+   {
+      return comment;
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/ContentAction.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ContentAction.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/ContentAction.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/ContentAction.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,24 @@
+package org.jboss.seam.security.examples.seamspace;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+
+import org.jboss.seam.security.Identity;
+
+ at Named
+public class ContentAction
+{
+   @Inject EntityManager entityManager;
+   @Inject Identity identity;
+   
+   public MemberImage getImage(int imageId)
+   {
+      MemberImage img = entityManager.find(MemberImage.class, imageId);
+      
+      if (img == null || !identity.hasPermission(img, "view"))
+         return null;
+      else
+         return img;
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/FriendAction.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/FriendAction.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/FriendAction.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/FriendAction.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,104 @@
+package org.jboss.seam.security.examples.seamspace.action;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.enterprise.context.Conversation;
+import javax.enterprise.context.ConversationScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+
+import org.jboss.seam.security.Identity;
+import org.jboss.seam.security.examples.seamspace.model.FriendComment;
+import org.jboss.seam.security.examples.seamspace.model.Member;
+import org.jboss.seam.security.examples.seamspace.model.MemberFriend;
+
+ at Named
+ at ConversationScoped
+public class FriendAction implements Serializable
+{
+   private static final long serialVersionUID = 4565339001481077911L;
+
+   @RequestParameter("name")
+   private String name;
+   
+   @Out(required = false)
+   private FriendComment friendComment;
+   
+   @Out(required = false)
+   private MemberFriend friendRequest;
+   
+   @Inject Member authenticatedMember;
+      
+   @Inject EntityManager entityManager;
+   
+   @Inject Conversation conversation;
+   
+   @Inject Identity identity;
+      
+   @Factory("friendComment")
+   public void createComment()
+   {      
+      conversation.begin();
+      try
+      {
+         Member member = (Member) entityManager.createQuery(
+         "from Member where memberName = :memberName")
+         .setParameter("memberName", name)
+         .getSingleResult();
+                  
+         Contexts.getMethodContext().set("friends", member.getFriends());
+         Identity.instance().checkPermission(member, "createFriendComment");
+
+         friendComment = new FriendComment();
+         friendComment.setFriend(authenticatedMember);
+         friendComment.setMember(member);
+      }
+      catch (NoResultException ex) 
+      { 
+         FacesMessages.instance().add("Member not found.");
+      }
+   }
+   
+   public void saveComment()
+   {
+      friendComment.setCommentDate(new Date());
+      entityManager.persist(friendComment);
+      conversation.end();
+   }
+   
+   public void createRequest()
+   {
+      try
+      {
+         conversation.begin();
+         Member member = (Member) entityManager.createQuery(
+         "from Member where memberName = :memberName")
+         .setParameter("memberName", name)
+         .getSingleResult();
+                  
+         Contexts.getMethodContext().set("friends", member.getFriends());
+         identity.checkPermission(member, "createFriendRequest");
+
+         friendRequest = new MemberFriend();
+         friendRequest.setFriend(authenticatedMember);
+         friendRequest.setMember(member);
+      }
+      catch (NoResultException ex) 
+      { 
+         FacesMessages.instance().add("Member not found.");
+         conversation.end();
+      }
+   }
+
+   public void saveRequest()
+   {
+      friendRequest.getMember().getFriends().add(friendRequest);
+      entityManager.persist(friendRequest);      
+      FacesMessages.instance().add("Friend request sent");
+      conversation.end();
+   }
+   
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/HashGenerator.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/HashGenerator.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/HashGenerator.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/HashGenerator.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,77 @@
+package org.jboss.seam.security.examples.seamspace.action;
+
+import javax.enterprise.inject.Model;
+import javax.inject.Inject;
+
+import org.jboss.seam.security.crypto.BinTools;
+import org.jboss.seam.security.management.JpaIdentityStore;
+import org.jboss.seam.security.management.PasswordHash;
+
+ at Model
+public class HashGenerator
+{
+   @Inject JpaIdentityStore identityStore;
+   @Inject PasswordHash hash;
+   
+   private String password;
+   private String passwordHash;
+   private String passwordSalt;
+   
+   public String getPassword()
+   {
+      return password;
+   }
+   
+   public void setPassword(String password)
+   {
+      this.password = password;
+   }
+   
+   public String getPasswordHash()
+   {
+      return passwordHash;
+   }
+   
+   public void setPasswordHash(String passwordHash)
+   {
+      this.passwordHash = passwordHash;
+   }
+   
+   public String getPasswordSalt()
+   {
+      return passwordSalt;
+   }
+   
+   public void setPasswordSalt(String passwordSalt)
+   {
+      this.passwordSalt = passwordSalt;
+   }
+   
+   public void generate()
+   {
+      byte[] salt;
+      
+      if (passwordSalt == null || "".equals(passwordSalt.trim()))
+      {
+         salt = hash.generateRandomSalt();
+         passwordSalt = BinTools.bin2hex(salt);
+      }
+      else
+      {
+         salt = BinTools.hex2bin(passwordSalt);
+      }
+      
+      passwordHash = identityStore.generatePasswordHash(password, salt);
+   }
+   
+   public String getSql()
+   {
+      StringBuilder sb = new StringBuilder();
+      sb.append("INSERT INTO USER_ACCOUNT (username, password_hash, password_salt) values ('johnsmith', '");
+      sb.append(passwordHash);
+      sb.append("', '");
+      sb.append(passwordSalt);
+      sb.append("');");      
+      return sb.toString();
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/ImagePermission.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ImagePermission.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/ImagePermission.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/ImagePermission.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,193 @@
+package org.jboss.seam.security.examples.seamspace.action;
+
+import java.io.Serializable;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.inject.Model;
+import javax.persistence.EntityManager;
+
+import org.jboss.seam.security.Role;
+import org.jboss.seam.security.SimplePrincipal;
+import org.jboss.seam.security.examples.seamspace.model.Member;
+import org.jboss.seam.security.management.IdentityManager;
+import org.jboss.seam.security.permission.Permission;
+import org.jboss.seam.security.permission.PermissionManager;
+import org.jboss.seam.security.permission.action.PermissionSearch;
+
+ at Model
+public class ImagePermission implements Serializable
+{
+   private static final long serialVersionUID = -4943654157860780587L;
+
+   private List<String> selectedRoles;   
+   private List<Member> selectedFriends;
+   private List<String> selectedActions;
+   
+   private List<String> originalActions;
+   
+   private List<Member> availableFriends;   
+   
+   @In IdentityManager identityManager;
+   @In PermissionManager permissionManager;
+   
+   @In EntityManager entityManager;
+   
+   @In PermissionSearch permissionSearch;   
+   
+   private MemberImage target; 
+   
+   private Principal recipient;
+   
+   @SuppressWarnings("unchecked")
+   @Begin(nested = true)
+   public void createPermission()
+   {
+      target = (MemberImage) permissionSearch.getTarget();
+      
+      selectedFriends = new ArrayList<Member>();
+      
+      availableFriends = entityManager.createQuery(
+            "select f.friend from MemberFriend f where f.member = :member and f.authorized = true")
+            .setParameter("member", target.getMember())
+            .getResultList();      
+   }
+   
+   @Begin(nested = true)
+   public void editPermission()
+   {
+      target = (MemberImage) permissionSearch.getTarget();
+      recipient = permissionSearch.getSelectedRecipient();
+            
+      List<Permission> permissions = permissionManager.listPermissions(target);
+      
+      selectedActions = new ArrayList<String>();      
+      
+      for (Permission permission : permissions)
+      {
+         if (permission.getRecipient().equals(recipient))
+         {
+            if (!selectedActions.contains(permission.getAction()))
+            {
+               selectedActions.add(permission.getAction());
+            }
+         }
+      }
+      
+      originalActions = new ArrayList<String>(selectedActions);
+   }
+
+   public List<String> getSelectedRoles()
+   {
+      return selectedRoles;
+   }
+   
+   public void setSelectedRoles(List<String> selectedRoles)
+   {
+      this.selectedRoles = selectedRoles;
+   }
+   
+   public List<Member> getSelectedFriends()
+   {
+      return selectedFriends;
+   }
+   
+   public void setSelectedFriends(List<Member> selectedFriends)
+   {
+      this.selectedFriends = selectedFriends;
+   }
+   
+   public List<String> getSelectedActions()
+   {
+      return selectedActions;
+   }
+   
+   public void setSelectedActions(List<String> selectedActions)
+   {
+      this.selectedActions = selectedActions;
+   }
+   
+   public String applyPermissions()
+   {
+      // If the recipient isn't null, it means we're editing existing permissions
+      if (recipient != null)
+      {
+         List<Permission> grantedPermissions = new ArrayList<Permission>();
+         List<Permission> revokedPermissions = new ArrayList<Permission>();
+         
+         for (String action : selectedActions)
+         {
+            if (!originalActions.contains(action)) 
+            {
+               grantedPermissions.add(new Permission(target, action, recipient));
+            }
+         }
+         
+         for (String action : originalActions)
+         {
+            if (!selectedActions.contains(action))
+            {
+               revokedPermissions.add(new Permission(target, action, recipient));
+            }
+         }
+         
+         if (!grantedPermissions.isEmpty()) permissionManager.grantPermissions(grantedPermissions);
+         if (!revokedPermissions.isEmpty()) permissionManager.revokePermissions(revokedPermissions);
+      }
+      // otherwise this is a set of new permissions
+      else
+      {
+         if (selectedActions.size() == 0)
+         {
+            FacesMessages.instance().add("You must select at least one action");
+            return "failure";
+         }
+         
+         List<Permission> permissions = new ArrayList<Permission>();
+   
+         for (String role : selectedRoles)
+         {
+            Principal r = new Role(role);
+            for (String action : selectedActions)
+            {            
+               permissions.add(new Permission(target, action, r));
+            }
+         }
+         
+         for (Member friend : selectedFriends)
+         {
+            MemberAccount acct = (MemberAccount) entityManager.createQuery(
+                  "select a from MemberAccount a where a.member = :member")
+                  .setParameter("member", friend)
+                  .getSingleResult();
+            
+            Principal p = new SimplePrincipal(acct.getUsername());
+            
+            for (String action : selectedActions)
+            {
+               permissions.add(new Permission(target, action, p));
+            }
+         }
+         
+         permissionManager.grantPermissions(permissions);
+      }
+      Conversation.instance().endBeforeRedirect();
+      return "success";
+   }
+   
+   public List<Member> getAvailableFriends()
+   {
+      return availableFriends;
+   }
+   
+   public MemberImage getTarget()
+   {
+      return target;
+   }
+   
+   public Principal getRecipient()
+   {
+      return recipient;
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/PictureAction.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/PictureAction.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/PictureAction.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/PictureAction.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,34 @@
+package org.jboss.seam.security.examples.seamspace.action;
+
+
+import javax.enterprise.inject.Model;
+import javax.persistence.EntityManager;
+
+ at Model
+public class PictureAction
+{
+   private MemberImage memberImage;
+   
+   @In(required = false)
+   private Member authenticatedMember;
+   
+   @In EntityManager entityManager;
+   
+   @Begin
+   public void uploadPicture()
+   {
+      memberImage = new MemberImage();
+   }
+   
+   public void savePicture()
+   {
+      memberImage.setMember(entityManager.find(Member.class, authenticatedMember.getMemberId()));
+      entityManager.persist(memberImage);
+      Conversation.instance().end();
+   }
+
+   public MemberImage getMemberImage()
+   {
+      return memberImage;
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/PictureSearch.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/PictureSearch.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/PictureSearch.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/PictureSearch.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,59 @@
+package org.jboss.seam.security.examples.seamspace.action;
+
+
+import java.io.Serializable;
+import java.util.List;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+
+import org.jboss.seam.security.Identity;
+
+ at RequestScoped
+ at Named
+public class PictureSearch implements Serializable
+{
+   private static final long serialVersionUID = -1868188969326866331L;
+   
+   private String memberName;
+   
+   @In
+   private EntityManager entityManager;
+   
+   @Out(required = false)
+   private List<MemberImage> memberImages;
+   
+   @RequestParameter
+   private Integer imageId;
+   
+   public String getMemberName()
+   {
+      return memberName;
+   }
+
+   public void setMemberName(String memberName)
+   {
+      this.memberName = memberName;
+   }
+   
+   public void delete(@Delete MemberImage image)
+   {
+      entityManager.remove(image);
+   }
+   
+   public MemberImage lookupImage()
+   {
+      return entityManager.find(MemberImage.class, imageId);
+   }
+   
+   @SuppressWarnings("unchecked")
+   public void loadMemberPictures()
+   {
+      memberImages = (List<MemberImage>) entityManager.createQuery(
+            "select i from MemberImage i where i.member.memberName = :name and not i = i.member.picture")
+            .setParameter("name", memberName)
+            .getResultList();      
+      Identity.instance().filterByPermission(memberImages, "view");
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/ProfileAction.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ProfileAction.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/ProfileAction.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/ProfileAction.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,124 @@
+package org.jboss.seam.security.examples.seamspace.action;
+
+
+import java.util.List;
+import java.util.Random;
+
+import javax.ejb.Remove;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+
+ at RequestScoped
+ at Named
+public class ProfileAction
+{
+   @RequestParameter
+   private String name;
+
+   @In(required = false) @Out(required = false, scope = CONVERSATION)
+   private Member selectedMember;
+   
+   @In(required = false)
+   private Member authenticatedMember;
+   
+   @Out(required = false)
+   List<Member> newMembers;
+   
+   @Out(required = false)
+   List<MemberBlog> memberBlogs;   
+   
+   @In
+   private EntityManager entityManager;
+
+   @Factory("selectedMember")
+   public void display()
+   {      
+      if (name == null && authenticatedMember != null)
+      {
+         selectedMember = (Member) entityManager.find(Member.class, 
+               authenticatedMember.getMemberId());
+      }
+      else if (name != null)
+      {
+         try
+         {
+            selectedMember = (Member) entityManager.createQuery(
+            "from Member where memberName = :memberName")
+            .setParameter("memberName", name)
+            .getSingleResult(); 
+         }
+         catch (NoResultException ex) { }
+      }
+   }
+   
+   /**
+    * Returns the 5 latest blog entries for a member
+    */
+   @SuppressWarnings("unchecked")
+   public List<MemberBlog> getLatestBlogs()
+   {
+      return entityManager.createQuery(
+           "from MemberBlog b where b.member = :member order by b.entryDate desc")
+           .setParameter("member", selectedMember)
+           .setMaxResults(5)
+           .getResultList();
+   }
+
+   /**
+    * Used to read all blog entries for a member
+    */
+   @SuppressWarnings("unchecked")
+   @Factory("memberBlogs")
+   public void getMemberBlogs()
+   {
+      if (name == null && authenticatedMember != null)
+      {
+         name = authenticatedMember.getMemberName();
+      }      
+      
+      memberBlogs = entityManager.createQuery(
+            "from MemberBlog b where b.member.memberName = :memberName order by b.entryDate desc")
+            .setParameter("memberName", name)
+            .getResultList();
+   }   
+   
+   @SuppressWarnings("unchecked")
+   @Factory("newMembers")
+   public void newMembers()
+   {
+      newMembers = entityManager.createQuery(
+            "from Member order by memberSince desc")
+            .setMaxResults(10)
+            .getResultList();
+      
+      // Randomly select 3 of the latest 10 members
+      Random rnd = new Random(System.currentTimeMillis());
+      while (newMembers.size() > 3)
+      {
+         newMembers.remove(rnd.nextInt(newMembers.size()));
+      }
+   }
+   
+   @SuppressWarnings("unchecked")
+   public List<Member> getFriends()
+   {
+      return entityManager.createQuery(
+            "select f.friend from MemberFriend f where f.member = :member and authorized = true")
+            .setParameter("member", selectedMember)
+            .getResultList();
+   }
+   
+   @SuppressWarnings("unchecked")
+   public List<FriendComment> getFriendComments()
+   {
+      return entityManager.createQuery(
+            "from FriendComment c where c.member = :member order by commentDate desc")
+            .setParameter("member", selectedMember)
+            .getResultList();
+   }
+   
+   @Remove @Destroy
+   public void destroy() { }   
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/RegisterAction.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/RegisterAction.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/RegisterAction.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/action/RegisterAction.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,197 @@
+package org.jboss.seam.security.examples.seamspace.action;
+
+import java.util.Date;
+
+import javax.enterprise.context.Conversation;
+import javax.enterprise.inject.Model;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+import org.jboss.seam.security.Credentials;
+import org.jboss.seam.security.Identity;
+import org.jboss.seam.security.RunAsOperation;
+import org.jboss.seam.security.examples.seamspace.model.Member;
+import org.jboss.seam.security.examples.seamspace.model.MemberAccount;
+import org.jboss.seam.security.examples.seamspace.model.MemberImage;
+import org.jboss.seam.security.management.IdentityManager;
+import org.jboss.seam.security.management.JpaIdentityStore;
+
+ at Model
+public class RegisterAction
+{
+   private Member member;
+   
+   @Inject EntityManager entityManager;
+   
+   @Inject Identity identity;
+   
+   @Inject Credentials credentials;
+   
+   @Inject IdentityManager identityManager;
+   
+   @Inject Conversation conversation;
+      
+   private MemberAccount newAccount;
+   
+   private String username;   
+   
+   /**
+    * Password confirmation
+    */
+   private String password;
+   private String confirm;   
+   
+   private String gender;
+   
+   private byte[] picture;
+   private String pictureContentType;
+   
+   private boolean verified;
+
+   public void start()
+   {
+      conversation.begin();
+      member = new Member();
+   }
+   
+   public void next()
+   {
+      member.setGender(Member.Gender.valueOf(gender.toLowerCase()));
+      
+      verified = (confirm != null && confirm.equals(password));
+      
+      if (!verified)
+      {
+         FacesMessages.instance().addToControl("confirmPassword", "Passwords do not match");
+      }           
+   }
+   
+   //@Observer(JpaIdentityStore.EVENT_USER_CREATED)
+   public void accountCreated(MemberAccount account)
+   {
+      // The user *may* have been created from the user manager screen. In that
+      // case, create a dummy Member record just for the purpose of demonstrating the
+      // identity management API
+      if (member == null)
+      {
+         member = new Member();
+         member.setMemberName(account.getUsername());
+         member.setGender(Member.Gender.male);
+         member.setFirstName("John");
+         member.setLastName("Doe");
+         member.setEmail(account.getUsername() + "@nowhere.com");
+         member.setDob(new Date());
+         member.setMemberSince(new Date());
+         entityManager.persist(member);
+      }
+      
+      account.setMember(member);
+      this.newAccount = account;
+   }
+
+   public void uploadPicture() 
+   {  
+      member.setMemberSince(new Date());      
+      entityManager.persist(member);      
+      
+      new RunAsOperation() {
+         public void execute() {
+            identityManager.createUser(username, password);
+            identityManager.grantRole(username, "user");            
+         }         
+      }.addRole("admin")
+       .run();
+            
+      newAccount.setMember(member);
+      newAccount = entityManager.merge(newAccount);
+
+      if (picture != null && picture.length > 0)
+      {
+         MemberImage img = new MemberImage();
+         img.setData(picture);
+         img.setMember(member);
+         img.setContentType(pictureContentType);
+         entityManager.persist(img);
+         member.setPicture(img);
+         
+         member = entityManager.merge(member);
+      }
+      
+      // Login the user
+      credentials.setUsername(username);
+      credentials.setPassword(password);
+      identity.login();
+      
+      conversation.end();
+   }
+   
+   public Member getMember()
+   {
+      return member;
+   }
+   
+   public String getUsername()
+   {
+      return username;
+   }
+   
+   public void setUsername(String username)
+   {
+      this.username = username;
+   }
+   
+   public String getPassword()
+   {
+      return password;
+   }
+   
+   public void setPassword(String password)
+   {
+      this.password = password;
+   }
+   
+   public String getConfirm()
+   {
+      return confirm;
+   }
+   
+   public void setConfirm(String confirm)
+   {
+      this.confirm = confirm;
+   }
+   
+   public String getGender()
+   {
+      return gender;
+   }
+   
+   public void setGender(String gender)
+   {
+      this.gender = gender;
+   }
+   
+   public void setPicture(byte[] picture)
+   {
+      this.picture = picture;
+   }
+   
+   public byte[] getPicture()
+   {
+      return picture;
+   }
+   
+   public String getPictureContentType()
+   {
+      return pictureContentType;  
+   }
+   
+   public void setPictureContentType(String contentType)
+   {
+      this.pictureContentType = contentType;
+   }
+   
+   public boolean isVerified()
+   {
+      return verified;
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/AccountPermission.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/AccountPermission.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/AccountPermission.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/AccountPermission.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,81 @@
+package org.jboss.seam.security.examples.seamspace.model;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.jboss.seam.security.annotations.permission.PermissionAction;
+import org.jboss.seam.security.annotations.permission.PermissionDiscriminator;
+import org.jboss.seam.security.annotations.permission.PermissionRole;
+import org.jboss.seam.security.annotations.permission.PermissionTarget;
+import org.jboss.seam.security.annotations.permission.PermissionUser;
+
+ at Entity
+public class AccountPermission implements Serializable
+{
+   private static final long serialVersionUID = -5628863031792429938L;
+   
+   private Integer permissionId;
+   private String recipient;
+   private String target;
+   private String action;
+   private String discriminator;
+   
+   @Id @GeneratedValue
+   public Integer getPermissionId()
+   {
+      return permissionId;
+   }
+   
+   public void setPermissionId(Integer permissionId)
+   {
+      this.permissionId = permissionId;
+   }
+   
+   @PermissionUser 
+   @PermissionRole
+   public String getRecipient()
+   {
+      return recipient;
+   }
+   
+   public void setRecipient(String recipient)
+   {
+      this.recipient = recipient;
+   }
+   
+   @PermissionTarget
+   public String getTarget()
+   {
+      return target;
+   }
+   
+   public void setTarget(String target)
+   {
+      this.target = target;
+   }
+   
+   @PermissionAction
+   public String getAction()
+   {
+      return action;
+   }
+   
+   public void setAction(String action)
+   {
+      this.action = action;
+   }
+   
+   @PermissionDiscriminator
+   public String getDiscriminator()
+   {
+      return discriminator;
+   }
+   
+   public void setDiscriminator(String discriminator)
+   {
+      this.discriminator = discriminator;
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/BlogComment.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/BlogComment.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/BlogComment.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/BlogComment.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,92 @@
+package org.jboss.seam.security.examples.seamspace.model;
+
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Transient;
+import javax.validation.constraints.NotNull;
+
+
+ at Entity
+public class BlogComment implements Serializable
+{
+   private static final long serialVersionUID = 5495139096911872039L;
+
+   private static SimpleDateFormat df = new SimpleDateFormat("EEEE, MMMM d, yyyy 'at' hh:mm a");   
+   
+   private Integer commentId;
+   private MemberBlog blog;
+   private Member commentor;
+   private Date commentDate;
+   private String comment;
+   
+   @Id @GeneratedValue
+   public Integer getCommentId()
+   {
+      return commentId;
+   }
+   
+   public void setCommentId(Integer commentId)
+   {
+      this.commentId = commentId;
+   }   
+   
+   @ManyToOne
+   @JoinColumn(name = "BLOG_ID")
+   public MemberBlog getBlog()
+   {
+      return blog;
+   }
+   
+   public void setBlog(MemberBlog blog)
+   {
+      this.blog = blog;
+   }
+   
+   @NotNull
+   public String getComment()
+   {
+      return comment;
+   }
+   public void setComment(String comment)
+   {
+      this.comment = comment;
+   }
+   
+   @NotNull
+   public Date getCommentDate()
+   {
+      return commentDate;
+   }
+   
+   public void setCommentDate(Date commentDate)
+   {
+      this.commentDate = commentDate;
+   }
+   
+   @Transient
+   public String getFormattedCommentDate()
+   {
+     return df.format(commentDate);  
+   }
+
+   @ManyToOne
+   @JoinColumn(name = "COMMENTOR_ID")
+   public Member getCommentor()
+   {
+      return commentor;
+   }
+   
+   public void setCommentor(Member commentor)
+   {
+      this.commentor = commentor;
+   }
+  
+   
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/FriendComment.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/FriendComment.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/FriendComment.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/FriendComment.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,88 @@
+package org.jboss.seam.security.examples.seamspace.model;
+
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Transient;
+
+ at Entity
+public class FriendComment implements Serializable
+{
+   private static final long serialVersionUID = -288494386341008371L;
+
+   private static SimpleDateFormat df = new SimpleDateFormat("d MMMM yyyy hh:mm a");   
+   
+   private Integer id;
+   private Member member;
+   private Member friend;
+   private Date commentDate;
+   private String comment;
+   
+   @Id @GeneratedValue
+   public Integer getId()
+   {
+      return id;
+   }
+   
+   public void setId(Integer id)
+   {
+      this.id = id;
+   }   
+   
+   public String getComment()
+   {
+      return comment;
+   }
+   
+   public void setComment(String comment)
+   {
+      this.comment = comment;
+   }
+   
+   public Date getCommentDate()
+   {
+      return commentDate;
+   }
+   
+   public void setCommentDate(Date commentDate)
+   {
+      this.commentDate = commentDate;
+   }
+   
+   @Transient
+   public String getFormattedCommentDate()
+   {
+     return df.format(commentDate);  
+   }   
+   
+   @ManyToOne
+   @JoinColumn(name = "FRIEND_ID")
+   public Member getFriend()
+   {
+      return friend;
+   }
+   
+   public void setFriend(Member friend)
+   {
+      this.friend = friend;
+   }
+      
+   @ManyToOne
+   @JoinColumn(name = "MEMBER_ID")
+   public Member getMember()
+   {
+      return member;
+   }
+   
+   public void setMember(Member member)
+   {
+      this.member = member;
+   }
+
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/Member.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/Member.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/Member.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/Member.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,248 @@
+package org.jboss.seam.security.examples.seamspace.model;
+
+import java.io.Serializable;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import javax.persistence.UniqueConstraint;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+
+/**
+ * A member account
+ * 
+ * @author Shane Bryzak
+ */
+ at Entity
+ at Table(uniqueConstraints = @UniqueConstraint(columnNames = "membername"))
+public class Member implements Serializable
+{
+   private static final long serialVersionUID = 5179242727836683375L;
+   
+   public enum Gender {
+      male("Male", "his"), 
+      female("Female", "her");
+      
+     private String descr;
+     private String possessive;
+     
+     Gender(String descr, String possessive) {
+       this.descr = descr;
+       this.possessive = possessive;
+      }
+     public String getDescr() {
+        return descr;
+     }
+     
+     public String getPossessive() {
+        return possessive;
+     }
+   };
+   
+   private Integer memberId;
+   private String memberName;
+   private String firstName;
+   private String lastName;
+   private String email;
+   private MemberImage picture;
+   
+   private String tagline;
+   private Gender gender;
+   private Date dob;
+   private String location;
+   private Date memberSince;
+   
+   private Set<MemberImage> images;   
+   private Set<MemberFriend> friends;
+
+   @Id @GeneratedValue
+   public Integer getMemberId()
+   {
+      return memberId;
+   }
+
+   public void setMemberId(Integer memberId)
+   {
+      this.memberId = memberId;
+   }
+   
+   @NotNull
+   @Size(min = 3, max = 40)
+   @Pattern(regexp="[a-zA-Z]?[a-zA-Z0-9_]+", 
+         message="Member name must start with a letter, and only contain letters, numbers or underscores")
+   public String getMemberName()
+   {
+      return memberName;
+   }
+
+   public void setMemberName(String memberName)
+   {
+      this.memberName = memberName;
+   }
+   
+   @NotNull
+   @Size(min = 3, max = 40)
+   @Pattern(regexp="[a-zA-Z]+", message="First name must only contain letters")
+   public String getFirstName()
+   {
+      return firstName;
+   }
+   
+   public void setFirstName(String firstName)
+   {
+      this.firstName = firstName;
+   }
+   
+   @NotNull
+   @Size(min = 3, max = 40)
+   @Pattern(regexp="[a-zA-Z]+", message="Last name must only contain letters")
+   public String getLastName()
+   {
+      return lastName;
+   }
+   
+   public void setLastName(String lastName)
+   {
+      this.lastName = lastName;
+   }   
+   
+   @NotNull @Email
+   public String getEmail()
+   {
+      return email;
+   }
+   
+   public void setEmail(String email)
+   {
+      this.email = email;
+   }
+
+   @OneToOne(fetch = FetchType.LAZY)
+   @JoinColumn(name = "PICTURE_ID")
+   public MemberImage getPicture()
+   {
+      return picture;
+   }
+
+   public void setPicture(MemberImage picture)
+   {
+      this.picture = picture;
+   }
+
+   @NotNull
+   public Date getDob()
+   {
+      return dob;
+   }
+
+   public void setDob(Date dob)
+   {
+      this.dob = dob;
+   }
+
+   @NotNull
+   public Gender getGender()
+   {
+      return gender;
+   }
+
+   public void setGender(Gender gender)
+   {
+      this.gender = gender;
+   }
+
+   public String getLocation()
+   {
+      return location;
+   }
+
+   public void setLocation(String location)
+   {
+      this.location = location;
+   }
+   
+   @NotNull
+   public Date getMemberSince()
+   {
+      return memberSince;
+   }
+   
+   public void setMemberSince(Date memberSince)
+   {
+      this.memberSince = memberSince;
+   }
+
+   public String getTagline()
+   {
+      return tagline;
+   }
+
+   public void setTagline(String tagline)
+   {
+      this.tagline = tagline;
+   }
+
+   @OneToMany(mappedBy = "member", fetch = FetchType.LAZY)
+   public Set<MemberImage> getImages()
+   {
+      return images;
+   }
+
+   public void setImages(Set<MemberImage> images)
+   {
+      this.images = images;
+   }
+   
+   @OneToMany(mappedBy = "member")
+   public Set<MemberFriend> getFriends()
+   {
+      return friends;
+   }
+   
+   public void setFriends(Set<MemberFriend> friends)
+   {
+      this.friends = friends;   
+   }
+   
+   @Transient
+   public boolean isFriend(Member member)
+   {
+      for (MemberFriend f : friends)
+      {
+         if (f.getFriend().getMemberId().equals(member.getMemberId())) return true;          
+      }
+      
+      return false;
+   }
+   
+   @Transient
+   public String getAge()
+   {
+      Calendar birthday = new GregorianCalendar();
+      birthday.setTime(dob);
+      int by = birthday.get(Calendar.YEAR);
+      int bm = birthday.get(Calendar.MONTH);
+      int bd = birthday.get(Calendar.DATE);
+      
+      Calendar now = new GregorianCalendar();
+      now.setTimeInMillis(System.currentTimeMillis());
+      int ny = now.get(Calendar.YEAR);
+      int nm = now.get(Calendar.MONTH);
+      int nd = now.get(Calendar.DATE);      
+      
+      int age = ny - by + (nm > bm || (nm == bm && nd >= bd) ? 0 : -1);                              
+      return String.format("%d years old", age);                              
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberAccount.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberAccount.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberAccount.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberAccount.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,120 @@
+package org.jboss.seam.security.examples.seamspace.model;
+
+import java.io.Serializable;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.UniqueConstraint;
+import javax.validation.constraints.NotNull;
+
+import org.jboss.seam.security.annotations.management.PasswordSalt;
+import org.jboss.seam.security.annotations.management.UserEnabled;
+import org.jboss.seam.security.annotations.management.UserPassword;
+import org.jboss.seam.security.annotations.management.UserPrincipal;
+import org.jboss.seam.security.annotations.management.UserRoles;
+
+ at Entity
+ at Table(uniqueConstraints = @UniqueConstraint(columnNames = "username"))
+public class MemberAccount implements Serializable
+{
+   private static final long serialVersionUID = 6368734442192368866L;
+   
+   private Integer accountId;
+   private String username;
+   private String passwordHash;
+   private String passwordSalt;
+   private boolean enabled;   
+   
+   private Set<MemberRole> roles;
+   private Member member;   
+   
+   @Id @GeneratedValue
+   public Integer getAccountId()
+   {
+      return accountId;
+   }
+   
+   public void setAccountId(Integer accountId)
+   {
+      this.accountId = accountId;
+   }
+   
+   @NotNull @UserPrincipal
+   public String getUsername()
+   {
+      return username;
+   }
+   
+   public void setUsername(String username)
+   {
+      this.username = username;
+   }
+   
+   @UserPassword
+   public String getPasswordHash()
+   {
+      return passwordHash;
+   }
+   
+   public void setPasswordHash(String passwordHash)
+   {
+      this.passwordHash = passwordHash;      
+   }
+   
+   @PasswordSalt
+   public String getPasswordSalt()
+   {
+      return passwordSalt;
+   }
+   
+   public void setPasswordSalt(String passwordSalt)
+   {
+      this.passwordSalt = passwordSalt;
+   }
+   
+   @UserEnabled
+   public boolean isEnabled()
+   {
+      return enabled;
+   }
+
+   public void setEnabled(boolean enabled)
+   {
+      this.enabled = enabled;      
+   }   
+
+   @UserRoles
+   @ManyToMany(targetEntity = MemberRole.class)
+   @JoinTable(name = "AccountMembership", 
+         joinColumns = @JoinColumn(name = "AccountId"),
+         inverseJoinColumns = @JoinColumn(name = "MemberOf")
+      )
+   public Set<MemberRole> getRoles()
+   {
+      return roles;
+   }
+   
+   public void setRoles(Set<MemberRole> roles)
+   {
+      this.roles = roles;
+   }
+   
+   @OneToOne
+   @JoinColumn(name = "MEMBER_ID")
+   public Member getMember()
+   {
+      return member;
+   }
+   
+   public void setMember(Member member)
+   {
+      this.member = member;
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberBlog.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberBlog.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberBlog.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberBlog.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,132 @@
+package org.jboss.seam.security.examples.seamspace.model;
+
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.PrePersist;
+import javax.persistence.Transient;
+
+import org.jboss.seam.security.annotations.Restrict;
+
+ at Entity
+public class MemberBlog implements Serializable
+{
+   private static final long serialVersionUID = 7824113911888715595L;
+   
+   private static SimpleDateFormat df = new SimpleDateFormat("EEEE, MMMM d, yyyy - hh:mm a");
+   
+   private Integer blogId;
+   private Member member;
+   private Date entryDate;
+   private String title;
+   private String text;
+   
+   private List<BlogComment> comments;
+   
+   /**
+    * This is an example of a security restriction.  Any attempts to persist a
+    * new memberBlog instance requires the user to pass a permission check.  In 
+    * this case, because the method is annotated with <code>@PrePersist</code> 
+    * the required permission is memberBlog:insert    
+    */
+   @PrePersist @Restrict
+   public void prePersist() {}
+   
+   @Id @GeneratedValue
+   public Integer getBlogId()
+   {
+      return blogId;
+   }
+   
+   public void setBlogId(Integer blogId)
+   {
+      this.blogId = blogId;
+   }
+
+   public Date getEntryDate()
+   {
+      return entryDate;
+   }
+
+   public void setEntryDate(Date entryDate)
+   {
+      this.entryDate = entryDate;
+   }
+   
+   @Transient
+   public String getFormattedEntryDate()
+   {
+      return df.format(entryDate);
+   }
+
+   @ManyToOne
+   @JoinColumn(name = "MEMBER_ID")   
+   public Member getMember()
+   {
+      return member;
+   }
+
+   public void setMember(Member member)
+   {
+      this.member = member;
+   }
+
+   public String getText()
+   {
+      return text;
+   }
+
+   public void setText(String text)
+   {
+      this.text = text;
+   }
+
+   public String getTitle()
+   {
+      return title;
+   }
+
+   public void setTitle(String title)
+   {
+      this.title = title;
+   }
+   
+   @OneToMany(mappedBy = "blog")
+   public List<BlogComment> getComments()
+   {
+      return comments;
+   }
+   
+   public void setComments(List<BlogComment> comments)
+   {
+      this.comments = comments;
+   }
+   
+   @Transient
+   public List<BlogComment> getSortedComments()
+   {
+      Collections.sort(comments, new Comparator<BlogComment>() {
+         public int compare(BlogComment o1, BlogComment o2) {
+            return (int) (o1.getCommentDate().getTime() - o2.getCommentDate().getTime());
+         }
+      });
+      
+      return comments;
+   }
+   
+   @Transient
+   public int getCommentCount()
+   {
+      return comments.size();
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberFriend.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberFriend.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberFriend.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberFriend.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,89 @@
+package org.jboss.seam.security.examples.seamspace.model;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+
+ at Entity
+public class MemberFriend implements Serializable
+{
+   private static final long serialVersionUID = -167586088947004386L;
+   
+   private Integer id;
+   private Member member;
+   private Member friend;
+   
+   private String introduction;
+   private String response;
+   
+   private boolean authorized;
+
+   @Id @GeneratedValue
+   public Integer getId()
+   {
+      return id;
+   }
+   
+   public void setId(Integer id)
+   {
+      this.id = id;
+   }   
+   
+   public boolean isAuthorized()
+   {
+      return authorized;
+   }
+   
+   public void setAuthorized(boolean authorized)
+   {
+      this.authorized = authorized;
+   }
+   
+   @ManyToOne
+   @JoinColumn(name = "FRIEND_ID")
+   public Member getFriend()
+   {
+      return friend;
+   }
+   
+   public void setFriend(Member friend)
+   {
+      this.friend = friend;
+   }
+
+   @ManyToOne
+   @JoinColumn(name = "MEMBER_ID")
+   public Member getMember()
+   {
+      return member;
+   }
+   
+   public void setMember(Member member)
+   {
+      this.member = member;
+   }
+
+   public String getIntroduction()
+   {
+      return introduction;
+   }
+
+   public void setIntroduction(String introduction)
+   {
+      this.introduction = introduction;
+   }
+
+   public String getResponse()
+   {
+      return response;
+   }
+
+   public void setResponse(String response)
+   {
+      this.response = response;
+   }      
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberImage.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberImage.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberImage.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberImage.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,84 @@
+package org.jboss.seam.security.examples.seamspace.model;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.Lob;
+import javax.persistence.ManyToOne;
+
+import org.jboss.seam.security.annotations.permission.Permission;
+import org.jboss.seam.security.annotations.permission.Permissions;
+
+ at Permissions({
+   @Permission(action = "view"),
+   @Permission(action = "comment")
+})
+ at Entity
+public class MemberImage implements Serializable
+{
+   private static final long serialVersionUID = -8088455267213832920L;
+   
+   private Integer imageId;
+   private Member member;
+   private byte[] data;
+   private String contentType;
+   private String caption;
+   
+   @Id @GeneratedValue
+   public Integer getImageId()
+   {
+      return imageId;
+   }
+   
+   public void setImageId(Integer imageId)
+   {
+      this.imageId = imageId;
+   }
+   
+   @ManyToOne
+   @JoinColumn(name = "MEMBER_ID")
+   public Member getMember()
+   {
+      return member;
+   }
+   
+   public void setMember(Member member)
+   {
+      this.member = member;
+   }
+
+   public String getContentType()
+   {
+      return contentType;
+   }
+
+   public void setContentType(String contentType)
+   {
+      this.contentType = contentType;
+   }
+   
+   public String getCaption()
+   {
+      return caption;
+   }
+   
+   public void setCaption(String caption)
+   {
+      this.caption = caption;
+   }
+
+   @Lob
+   public byte[] getData()
+   {
+      return data;
+   }
+
+   public void setData(byte[] data)
+   {
+      this.data = data;
+   }
+
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberRole.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/MemberRole.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberRole.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/model/MemberRole.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,76 @@
+package org.jboss.seam.security.examples.seamspace.model;
+
+import java.io.Serializable;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+
+import org.jboss.seam.security.annotations.management.RoleConditional;
+import org.jboss.seam.security.annotations.management.RoleGroups;
+import org.jboss.seam.security.annotations.management.RoleName;
+
+ at Entity
+public class MemberRole implements Serializable
+{
+   private static final long serialVersionUID = 9177366120789064801L;
+   
+   private Integer roleId;
+   private String name;
+   private boolean conditional;
+   
+   private Set<MemberRole> groups;
+   
+   @Id @GeneratedValue
+   public Integer getRoleId()
+   {
+      return roleId;
+   }
+   
+   public void setRoleId(Integer roleId)
+   {
+      this.roleId = roleId;
+   }
+   
+   @RoleName
+   public String getName()
+   {
+      return name;
+   }
+   
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+   
+   @RoleGroups
+   @ManyToMany(targetEntity = MemberRole.class)
+   @JoinTable(name = "RoleGroup", 
+         joinColumns = @JoinColumn(name = "RoleId"),
+         inverseJoinColumns = @JoinColumn(name = "MemberOf")
+      )
+   public Set<MemberRole> getGroups()
+   {
+      return groups;
+   }
+   
+   public void setGroups(Set<MemberRole> groups)
+   {
+      this.groups = groups;
+   }   
+   
+   @RoleConditional
+   public boolean isConditional()
+   {
+      return conditional;
+   }
+   
+   public void setConditional(boolean conditional)
+   {
+      this.conditional = conditional;
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/util/AuthenticationEvents.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/AuthenticationEvents.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/util/AuthenticationEvents.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/util/AuthenticationEvents.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,15 @@
+package org.jboss.seam.security.examples.seamspace.util;
+
+import javax.inject.Named;
+
+import org.jboss.seam.security.management.JpaIdentityStore;
+
+ at Named
+public class AuthenticationEvents
+{
+   //@Observer(JpaIdentityStore.EVENT_USER_AUTHENTICATED)
+   public void loginSuccessful(MemberAccount account)
+   {
+     // Contexts.getSessionContext().set("authenticatedMember", account.getMember());
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/util/ContentServlet.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/ContentServlet.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/util/ContentServlet.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/util/ContentServlet.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,136 @@
+package org.jboss.seam.security.examples.seamspace.util;
+
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.ImageIO;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.swing.ImageIcon;
+
+
+/**
+ * Serves images and other member content
+ * 
+ * @author Shane Bryzak
+ */
+public class ContentServlet extends HttpServlet
+{
+   private static final long serialVersionUID = -8461940507242022217L;
+
+   private static final String IMAGES_PATH = "/images";
+
+   /**
+    * The maximum width allowed for image rescaling
+    */
+   private static final int MAX_IMAGE_WIDTH = 1024;
+   
+   private byte[] noImage;
+   
+   public ContentServlet()
+   {
+      InputStream in = getClass().getResourceAsStream("/images/no_image.png");
+      if (in != null)
+      {
+         ByteArrayOutputStream out = new ByteArrayOutputStream();
+         byte[] buffer = new byte[512];
+         try
+         {
+            int read = in.read(buffer);
+            while (read != -1)
+            {
+               out.write(buffer, 0, read);
+               read = in.read(buffer);
+            }
+            
+            noImage = out.toByteArray();
+         } 
+         catch (IOException e) { }
+      }
+      
+   }
+
+   @Override
+   protected void doGet(HttpServletRequest request, HttpServletResponse response)
+         throws ServletException, IOException
+   {
+      if (IMAGES_PATH.equals(request.getPathInfo()))
+      {
+         ContentAction contentAction = (ContentAction) Component.getInstance(ContentAction.class);
+
+         String id = request.getParameter("id");
+         MemberImage mi = (id != null && !"".equals(id)) ? 
+               contentAction.getImage(Integer.parseInt(id)) : null;
+         
+         String contentType = null;
+         byte[] data = null;
+         
+         if (mi != null && mi.getData() != null && mi.getData().length > 0)
+         {
+            contentType = mi.getContentType();
+            data = mi.getData();
+         }
+         else if (noImage != null)
+         {
+            contentType = "image/png";
+            data = noImage;
+         }
+         
+         if (data != null)
+         {
+            response.setContentType(contentType);
+   
+            boolean rescale = false;
+            int width = 0;
+            ImageIcon icon = null;
+   
+            // Check if the image needs to be rescaled
+            if (request.getParameter("width") != null)
+            {
+               width = Math.min(MAX_IMAGE_WIDTH, Integer.parseInt(request
+                     .getParameter("width")));
+               icon = new ImageIcon(data);
+               if (width > 0 && width != icon.getIconWidth())
+                  rescale = true;
+            }
+   
+            // Rescale the image if required
+            if (rescale)
+            {
+               double ratio = (double) width / icon.getIconWidth();
+               int height = (int) (icon.getIconHeight() * ratio);
+               
+               int imageType = "image/png".equals(contentType) ? 
+                     BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;                  
+               BufferedImage bImg = new BufferedImage(width, height, imageType);
+               Graphics2D g2d = bImg.createGraphics();
+               g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+                     RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+               g2d.drawImage(icon.getImage(), 0, 0, width, height, null);
+               g2d.dispose();
+   
+               String formatName = "";
+               if (contentType != null && contentType.indexOf("png") != -1)
+                  formatName = "png";
+               else if (contentType != null && (contentType.indexOf("jpg") != -1) ||
+                     contentType.indexOf("jpeg") != -1)
+                  formatName = "jpeg";
+   
+               ImageIO.write(bImg, formatName, response.getOutputStream());
+            }
+            else
+            {
+               response.getOutputStream().write(data);
+            }
+         }
+
+         response.getOutputStream().flush();
+      }
+   }
+}

Copied: modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/util/Hash.java (from rev 12265, modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/Hash.java)
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/util/Hash.java	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/java/org/jboss/seam/security/examples/seamspace/util/Hash.java	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1,38 @@
+package org.jboss.seam.security.examples.seamspace.util;
+
+import java.security.MessageDigest;
+
+import org.jboss.seam.util.Hex;
+
+public class Hash {
+    String hashFunction = "MD5";
+    String charset      = "UTF-8";
+    
+    public String hash(String password) {
+        try {
+            MessageDigest md = MessageDigest.getInstance(hashFunction);
+            md.update(password.getBytes(charset));
+            byte[] raw = md.digest();
+            return new String(Hex.encodeHex(raw));
+        } 
+        catch (Exception e) {
+            throw new RuntimeException(e);        
+        }
+    }
+
+    public String getCharset() {
+        return charset;
+    }
+
+    public void setCharset(String charset) {
+        this.charset = charset;
+    }
+
+    public String getHashFunction() {
+        return hashFunction;
+    }
+
+    public void setHashFunction(String hashFunction) {
+        this.hashFunction = hashFunction;
+    }    
+}

Added: modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/beans.xml
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/beans.xml	                        (rev 0)
+++ modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/beans.xml	2010-03-25 06:53:40 UTC (rev 12269)
@@ -0,0 +1 @@
+



More information about the seam-commits mailing list