[seam-commits] Seam SVN: r10664 - in modules/trunk/security: src/main/java/org/jboss/seam/security and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Apr 27 22:45:17 EDT 2009


Author: shane.bryzak at jboss.com
Date: 2009-04-27 22:45:16 -0400 (Mon, 27 Apr 2009)
New Revision: 10664

Added:
   modules/trunk/security/src/main/java/org/jboss/seam/security/events/DefaultResolverChainCreatedEvent.java
Modified:
   modules/trunk/security/pom.xml
   modules/trunk/security/src/main/java/org/jboss/seam/security/EntityPermissionChecker.java
   modules/trunk/security/src/main/java/org/jboss/seam/security/JpaTokenStore.java
   modules/trunk/security/src/main/java/org/jboss/seam/security/permission/EntityIdentifierStrategy.java
   modules/trunk/security/src/main/java/org/jboss/seam/security/permission/JpaPermissionStore.java
   modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PermissionMapper.java
   modules/trunk/security/src/main/java/org/jboss/seam/security/permission/RuleBasedPermissionResolver.java
   modules/trunk/security/src/main/java/org/jboss/seam/security/permission/action/PermissionSearch.java
Log:
convert more security components

Modified: modules/trunk/security/pom.xml
===================================================================
--- modules/trunk/security/pom.xml	2009-04-28 02:43:30 UTC (rev 10663)
+++ modules/trunk/security/pom.xml	2009-04-28 02:45:16 UTC (rev 10664)
@@ -32,10 +32,29 @@
          <artifactId>jsf-api</artifactId>
       </dependency>  
       <dependency>
+         <groupId>javax.ejb</groupId>
+         <artifactId>ejb-api</artifactId>
+      </dependency>
+      <dependency>
+         <groupId>org.drools</groupId>
+         <artifactId>drools-core</artifactId>
+      </dependency>
+      <dependency>
          <groupId>org.jboss.seam</groupId>
          <artifactId>seam-drools</artifactId>        
       </dependency>
-      
+      <dependency>
+         <groupId>org.jboss.seam</groupId>
+         <artifactId>seam-el</artifactId>        
+      </dependency>
+      <dependency>
+         <groupId>org.jboss.seam</groupId>
+         <artifactId>seam-persistence</artifactId>        
+      </dependency>
+      <dependency>
+         <groupId>org.hibernate</groupId>
+         <artifactId>hibernate</artifactId>
+      </dependency>      
    </dependencies>
 
 </project>

Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/EntityPermissionChecker.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/EntityPermissionChecker.java	2009-04-28 02:43:30 UTC (rev 10663)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/EntityPermissionChecker.java	2009-04-28 02:45:16 UTC (rev 10664)
@@ -3,12 +3,13 @@
 import java.lang.reflect.Method;
 
 import javax.context.ApplicationScoped;
+import javax.inject.Current;
+import javax.inject.manager.Manager;
 import javax.persistence.EntityManager;
 
-import org.jboss.seam.annotations.security.Restrict;
-import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.security.annotations.Restrict;
 import org.jboss.seam.persistence.PersistenceProvider;
-import org.jboss.seam.util.Strings;
+import org.jboss.seam.security.util.Strings;
 
 /**
  * Entity permission checks
@@ -19,6 +20,8 @@
 public class EntityPermissionChecker
 {
    private String entityManagerName = "entityManager";
+  
+   @Current Manager manager;
    
    private EntityManager getEntityManager()
    {
@@ -35,35 +38,15 @@
       this.entityManagerName = name;
    } 
    
-   public static EntityPermissionChecker instance()
-   {
-      if ( !Contexts.isApplicationContextActive() )
-      {
-         throw new IllegalStateException("No active application context");
-      }
-
-      EntityPermissionChecker instance = (EntityPermissionChecker) Component.getInstance(
-            EntityPermissionChecker.class, ScopeType.APPLICATION);
-
-      if (instance == null)
-      {
-         throw new IllegalStateException("No EntityPermissionChecker could be created");
-      }
-
-      return instance;      
-   }
-   
    public void checkEntityPermission(Object entity, EntityAction action)
    {      
       if (!Identity.isSecurityEnabled()) return;
       
-      if (!Contexts.isSessionContextActive()) return;
-      
-      Identity identity = Identity.instance();
-      
+      Identity identity = manager.getInstanceByType(Identity.class);
       identity.tryLogin();
       
-      PersistenceProvider provider = PersistenceProvider.instance(); 
+      PersistenceProvider provider = manager.getInstanceByType(PersistenceProvider.class);
+      
       Class beanClass = provider.getBeanClass(entity);
       
       if (beanClass != null)

Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/JpaTokenStore.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/JpaTokenStore.java	2009-04-28 02:43:30 UTC (rev 10663)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/JpaTokenStore.java	2009-04-28 02:45:16 UTC (rev 10664)
@@ -1,37 +1,28 @@
 package org.jboss.seam.security;
 
-import static org.jboss.seam.ScopeType.APPLICATION;
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
 import java.io.Serializable;
 
+import javax.context.ApplicationScoped;
+import javax.inject.Initializer;
 import javax.persistence.EntityManager;
 import javax.persistence.NoResultException;
 import javax.persistence.Query;
 
-import org.jboss.seam.annotations.Create;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.annotations.security.TokenUsername;
-import org.jboss.seam.annotations.security.TokenValue;
-import org.jboss.seam.core.Expressions;
-import org.jboss.seam.core.Expressions.ValueExpression;
+import org.jboss.seam.security.annotations.TokenUsername;
+import org.jboss.seam.security.annotations.TokenValue;
 import org.jboss.seam.security.management.IdentityManagementException;
-import org.jboss.seam.util.AnnotatedBeanProperty;
+import org.jboss.seam.security.util.AnnotatedBeanProperty;
 
 /**
  * A TokenStore implementation, stores tokens inside a database table.
  * 
  * @author Shane Bryzak
  */
