[seam-commits] Seam SVN: r10636 - in modules/trunk/security: src/main/java/org/jboss/seam/security/management and 1 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Fri Apr 24 19:27:35 EDT 2009
Author: shane.bryzak at jboss.com
Date: 2009-04-24 19:27:35 -0400 (Fri, 24 Apr 2009)
New Revision: 10636
Modified:
modules/trunk/security/pom.xml
modules/trunk/security/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java
modules/trunk/security/src/main/java/org/jboss/seam/security/management/PasswordHash.java
modules/trunk/security/src/main/java/org/jboss/seam/security/permission/ClassIdentifierStrategy.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/IdentifierPolicy.java
modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PermissionManager.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/PermissionMetadata.java
modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PersistentPermissionResolver.java
modules/trunk/security/src/main/java/org/jboss/seam/security/permission/ResolverChain.java
modules/trunk/security/src/main/java/org/jboss/seam/security/permission/RuleBasedPermissionResolver.java
Log:
more porting of security module
Modified: modules/trunk/security/pom.xml
===================================================================
--- modules/trunk/security/pom.xml 2009-04-24 23:27:12 UTC (rev 10635)
+++ modules/trunk/security/pom.xml 2009-04-24 23:27:35 UTC (rev 10636)
@@ -31,6 +31,11 @@
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.jboss.seam</groupId>
+ <artifactId>seam-drools</artifactId>
+ </dependency>
+
</dependencies>
</project>
Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java 2009-04-24 23:27:12 UTC (rev 10635)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java 2009-04-24 23:27:35 UTC (rev 10636)
@@ -31,9 +31,6 @@
import org.jboss.seam.security.annotations.management.UserPassword;
import org.jboss.seam.security.annotations.management.UserPrincipal;
import org.jboss.seam.security.annotations.management.UserRoles;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.core.Expressions;
-import org.jboss.seam.core.Expressions.ValueExpression;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
import org.jboss.seam.security.Identity;
@@ -63,7 +60,9 @@
private ValueExpression<EntityManager> entityManager;
private Bean<EntityManager> entityManagerBean;
+
@Current Manager manager;
+ @Current PasswordHash passwordHash;
private Class<?> userClass;
private Class<?> roleClass;
@@ -271,7 +270,7 @@
*/
public byte[] generateUserSalt(Object user)
{
- return PasswordHash.instance().generateRandomSalt();
+ return passwordHash.generateRandomSalt();
}
public boolean createUser(String username, String password)
@@ -744,7 +743,7 @@
{
try
{
- return PasswordHash.instance().createPasswordKey(password.toCharArray(), salt,
+ return passwordHash.createPasswordKey(password.toCharArray(), salt,
userPasswordProperty.getAnnotation().iterations());
}
catch (GeneralSecurityException ex)
@@ -771,11 +770,11 @@
{
if (salt == null || "".equals(salt))
{
- return PasswordHash.instance().generateHash(password);
+ return passwordHash.generateHash(password);
}
else
{
- return PasswordHash.instance().generateSaltedHash(password, salt);
+ return passwordHash.generateSaltedHash(password, salt);
}
}
else if ("none".equalsIgnoreCase(algorithm))
@@ -786,11 +785,11 @@
{
if (salt == null || "".equals(salt))
{
- return PasswordHash.instance().generateHash(password, algorithm);
+ return passwordHash.generateHash(password, algorithm);
}
else
{
- return PasswordHash.instance().generateSaltedHash(password, salt, algorithm);
+ return passwordHash.generateSaltedHash(password, salt, algorithm);
}
}
}
Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/management/PasswordHash.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/management/PasswordHash.java 2009-04-24 23:27:12 UTC (rev 10635)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/management/PasswordHash.java 2009-04-24 23:27:35 UTC (rev 10636)
@@ -1,37 +1,28 @@
package org.jboss.seam.security.management;
-import static org.jboss.seam.ScopeType.STATELESS;
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.SecureRandom;
+import javax.annotation.Named;
+import javax.context.Dependent;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-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.security.crypto.BinTools;
import org.jboss.seam.security.crypto.PBKDF2;
import org.jboss.seam.security.crypto.PBKDF2Engine;
import org.jboss.seam.security.crypto.PBKDF2Parameters;
-import org.jboss.seam.util.Base64;
+import org.jboss.seam.security.util.Base64;
/**
* Password hashing utility functions
*
* @author Shane Bryzak
*/
- at Scope(STATELESS)
- at Name("org.jboss.seam.security.passwordHash")
- at Install(precedence = BUILT_IN)
- at BypassInterceptors
+ at Named
+ at Dependent
public class PasswordHash
{
public static final String ALGORITHM_MD5 = "MD5";
@@ -127,11 +118,6 @@
}
}
- public static PasswordHash instance()
- {
- return (PasswordHash) Component.getInstance(PasswordHash.class, ScopeType.STATELESS);
- }
-
public String getHashAlgorithm()
{
return hashAlgorithm;
Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/permission/ClassIdentifierStrategy.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/permission/ClassIdentifierStrategy.java 2009-04-24 23:27:12 UTC (rev 10635)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/ClassIdentifierStrategy.java 2009-04-24 23:27:35 UTC (rev 10636)
@@ -3,14 +3,16 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import org.jboss.seam.Seam;
-import org.jboss.seam.annotations.security.permission.Identifier;
+import javax.context.Dependent;
+import org.jboss.seam.security.annotations.permission.Identifier;
+
/**
* An Identifier strategy for class-based permission checks
*
* @author Shane Bryzak
*/
+ at Dependent
public class ClassIdentifierStrategy implements IdentifierStrategy
{
private Map<Class,String> identifierNames = new ConcurrentHashMap<Class,String>();
@@ -47,11 +49,6 @@
if (name == null)
{
- name = Seam.getComponentName(cls);
- }
-
- if (name == null)
- {
name = cls.getName().substring(cls.getName().lastIndexOf('.') + 1);
}
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-24 23:27:12 UTC (rev 10635)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/EntityIdentifierStrategy.java 2009-04-24 23:27:35 UTC (rev 10636)
@@ -3,22 +3,22 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import javax.context.Dependent;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
-import org.jboss.seam.Component;
-import org.jboss.seam.Seam;
-import org.jboss.seam.annotations.security.permission.Identifier;
+import org.jboss.seam.security.annotations.permission.Identifier;
import org.jboss.seam.core.Expressions;
import org.jboss.seam.core.Expressions.ValueExpression;
import org.jboss.seam.persistence.PersistenceProvider;
-import org.jboss.seam.util.Strings;
+import org.jboss.seam.security.util.Strings;
/**
* An Identifier strategy for entity-based permission checks
*
* @author Shane Bryzak
*/
+ at Dependent
public class EntityIdentifierStrategy implements IdentifierStrategy
{
private ValueExpression<EntityManager> entityManager;
@@ -63,14 +63,9 @@
name = identifier.name();
}
}
-
+
if (name == null)
{
- name = Seam.getComponentName(cls);
- }
-
- if (name == null)
- {
name = cls.getName().substring(cls.getName().lastIndexOf('.') + 1);
}
Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/permission/IdentifierPolicy.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/permission/IdentifierPolicy.java 2009-04-24 23:27:12 UTC (rev 10635)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/IdentifierPolicy.java 2009-04-24 23:27:35 UTC (rev 10636)
@@ -1,19 +1,15 @@
package org.jboss.seam.security.permission;
-import static org.jboss.seam.ScopeType.APPLICATION;
-
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-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.Identifier;
+import javax.context.ApplicationScoped;
+import javax.inject.Initializer;
+import org.jboss.seam.security.annotations.permission.Identifier;
+
/**
* A policy for the generation of object "identifiers" - unique Strings that identify a specific
* instance of an object. A policy can consist of numerous identifier strategies, each with the
@@ -21,17 +17,14 @@
*
* @author Shane Bryzak
*/
- at Name("org.jboss.seam.security.identifierPolicy")
- at Scope(APPLICATION)
- at BypassInterceptors
- at Install(precedence = Install.BUILT_IN)
+ at ApplicationScoped
public class IdentifierPolicy
{
private Map<Class,IdentifierStrategy> strategies = new ConcurrentHashMap<Class,IdentifierStrategy>();
private Set<IdentifierStrategy> registeredStrategies = new HashSet<IdentifierStrategy>();
- @Create
+ @Initializer
public void create()
{
if (registeredStrategies.isEmpty())
Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PermissionManager.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PermissionManager.java 2009-04-24 23:27:12 UTC (rev 10635)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PermissionManager.java 2009-04-24 23:27:35 UTC (rev 10636)
@@ -1,21 +1,14 @@
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.util.List;
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-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.contexts.Contexts;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
+import javax.annotation.Named;
+import javax.inject.Current;
+
import org.jboss.seam.security.Identity;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
/**
* Permission management component, used to grant or revoke permissions on specific objects or of
@@ -23,56 +16,20 @@
*
* @author Shane Bryzak
*/
- at Scope(APPLICATION)
- at Name("org.jboss.seam.security.permissionManager")
- at Install(precedence = BUILT_IN)
+ at Named
public class PermissionManager implements Serializable
{
- public static final String PERMISSION_STORE_COMPONENT_NAME = "org.jboss.seam.security.jpaPermissionStore";
+ private static final long serialVersionUID = -2694925751585231813L;
- public static final String PERMISSION_PERMISSION_NAME = "seam.permission";
-
public static final String PERMISSION_READ = "seam.read-permissions";
public static final String PERMISSION_GRANT = "seam.grant-permission";
public static final String PERMISSION_REVOKE = "seam.revoke-permission";
private static final LogProvider log = Logging.getLogProvider(PermissionManager.class);
- private PermissionStore permissionStore;
-
- @Create
- public void create()
- {
- if (permissionStore == null)
- {
- permissionStore = (PermissionStore) Component.getInstance(PERMISSION_STORE_COMPONENT_NAME, true);
- }
-
- if (permissionStore == null)
- {
- log.warn("no permission store available - please install a PermissionStore with the name '" +
- PERMISSION_STORE_COMPONENT_NAME + "' if permission management is required.");
- }
- }
-
- public static PermissionManager instance()
- {
- if ( !Contexts.isApplicationContextActive() )
- {
- throw new IllegalStateException("No active application context");
- }
-
- PermissionManager instance = (PermissionManager) Component.getInstance(
- PermissionManager.class, ScopeType.APPLICATION);
-
- if (instance == null)
- {
- throw new IllegalStateException("No PermissionManager could be created");
- }
-
- return instance;
- }
-
+ @Current PermissionStore permissionStore;
+ @Current Identity identity;
+
public PermissionStore getPermissionStore()
{
return permissionStore;
@@ -86,20 +43,20 @@
public List<Permission> listPermissions(Object target, String action)
{
if (target == null) return null;
- Identity.instance().checkPermission(target, PERMISSION_READ);
+ identity.checkPermission(target, PERMISSION_READ);
return permissionStore.listPermissions(target, action);
}
public List<Permission> listPermissions(Object target)
{
if (target == null) return null;
- Identity.instance().checkPermission(target, PERMISSION_READ);
+ identity.checkPermission(target, PERMISSION_READ);
return permissionStore.listPermissions(target);
}
public boolean grantPermission(Permission permission)
{
- Identity.instance().checkPermission(permission.getTarget(), PERMISSION_GRANT);
+ identity.checkPermission(permission.getTarget(), PERMISSION_GRANT);
return permissionStore.grantPermission(permission);
}
@@ -107,14 +64,14 @@
{
for (Permission permission : permissions)
{
- Identity.instance().checkPermission(permission.getTarget(), PERMISSION_GRANT);
+ identity.checkPermission(permission.getTarget(), PERMISSION_GRANT);
}
return permissionStore.grantPermissions(permissions);
}
public boolean revokePermission(Permission permission)
{
- Identity.instance().checkPermission(permission.getTarget(), PERMISSION_REVOKE);
+ identity.checkPermission(permission.getTarget(), PERMISSION_REVOKE);
return permissionStore.revokePermission(permission);
}
@@ -122,7 +79,7 @@
{
for (Permission permission : permissions)
{
- Identity.instance().checkPermission(permission.getTarget(), PERMISSION_REVOKE);
+ identity.checkPermission(permission.getTarget(), PERMISSION_REVOKE);
}
return permissionStore.revokePermissions(permissions);
}
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-24 23:27:12 UTC (rev 10635)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PermissionMapper.java 2009-04-24 23:27:35 UTC (rev 10636)
@@ -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.util.Collection;
import java.util.HashMap;
@@ -10,27 +7,14 @@
import java.util.Map;
import java.util.Set;
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Startup;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.core.Events;
-import org.jboss.seam.core.Init;
+import javax.context.ApplicationScoped;
/**
* Maps permission checks to resolver chains
*
* @author Shane Bryzak
*/
- at Scope(APPLICATION)
- at Name("org.jboss.seam.security.permissionMapper")
- at Install(precedence = BUILT_IN)
- at BypassInterceptors
- at Startup
+ at ApplicationScoped
public class PermissionMapper implements Serializable
{
public static final String DEFAULT_RESOLVER_CHAIN_CREATED = "org.jboss.seam.security.defaultResolverChainCreated";
@@ -168,22 +152,4 @@
return chain;
}
-
- public static PermissionMapper instance()
- {
- if ( !Contexts.isApplicationContextActive() )
- {
- throw new IllegalStateException("No active application context");
- }
-
- PermissionMapper instance = (PermissionMapper) Component.getInstance(
- PermissionMapper.class, ScopeType.APPLICATION);
-
- if (instance == null)
- {
- throw new IllegalStateException("No PermissionMapper could be created");
- }
-
- return instance;
- }
}
Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PermissionMetadata.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PermissionMetadata.java 2009-04-24 23:27:12 UTC (rev 10635)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PermissionMetadata.java 2009-04-24 23:27:35 UTC (rev 10636)
@@ -7,7 +7,7 @@
import java.util.Map;
import java.util.Set;
-import org.jboss.seam.annotations.security.permission.Permissions;
+import org.jboss.seam.security.annotations.permission.Permissions;
/**
* Permission actions can either be persisted as a comma-separated list of values, or as a
@@ -33,10 +33,10 @@
Permissions p = (Permissions) cls.getAnnotation(Permissions.class);
if (p != null)
{
- org.jboss.seam.annotations.security.permission.Permission[] permissions = p.value();
+ org.jboss.seam.security.annotations.permission.Permission[] permissions = p.value();
if (permissions != null)
{
- for (org.jboss.seam.annotations.security.permission.Permission permission : permissions)
+ for (org.jboss.seam.security.annotations.permission.Permission permission : permissions)
{
actions.put(permission.action(), permission.mask());
Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PersistentPermissionResolver.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PersistentPermissionResolver.java 2009-04-24 23:27:12 UTC (rev 10635)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/PersistentPermissionResolver.java 2009-04-24 23:27:35 UTC (rev 10636)
@@ -1,23 +1,16 @@
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.util.Iterator;
import java.util.List;
import java.util.Set;
-import org.jboss.seam.Component;
-import org.jboss.seam.Seam;
-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.Startup;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
+import javax.inject.Current;
+import javax.inject.Initializer;
+import javax.inject.manager.Manager;
+
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
import org.jboss.seam.security.Identity;
import org.jboss.seam.security.Role;
import org.jboss.seam.security.SimplePrincipal;
@@ -28,34 +21,28 @@
*
* @author Shane Bryzak
*/
- at Name("org.jboss.seam.security.persistentPermissionResolver")
- at Scope(APPLICATION)
- at BypassInterceptors
- at Install(precedence=BUILT_IN)
- at Startup
public class PersistentPermissionResolver implements PermissionResolver, Serializable
{
+ private static final long serialVersionUID = -603389172032219059L;
+
private PermissionStore permissionStore;
- private static final LogProvider log = Logging.getLogProvider(PersistentPermissionResolver.class);
+ private static final LogProvider log = Logging.getLogProvider(PersistentPermissionResolver.class);
- @Create
- public void create()
+ @Current Manager manager;
+ @Current Identity identity;
+
+ @Initializer
+ public void initPermissionStore()
{
- initPermissionStore();
- }
-
- protected void initPermissionStore()
- {
if (permissionStore == null)
- {
- permissionStore = (PermissionStore) Component.getInstance(JpaPermissionStore.class, true);
+ {
+ permissionStore = manager.getInstanceByType(JpaPermissionStore.class);
}
if (permissionStore == null)
{
- log.warn("no permission store available - please install a PermissionStore with the name '" +
- Seam.getComponentName(JpaPermissionStore.class) + "' if persistent permissions are required.");
+ log.warn("no permission store available - please install a PermissionStore if persistent permissions are required.");
}
}
@@ -72,9 +59,7 @@
public boolean hasPermission(Object target, String action)
{
if (permissionStore == null) return false;
-
- Identity identity = Identity.instance();
-
+
if (!identity.isLoggedIn()) return false;
List<Permission> permissions = permissionStore.listPermissions(target, action);
@@ -112,7 +97,6 @@
{
if (permissionStore == null) return;
- Identity identity = Identity.instance();
if (!identity.isLoggedIn()) return;
List<Permission> permissions = permissionStore.listPermissions(targets, action);
Modified: modules/trunk/security/src/main/java/org/jboss/seam/security/permission/ResolverChain.java
===================================================================
--- modules/trunk/security/src/main/java/org/jboss/seam/security/permission/ResolverChain.java 2009-04-24 23:27:12 UTC (rev 10635)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/ResolverChain.java 2009-04-24 23:27:35 UTC (rev 10636)
@@ -1,13 +1,10 @@
package org.jboss.seam.security.permission;
-import static org.jboss.seam.ScopeType.SESSION;
-
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import javax.context.SessionScoped;
/**
* A chain of permission resolvers. Specific permission checks are generally mapped to a
@@ -15,10 +12,11 @@
*
* @author Shane Bryzak
*/
- at Scope(SESSION)
- at BypassInterceptors
+ at SessionScoped
public class ResolverChain implements Serializable
{
+ private static final long serialVersionUID = 4395507285094476740L;
+
private List<PermissionResolver> resolvers = new ArrayList<PermissionResolver>();
public List<PermissionResolver> getResolvers()
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-24 23:27:12 UTC (rev 10635)
+++ modules/trunk/security/src/main/java/org/jboss/seam/security/permission/RuleBasedPermissionResolver.java 2009-04-24 23:27:35 UTC (rev 10636)
@@ -12,26 +12,22 @@
import java.util.List;
import java.util.Set;
+import javax.context.SessionScoped;
+import javax.event.Observes;
+import javax.inject.manager.Initialized;
+
import org.drools.FactHandle;
import org.drools.RuleBase;
import org.drools.StatefulSession;
import org.drools.base.ClassObjectFilter;
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.Seam;
-import org.jboss.seam.annotations.Create;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Observer;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Startup;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.drools.SeamGlobalResolver;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
import org.jboss.seam.security.Identity;
import org.jboss.seam.security.Role;
+import org.jboss.seam.security.events.LoggedOutEvent;
+import org.jboss.seam.security.events.PostAuthenticateEvent;
import org.jboss.seam.security.management.JpaIdentityStore;
/**
@@ -39,11 +35,7 @@
*
* @author Shane Bryzak
*/
- at Name("org.jboss.seam.security.ruleBasedPermissionResolver")
- at Scope(SESSION)
- at BypassInterceptors
- at Install(precedence=BUILT_IN, classDependencies="org.drools.WorkingMemory")
- at Startup
+ at SessionScoped
public class RuleBasedPermissionResolver implements PermissionResolver, Serializable
{
public static final String RULES_COMPONENT_NAME = "securityRules";
@@ -54,7 +46,9 @@
private RuleBase securityRules;
- @Create
+ @Current Identity identity;
+
+ @Initialized
public boolean create()
{
initSecurityContext();
@@ -202,8 +196,7 @@
}
@SuppressWarnings("unchecked")
- @Observer(Identity.EVENT_LOGGED_OUT)
- public void unAuthenticate()
+ public void unAuthenticate(@Observes LoggedOutEvent event)
{
if (getSecurityContext() != null)
{
@@ -217,9 +210,7 @@
* Synchronises the state of the security context with that of the subject
*/
private void synchronizeContext()
- {
- Identity identity = Identity.instance();
-
+ {
if (getSecurityContext() != null)
{
getSecurityContext().insert(identity.getPrincipal());
@@ -310,12 +301,11 @@
/**
* Post-authentication event observer
*/
- @Observer(Identity.EVENT_POST_AUTHENTICATE)
- public void setUserAccountInSecurityContext()
+ public void setUserAccountInSecurityContext(@Observes PostAuthenticateEvent event)
{
if (getSecurityContext() != null)
{
- getSecurityContext().insert(Identity.instance().getPrincipal());
+ getSecurityContext().insert(identity.getPrincipal());
// If we were authenticated with the JpaIdentityStore, then insert the authenticated
// UserAccount into the security context.
More information about the seam-commits
mailing list