Author: manaRH
Date: 2011-10-28 13:13:21 -0400 (Fri, 28 Oct 2011)
New Revision: 14239
Modified:
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/ClassIdentifierStrategy.java
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/EntityIdentifierStrategy.java
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/IdentifierPolicy.java
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/IdentifierStrategy.java
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/PermissionMetadata.java
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/util/AnnotatedBeanProperty.java
Log:
JBSEAM-4829 clusterable changes
Modified:
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java
===================================================================
---
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java 2011-10-28
15:33:42 UTC (rev 14238)
+++
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/management/JpaIdentityStore.java 2011-10-28
17:13:21 UTC (rev 14239)
@@ -57,6 +57,9 @@
@BypassInterceptors
public class JpaIdentityStore implements IdentityStore, Serializable
{
+
+ private static final long serialVersionUID = -3627993296654916436L;
+
public static final String AUTHENTICATED_USER =
"org.jboss.seam.security.management.authenticatedUser";
public static final String EVENT_USER_CREATED =
"org.jboss.seam.security.management.userCreated";
Modified:
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/ClassIdentifierStrategy.java
===================================================================
---
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/ClassIdentifierStrategy.java 2011-10-28
15:33:42 UTC (rev 14238)
+++
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/ClassIdentifierStrategy.java 2011-10-28
17:13:21 UTC (rev 14239)
@@ -1,5 +1,6 @@
package org.jboss.seam.security.permission;
+import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -11,11 +12,13 @@
*
* @author Shane Bryzak
*/
-public class ClassIdentifierStrategy implements IdentifierStrategy
+public class ClassIdentifierStrategy implements IdentifierStrategy, Serializable
{
- private Map<Class,String> identifierNames = new
ConcurrentHashMap<Class,String>();
+ private static final long serialVersionUID = 3338883246522630571L;
- public boolean canIdentify(Class targetClass)
+ private Map<Class<?>,String> identifierNames = new
ConcurrentHashMap<Class<?>,String>();
+
+ public boolean canIdentify(Class<?> targetClass)
{
return Class.class.equals(targetClass);
}
@@ -27,10 +30,10 @@
throw new IllegalArgumentException("Target [" + target + "] must
be instance of Class");
}
- return getIdentifierName((Class) target);
+ return getIdentifierName((Class<?>) target);
}
- private String getIdentifierName(Class cls)
+ private String getIdentifierName(Class<?> cls)
{
if (!identifierNames.containsKey(cls))
{
Modified:
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/EntityIdentifierStrategy.java
===================================================================
---
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/EntityIdentifierStrategy.java 2011-10-28
15:33:42 UTC (rev 14238)
+++
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/EntityIdentifierStrategy.java 2011-10-28
17:13:21 UTC (rev 14239)
@@ -1,5 +1,6 @@
package org.jboss.seam.security.permission;
+import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -19,37 +20,49 @@
*
* @author Shane Bryzak
*/
-public class EntityIdentifierStrategy implements IdentifierStrategy
+public class EntityIdentifierStrategy implements IdentifierStrategy, Serializable
{
- private ValueExpression<EntityManager> entityManager;
+
+ private static final long serialVersionUID = 12456789L;
+
+ private transient ValueExpression<EntityManager> entityManager;
- private PersistenceProvider persistenceProvider;
+ private transient PersistenceProvider persistenceProvider;
- private Map<Class,String> identifierNames = new
ConcurrentHashMap<Class,String>();
-
- public EntityIdentifierStrategy()
+ private Map<Class <?>,String> identifierNames = new
ConcurrentHashMap<Class <?>,String>();
+
+ public void init()
{
- persistenceProvider = (PersistenceProvider)
Component.getInstance(PersistenceProvider.class, true);
-
+ if (persistenceProvider == null)
+ {
+ persistenceProvider = (PersistenceProvider)
Component.getInstance(PersistenceProvider.class, true);
+ }
+
if (entityManager == null)
{
- entityManager =
Expressions.instance().createValueExpression("#{entityManager}",
- EntityManager.class);
- }
+ entityManager =
Expressions.instance().createValueExpression("#{entityManager}",
EntityManager.class);
+ }
+
}
+
+ public EntityIdentifierStrategy()
+ {
+ init();
+ }
- public boolean canIdentify(Class targetClass)
+ public boolean canIdentify(Class<?> targetClass)
{
return targetClass.isAnnotationPresent(Entity.class);
}
public String getIdentifier(Object target)
{
- return String.format("%s:%s", getIdentifierName(target.getClass()),
- persistenceProvider.getId(target, lookupEntityManager()).toString());
+ if(persistenceProvider == null) init();
+ Object persProviderId = persistenceProvider.getId(target,
lookupEntityManager()).toString();
+ return String.format("%s:%s", getIdentifierName(target.getClass()),
persProviderId);
}
- private String getIdentifierName(Class cls)
+ private String getIdentifierName(Class<? extends Object> cls)
{
if (!identifierNames.containsKey(cls))
{
@@ -57,7 +70,7 @@
if (cls.isAnnotationPresent(Identifier.class))
{
- Identifier identifier = (Identifier) cls.getAnnotation(Identifier.class);
+ Identifier identifier = cls.getAnnotation(Identifier.class);
if ( !Strings.isEmpty(identifier.name()) )
{
name = identifier.name();
@@ -83,6 +96,7 @@
private EntityManager lookupEntityManager()
{
+ if(entityManager == null) init();
return entityManager.getValue();
}
}
Modified:
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/IdentifierPolicy.java
===================================================================
---
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/IdentifierPolicy.java 2011-10-28
15:33:42 UTC (rev 14238)
+++
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/IdentifierPolicy.java 2011-10-28
17:13:21 UTC (rev 14239)
@@ -2,6 +2,7 @@
import static org.jboss.seam.ScopeType.APPLICATION;
+import java.io.Serializable;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -25,9 +26,12 @@
@Scope(APPLICATION)
@BypassInterceptors
@Install(precedence = Install.BUILT_IN)
-public class IdentifierPolicy
+public class IdentifierPolicy implements Serializable
{
- private Map<Class,IdentifierStrategy> strategies = new
ConcurrentHashMap<Class,IdentifierStrategy>();
+
+ private static final long serialVersionUID = 684295244567560969L;
+
+ private Map<Class <?>,IdentifierStrategy> strategies = new
ConcurrentHashMap<Class<?>,IdentifierStrategy>();
private Set<IdentifierStrategy> registeredStrategies = new
HashSet<IdentifierStrategy>();
Modified:
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/IdentifierStrategy.java
===================================================================
---
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/IdentifierStrategy.java 2011-10-28
15:33:42 UTC (rev 14238)
+++
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/IdentifierStrategy.java 2011-10-28
17:13:21 UTC (rev 14239)
@@ -7,6 +7,6 @@
*/
public interface IdentifierStrategy
{
- boolean canIdentify(Class targetClass);
+ boolean canIdentify(Class<?> targetClass);
String getIdentifier(Object target);
}
Modified:
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/PermissionMetadata.java
===================================================================
---
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/PermissionMetadata.java 2011-10-28
15:33:42 UTC (rev 14238)
+++
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/security/permission/PermissionMetadata.java 2011-10-28
17:13:21 UTC (rev 14239)
@@ -1,5 +1,6 @@
package org.jboss.seam.security.permission;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -17,12 +18,13 @@
*
* @author Shane Bryzak
*/
-public class PermissionMetadata
+public class PermissionMetadata implements Serializable
{
- private Map<Class,Boolean> usesActionMask = new HashMap<Class,Boolean>();
- private Map<Class,Map<String,Long>> classActions = new
HashMap<Class,Map<String,Long>>();
+ private static final long serialVersionUID = 7407543457388705950L;
+ private Map<Class<?>,Boolean> usesActionMask = new
HashMap<Class<?>,Boolean>();
+ private Map<Class<?>,Map<String,Long>> classActions = new
HashMap<Class<?>,Map<String,Long>>();
- private synchronized void initClassActions(Class cls)
+ private synchronized void initClassActions(Class<?> cls)
{
if (!classActions.containsKey(cls))
{
@@ -86,9 +88,9 @@
protected class ActionSet
{
private Set<String> members = new HashSet<String>();
- private Class targetClass;
+ private Class<?> targetClass;
- public ActionSet(Class targetClass, String members)
+ public ActionSet(Class<?> targetClass, String members)
{
this.targetClass = targetClass;
addMembers(members);
@@ -179,14 +181,14 @@
}
}
- public ActionSet createActionSet(Class targetClass, String members)
+ public ActionSet createActionSet(Class<?> targetClass, String members)
{
if (!classActions.containsKey(targetClass)) initClassActions(targetClass);
return new ActionSet(targetClass, members);
}
- public List<String> listAllowableActions(Class targetClass)
+ public List<String> listAllowableActions(Class<?> targetClass)
{
if (!classActions.containsKey(targetClass)) initClassActions(targetClass);
Modified:
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/util/AnnotatedBeanProperty.java
===================================================================
---
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/util/AnnotatedBeanProperty.java 2011-10-28
15:33:42 UTC (rev 14238)
+++
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/util/AnnotatedBeanProperty.java 2011-10-28
17:13:21 UTC (rev 14239)
@@ -1,6 +1,7 @@
package org.jboss.seam.util;
import java.beans.Introspector;
+import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -12,11 +13,12 @@
*
* @author Shane Bryzak
*/
-public class AnnotatedBeanProperty<T extends Annotation>
+public class AnnotatedBeanProperty<T extends Annotation> implements Serializable
{
- private Field propertyField;
- private Method propertyGetter;
- private Method propertySetter;
+ private static final long serialVersionUID = 2508430507136805635L;
+ private transient Field propertyField;
+ private transient Method propertyGetter;
+ private transient Method propertySetter;
private String name;
private Type propertyType;
private T annotation;
@@ -24,18 +26,28 @@
private boolean isFieldProperty;
private boolean set = false;
- public AnnotatedBeanProperty(Class<?> cls, Class<T> annotationClass)
+ private Class<?> cls;
+ private Class<? extends Annotation> annotationClass;
+
+ public AnnotatedBeanProperty(Class<?> cls, Class<? extends Annotation>
annotationClass)
{
- // First check declared fields
- for (Field f : cls.getDeclaredFields())
- {
- if (f.isAnnotationPresent(annotationClass))
+ this.cls = cls;
+ this.annotationClass = annotationClass;
+ init();
+ }
+
+ private void init()
+ {
+ // First check declared fields
+ for (Field f : cls.getDeclaredFields())
{
- setupFieldProperty(f);
- this.annotation = f.getAnnotation(annotationClass);
- set = true;
- return;
- }
+ if (f.isAnnotationPresent(annotationClass))
+ {
+ setupFieldProperty(f);
+ this.annotation = (T) f.getAnnotation(annotationClass);
+ set = true;
+ return;
+ }
}
// Then check public fields, in case it's inherited
@@ -43,7 +55,7 @@
{
if (f.isAnnotationPresent(annotationClass))
{
- this.annotation = f.getAnnotation(annotationClass);
+ this.annotation = (T) f.getAnnotation(annotationClass);
setupFieldProperty(f);
set = true;
return;
@@ -55,7 +67,7 @@
{
if (m.isAnnotationPresent(annotationClass))
{
- this.annotation = m.getAnnotation(annotationClass);
+ this.annotation = (T) m.getAnnotation(annotationClass);
String methodName = m.getName();
if ( m.getName().startsWith("get") )
@@ -84,6 +96,33 @@
}
}
+ public Field getPropertyField()
+ {
+ if (propertyField == null)
+ {
+ init();
+ }
+ return propertyField;
+ }
+
+ public Method getPropertyGetter()
+ {
+ if (propertyGetter == null)
+ {
+ init();
+ }
+ return propertyGetter;
+ }
+
+ public Method getPropertySetter()
+ {
+ if (propertySetter == null)
+ {
+ init();
+ }
+ return propertySetter;
+ }
+
private void setupFieldProperty(Field propertyField)
{
this.propertyField = propertyField;
@@ -96,11 +135,11 @@
{
if (isFieldProperty)
{
- Reflections.setAndWrap(propertyField, bean, value);
+ Reflections.setAndWrap(getPropertyField(), bean, value);
}
else
{
- Reflections.invokeAndWrap(propertySetter, bean, value);
+ Reflections.invokeAndWrap(getPropertySetter(), bean, value);
}
}
@@ -108,11 +147,11 @@
{
if (isFieldProperty)
{
- return Reflections.getAndWrap(propertyField, bean);
+ return Reflections.getAndWrap(getPropertyField(), bean);
}
else
{
- return Reflections.invokeAndWrap(propertyGetter, bean);
+ return Reflections.invokeAndWrap(getPropertyGetter(), bean);
}
}
@@ -123,7 +162,7 @@
public T getAnnotation()
{
- return annotation;
+ return (T) annotation;
}
public Type getPropertyType()