- at Name("org.jboss.seam.security.tokenStore")
- at Install(precedence = BUILT_IN, value=false) 
- at Scope(APPLICATION)
- at BypassInterceptors
+ at ApplicationScoped
 public class JpaTokenStore implements TokenStore, Serializable
 {
+   private static final long serialVersionUID = -1984227349549914828L;
+
    private Class tokenClass;
    
    private ValueExpression<EntityManager> entityManager;    
@@ -39,7 +30,7 @@
    private AnnotatedBeanProperty<TokenUsername> tokenUsernameProperty;
    private AnnotatedBeanProperty<TokenValue> tokenValueProperty;
    
-   @Create
+   @Initializer
    public void create()
    {
       if (entityManager == null)

Added: modules/trunk/security/src/main/java/org/jboss/seam/security/events/DefaultResolverChainCreatedEvent.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/events/DefaultResolverChainCreatedEvent.java	                        (rev 0)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/events/DefaultResolverChainCreatedEvent.java	2009-04-28 02:45:16 UTC (rev 10664)
@@ -0,0 +1,23 @@
+package org.jboss.seam.security.events;
+
+import org.jboss.seam.security.permission.ResolverChain;
+
+/**
+ * This event is raised when the default permission resolver chain is created
+ *  
+ * @author Shane Bryzak
+ */
+public class DefaultResolverChainCreatedEvent
+{
+   private ResolverChain chain;
+   
+   public DefaultResolverChainCreatedEvent(ResolverChain chain)
+   {
+      this.chain = chain;
+   }
+   
+   public ResolverChain getChain()
+   {
+      return chain;
+   }
+}

Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/permission/EntityIdentifierStrategy.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/permission/EntityIdentifierStrategy.java	2009-04-28 02:43:30 UTC (rev 10663)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/EntityIdentifierStrategy.java	2009-04-28 02:45:16 UTC (rev 10664)
@@ -22,15 +22,13 @@
 public class EntityIdentifierStrategy implements IdentifierStrategy
 {
    private ValueExpression<EntityManager> entityManager;   
-   
-   private PersistenceProvider persistenceProvider;
-   
+     
    private Map<Class,String> identifierNames = new ConcurrentHashMap<Class,String>();
    
+   @Current PersistenceProvider persistenceProvider;
+   
    public EntityIdentifierStrategy()
-   {
-      persistenceProvider = (PersistenceProvider) Component.getInstance(PersistenceProvider.class, true);
-      
+   {      
       if (entityManager == null)
       {
          entityManager = Expressions.instance().createValueExpression("#{entityManager}", 

Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/permission/JpaPermissionStore.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/permission/JpaPermissionStore.java	2009-04-28 02:43:30 UTC (rev 10663)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/JpaPermissionStore.java	2009-04-28 02:45:16 UTC (rev 10664)
@@ -1,8 +1,5 @@
 package org.jboss.seam.security.permission;
 
-import static org.jboss.seam.ScopeType.APPLICATION;
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
 import java.io.Serializable;
 import java.security.Principal;
 import java.util.ArrayList;
@@ -12,41 +9,36 @@
 import java.util.Map;
 import java.util.Set;
 
+import javax.context.ApplicationScoped;
+import javax.inject.Current;
+import javax.inject.Initializer;
+import javax.inject.manager.Manager;
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
-import org.jboss.seam.Component;
-import org.jboss.seam.annotations.Create;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.annotations.security.permission.PermissionAction;
-import org.jboss.seam.annotations.security.permission.PermissionDiscriminator;
-import org.jboss.seam.annotations.security.permission.PermissionRole;
-import org.jboss.seam.annotations.security.permission.PermissionTarget;
-import org.jboss.seam.annotations.security.permission.PermissionUser;
-import org.jboss.seam.core.Expressions;
-import org.jboss.seam.core.Expressions.ValueExpression;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
+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;
+import org.jboss.seam.el.Expressions;
+import org.jboss.seam.el.Expressions.ValueExpression;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
 import org.jboss.seam.security.Role;
 import org.jboss.seam.security.SimplePrincipal;
 import org.jboss.seam.security.management.IdentityManager;
 import org.jboss.seam.security.management.IdentityStore;
 import org.jboss.seam.security.management.JpaIdentityStore;
 import org.jboss.seam.security.permission.PermissionMetadata.ActionSet;
-import org.jboss.seam.util.AnnotatedBeanProperty;
+import org.jboss.seam.security.util.AnnotatedBeanProperty;
 
 /**
  * A permission store implementation that uses JPA as its persistence mechanism.
  * 
  * @author Shane Bryzak
  */
- at Name("org.jboss.seam.security.jpaPermissionStore")
- at Install(precedence = BUILT_IN, value=false) 
- at Scope(APPLICATION)
- at BypassInterceptors
+ at ApplicationScoped
 public class JpaPermissionStore implements PermissionStore, Serializable
 {
    private static final LogProvider log = Logging.getLogProvider(JpaPermissionStore.class);
@@ -69,12 +61,14 @@
    private AnnotatedBeanProperty<PermissionAction> roleActionProperty;
    
    private Map<Integer,String> queryCache = new HashMap<Integer,String>();
+     
+   private PermissionMetadata metadata;
    
-   private IdentifierPolicy identifierPolicy;
+   @Current IdentifierPolicy identifierPolicy;
+   @Current Manager manager;
+   @Current IdentityManager identityManager;
    
-   private PermissionMetadata metadata;
-
-   @Create
+   @Initializer
    public void init()
    {
       metadata = new PermissionMetadata();
@@ -93,8 +87,6 @@
       }       
       
       initProperties();
-      
-      identifierPolicy = (IdentifierPolicy) Component.getInstance(IdentifierPolicy.class, true);
    }   
    
    protected void initProperties()
@@ -543,7 +535,7 @@
    {
       boolean recipientIsRole = recipient instanceof Role;
          
-      JpaIdentityStore identityStore = (JpaIdentityStore) Component.getInstance(JpaIdentityStore.class, true);
+      JpaIdentityStore identityStore = manager.getInstanceByType(JpaIdentityStore.class);
       
       if (identityStore != null)
       {
@@ -562,11 +554,9 @@
    
    protected Principal resolvePrincipal(Object principal, boolean isUser)
    {
-      IdentityStore ids = IdentityManager.instance().getRoleIdentityStore();
-      JpaIdentityStore identityStore = null;
+      identityManager.getRoleIdentityStore();
+      JpaIdentityStore identityStore = null;      
       
-      if (ids instanceof JpaIdentityStore) identityStore = (JpaIdentityStore) ids;
-      
       if (principal instanceof String)
       {        
          return isUser ? new SimplePrincipal((String) principal) : new Role((String) principal, 

Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PermissionMapper.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PermissionMapper.java	2009-04-28 02:43:30 UTC (rev 10663)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PermissionMapper.java	2009-04-28 02:45:16 UTC (rev 10664)
@@ -8,7 +8,12 @@
 import java.util.Set;
 
 import javax.context.ApplicationScoped;
+import javax.inject.Current;
+import javax.inject.manager.Bean;
+import javax.inject.manager.Manager;
 
+import org.jboss.seam.security.events.DefaultResolverChainCreatedEvent;
+
 /**
  * Maps permission checks to resolver chains
  * 
@@ -25,6 +30,8 @@
    
    private static final String DEFAULT_RESOLVER_CHAIN = "org.jboss.seam.security.defaultResolverChain";
    
+   @Current Manager manager;
+   
    private ResolverChain getResolverChain(Object target, String action)
    {
       Class targetClass = null;
@@ -44,13 +51,13 @@
          Map<String,String> chains = resolverChains.get(target);
          if (chains != null && chains.containsKey(action))
          {
-            return (ResolverChain) Component.getInstance(chains.get(action), true);
+            return (ResolverChain) manager.getInstanceByName(chains.get(action));
          }
       }      
       
       if (defaultResolverChain != null && !"".equals(defaultResolverChain))
       {
-         return (ResolverChain) Component.getInstance(defaultResolverChain, true);   
+         return (ResolverChain) manager.getInstanceByName(defaultResolverChain);   
       }
       
       return createDefaultResolverChain();
@@ -141,13 +148,15 @@
       {
          chain = new ResolverChain();
          
-         for (String resolverName : Init.instance().getPermissionResolvers())
+         Set<Bean<PermissionResolver>> resolvers = manager.resolveByType(PermissionResolver.class);
+         for (Bean<PermissionResolver> resolverBean : resolvers)
          {
-            chain.getResolvers().add((PermissionResolver) Component.getInstance(resolverName, true)); 
+            chain.getResolvers().add((PermissionResolver) manager.getInstance(resolverBean));  
          }
          
          Contexts.getSessionContext().set(DEFAULT_RESOLVER_CHAIN, chain);
-         if (Events.exists()) Events.instance().raiseEvent(DEFAULT_RESOLVER_CHAIN_CREATED, chain);
+         
+         manager.fireEvent(new DefaultResolverChainCreatedEvent(chain));
       }
       
       return chain;

Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/permission/RuleBasedPermissionResolver.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/permission/RuleBasedPermissionResolver.java	2009-04-28 02:43:30 UTC (rev 10663)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/RuleBasedPermissionResolver.java	2009-04-28 02:45:16 UTC (rev 10664)
@@ -1,8 +1,5 @@
 package org.jboss.seam.security.permission;
 
-import static org.jboss.seam.ScopeType.SESSION;
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
 import java.io.Serializable;
 import java.security.Principal;
 import java.security.acl.Group;
@@ -14,6 +11,8 @@
 
 import javax.context.SessionScoped;
 import javax.event.Observes;
+import javax.inject.Current;
+import javax.inject.Initializer;
 import javax.inject.manager.Initialized;
 
 import org.drools.FactHandle;
@@ -48,7 +47,7 @@
    
    @Current Identity identity;
    
-   @Initialized
+   @Initializer
    public boolean create()
    {
       initSecurityContext();
@@ -280,24 +279,6 @@
       this.securityRules = securityRules;
    }       
    
-   public static RuleBasedPermissionResolver instance()
-   {
-      if ( !Contexts.isSessionContextActive() )
-      {
-         throw new IllegalStateException("No active session context");
-      }
-
-      RuleBasedPermissionResolver instance = (RuleBasedPermissionResolver) Component.getInstance(
-            RuleBasedPermissionResolver.class, ScopeType.SESSION);
-
-      if (instance == null)
-      {
-         throw new IllegalStateException("No RuleBasedPermissionResolver could be created");
-      }
-
-      return instance;
-   }
-   
    /**
     * Post-authentication event observer
     */

Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/permission/action/PermissionSearch.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/permission/action/PermissionSearch.java	2009-04-28 02:43:30 UTC (rev 10663)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/action/PermissionSearch.java	2009-04-28 02:45:16 UTC (rev 10664)
@@ -1,8 +1,5 @@
 package org.jboss.seam.security.permission.action;
 
-import static org.jboss.seam.ScopeType.CONVERSATION;
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
 import java.io.Serializable;
 import java.security.Principal;
 import java.util.ArrayList;
@@ -10,20 +7,19 @@
 import java.util.List;
 import java.util.Map;
 
-import org.jboss.seam.annotations.Begin;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
+import javax.annotation.Named;
+import javax.context.Conversation;
+import javax.context.ConversationScoped;
+import javax.inject.Current;
+
 import org.jboss.seam.annotations.datamodel.DataModel;
 import org.jboss.seam.annotations.datamodel.DataModelSelection;
 import org.jboss.seam.security.management.IdentityManager;
 import org.jboss.seam.security.permission.Permission;
 import org.jboss.seam.security.permission.PermissionManager;
 
- at Scope(CONVERSATION)
- at Name("org.jboss.seam.security.permission.permissionSearch")
- at Install(precedence = BUILT_IN)
+ at Named
+ at ConversationScoped
 public class PermissionSearch implements Serializable
 {
    private Map<Principal,List<Permission>> groupedPermissions = new HashMap<Principal,List<Permission>>();
@@ -34,15 +30,17 @@
    @DataModelSelection
    Principal selectedRecipient;
    
-   @In IdentityManager identityManager;
+   @Current IdentityManager identityManager;
    
-   @In PermissionManager permissionManager;
+   @Current PermissionManager permissionManager;
    
+   @Current Conversation conversation;
+   
    private Object target;
    
-   @Begin
    public void search(Object target)
    {
+      conversation.begin();
       this.target = target;      
    }
    




More information about the seam-commits mailing list