Seam SVN: r7690 - branches/Seam_2_0/doc/Seam_Reference_Guide/en.
by seam-commits@lists.jboss.org
Author: jbalunas(a)redhat.com
Date: 2008-03-25 10:18:04 -0400 (Tue, 25 Mar 2008)
New Revision: 7690
Modified:
branches/Seam_2_0/doc/Seam_Reference_Guide/en/Configuration.xml
branches/Seam_2_0/doc/Seam_Reference_Guide/en/Persistence.xml
Log:
Reverted changes made for JPA - JBSEAM-1946.
This will be handled differently.
Modified: branches/Seam_2_0/doc/Seam_Reference_Guide/en/Configuration.xml
===================================================================
--- branches/Seam_2_0/doc/Seam_Reference_Guide/en/Configuration.xml 2008-03-25 12:45:08 UTC (rev 7689)
+++ branches/Seam_2_0/doc/Seam_Reference_Guide/en/Configuration.xml 2008-03-25 14:18:04 UTC (rev 7690)
@@ -421,50 +421,6 @@
</sect2>
</sect1>
-
- <sect1 id="alt-jpa-providers">
- <title>Using Alternate JPA Providers</title>
-
- <para> Seam comes packaged and configured with Hibernate as the primary JPA provider.
- This helps with the <emphasis>Configuration by Exception</emphasis> concept.
- If you require using a different JPA provider you must tell <literal>seam</literal>
- about it.
- </para>
-
- <para>This can be be done in one of two ways:
- <itemizedlist>
- <listitem>
- <para>Update your application's <literal>components.xml</literal>
- so that the generic <literal>PersistenceProvider</literal> takes
- precedence over the hibernate version. Simply add the following
- to the file:
- <programlisting><![CDATA[<component name="org.jboss.seam.persistence.persistenceProvider"
- class="org.jboss.seam.persistence.PersistenceProvider"
- scope="stateless">
-</component>]]></programlisting>
- </para>
- </listitem>
- <listitem>
- <para>If you want to take advantage of your JPA providers
- non-standard features you will need to write you own implementation of
- the <literal>PersistenceProvider</literal>. Use
- <literal>HibernatePersistenceProvider</literal> as a starting
- point (don't forget to provide it to the community :). Then you
- will need to tell <literal>seam</literal> to use it as before.
- <programlisting><![CDATA[<component name="org.jboss.seam.persistence.persistenceProvider"
- class="org.your.package.YourPersistenceProvider">
-</component>]]></programlisting>
-
- </para>
- </listitem>
- </itemizedlist>
- </para>
- <para>All that is left is updating the <literal>persistence.xml</literal>
- file with the correct provider class, and what ever properties it
- needs. Don't forget to package your new provider's jar files in the
- application if they are needed.
- </para>
- </sect1>
<sect1>
<title>Configuring Seam in Java EE 5</title>
Modified: branches/Seam_2_0/doc/Seam_Reference_Guide/en/Persistence.xml
===================================================================
--- branches/Seam_2_0/doc/Seam_Reference_Guide/en/Persistence.xml 2008-03-25 12:45:08 UTC (rev 7689)
+++ branches/Seam_2_0/doc/Seam_Reference_Guide/en/Persistence.xml 2008-03-25 14:18:04 UTC (rev 7690)
@@ -484,8 +484,7 @@
API via the <literal>getDelegate()</literal> method. Naturally, the most interesting
vendor is Hibernate, and the most powerful delegate interface is
<literal>org.hibernate.Session</literal>. You'd be nuts to use anything else. Trust
- me, I'm not biased at all. For configuring alternate JPA providers see
- <link linkend="alt-jpa-providers">Using Alternate JPA Providers</link>
+ me, I'm not biased at all.
</para>
<para>
16 years, 11 months
Seam SVN: r7689 - branches/Seam_2_0/doc/Seam_Reference_Guide/common.
by seam-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-03-25 08:45:08 -0400 (Tue, 25 Mar 2008)
New Revision: 7689
Modified:
branches/Seam_2_0/doc/Seam_Reference_Guide/common/
Log:
ignores
Property changes on: branches/Seam_2_0/doc/Seam_Reference_Guide/common
___________________________________________________________________
Name: svn:ignore
+ Version_Info.xml
16 years, 11 months
Seam SVN: r7688 - maven-plugins/trunk/seam-docbook-xslt/src/main/resources/xslt/org/jboss/seam.
by seam-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-03-25 08:42:31 -0400 (Tue, 25 Mar 2008)
New Revision: 7688
Modified:
maven-plugins/trunk/seam-docbook-xslt/src/main/resources/xslt/org/jboss/seam/main-html.xsl
maven-plugins/trunk/seam-docbook-xslt/src/main/resources/xslt/org/jboss/seam/nochunk-html.xsl
Log:
JBSEAM-2777
Modified: maven-plugins/trunk/seam-docbook-xslt/src/main/resources/xslt/org/jboss/seam/main-html.xsl
===================================================================
--- maven-plugins/trunk/seam-docbook-xslt/src/main/resources/xslt/org/jboss/seam/main-html.xsl 2008-03-25 11:45:18 UTC (rev 7687)
+++ maven-plugins/trunk/seam-docbook-xslt/src/main/resources/xslt/org/jboss/seam/main-html.xsl 2008-03-25 12:42:31 UTC (rev 7688)
@@ -14,7 +14,6 @@
<!-- Needs MPJDOCBOOK-8 -->
<!-- <xsl:import href="classpath:/xslt/org/jboss/main-html.xsl"/>-->
<xsl:import href="../main-html.xsl" />
- <xsl:import href="version.xsl" />
<xsl:import href="common-xhtml.xsl" />
<xsl:param name="html.stylesheet" select="'css/seamframework.css'" />
Modified: maven-plugins/trunk/seam-docbook-xslt/src/main/resources/xslt/org/jboss/seam/nochunk-html.xsl
===================================================================
--- maven-plugins/trunk/seam-docbook-xslt/src/main/resources/xslt/org/jboss/seam/nochunk-html.xsl 2008-03-25 11:45:18 UTC (rev 7687)
+++ maven-plugins/trunk/seam-docbook-xslt/src/main/resources/xslt/org/jboss/seam/nochunk-html.xsl 2008-03-25 12:42:31 UTC (rev 7688)
@@ -16,7 +16,6 @@
<!-- <xsl:import href="classpath:/xslt/org/jboss/nochunk-html.xsl"/>-->
<xsl:import href="../nochunk-html.xsl" />
<xsl:import href="common-xhtml.xsl" />
- <xsl:import href="version.xsl" />
<xsl:param name="html.stylesheet" select="'css/seamframework-nochunk.css'" />
16 years, 11 months
Seam SVN: r7687 - trunk/src/main/org/jboss/seam/persistence.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2008-03-25 07:45:18 -0400 (Tue, 25 Mar 2008)
New Revision: 7687
Modified:
trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
Log:
disabled hibernate entity security
Modified: trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2008-03-25 11:44:28 UTC (rev 7686)
+++ trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2008-03-25 11:45:18 UTC (rev 7687)
@@ -396,6 +396,7 @@
return null;
}
+ /*
@Override
public Method getPostLoadMethod(Class beanClass, EntityManager entityManager)
{
@@ -419,7 +420,7 @@
public Method getPreRemoveMethod(Class beanClass, EntityManager entityManager)
{
return getCallbackMethod(entityManager, beanClass, "preRemoves");
- }
+ }*/
private Session getSession(EntityManager entityManager)
{
16 years, 11 months
Seam SVN: r7686 - branches/Seam_2_0/src/main/org/jboss/seam/persistence.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2008-03-25 07:44:28 -0400 (Tue, 25 Mar 2008)
New Revision: 7686
Modified:
branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
Log:
disabled hibernate entity security
Modified: branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2008-03-25 11:08:19 UTC (rev 7685)
+++ branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2008-03-25 11:44:28 UTC (rev 7686)
@@ -337,9 +337,9 @@
* @param entityManager
* @return
*/
- private EntityCallbackHandler getCallbackHandler(EntityManager entityManager)
+ private EntityCallbackHandler getCallbackHandler(Session session)
{
- PostLoadEventListener[] listeners = ((SessionImplementor) getSession(entityManager))
+ PostLoadEventListener[] listeners = ((SessionImplementor) session)
.getListeners().getPostLoadEventListeners();
for (PostLoadEventListener listener : listeners)
@@ -371,9 +371,18 @@
{
try
{
- Field f = EntityCallbackHandler.class.getField(fieldName);
- HashMap<Class,Callback[]> callbacks = (HashMap<Class,Callback[]>) f.get(handler);
- return callbacks.get(beanClass);
+ Field f = EntityCallbackHandler.class.getDeclaredField(fieldName);
+ boolean isAccessible = f.isAccessible();
+ try
+ {
+ f.setAccessible(true);
+ HashMap<Class,Callback[]> callbacks = (HashMap<Class,Callback[]>) f.get(handler);
+ return callbacks.get(beanClass);
+ }
+ finally
+ {
+ f.setAccessible(isAccessible);
+ }
}
catch (Exception ex)
{
@@ -381,10 +390,27 @@
}
}
- private Method getCallbackMethod(EntityManager entityManager, Class beanClass, String callbackFieldName)
+ private Method getCallbackMethod(Object persistenceContext, Class beanClass, String callbackFieldName)
{
- Callback[] callbacks = getCallbacks(getCallbackHandler(entityManager), callbackFieldName, beanClass);
+ EntityCallbackHandler callbackHandler = null;
+ if (persistenceContext instanceof EntityManager)
+ {
+ callbackHandler = getCallbackHandler(getSession((EntityManager) persistenceContext));
+ }
+ else if (persistenceContext instanceof Session)
+ {
+ callbackHandler = getCallbackHandler((Session) persistenceContext);
+ }
+
+ if (callbackHandler == null)
+ {
+ throw new RuntimeException("Could not determine callback handler for persistence context " +
+ persistenceContext);
+ }
+
+ Callback[] callbacks = getCallbacks(callbackHandler, callbackFieldName, beanClass);
+
if (callbacks != null)
{
for (Callback cb : callbacks)
@@ -396,30 +422,30 @@
return null;
}
- @Override
- public Method getPostLoadMethod(Class beanClass, EntityManager entityManager)
+ /*@Override
+ public Method getPostLoadMethod(Class beanClass, Object persistenceContext)
{
- return getCallbackMethod(entityManager, beanClass, "postLoads");
+ return getCallbackMethod(persistenceContext, beanClass, "postLoads");
}
@Override
- public Method getPrePersistMethod(Class beanClass, EntityManager entityManager)
+ public Method getPrePersistMethod(Class beanClass, Object persistenceContext)
{
- return getCallbackMethod(entityManager, beanClass, "preCreates");
+ return getCallbackMethod(persistenceContext, beanClass, "preCreates");
}
@Override
- public Method getPreUpdateMethod(Class beanClass, EntityManager entityManager)
+ public Method getPreUpdateMethod(Class beanClass, Object persistenceContext)
{
- return getCallbackMethod(entityManager, beanClass, "preUpdates");
+ return getCallbackMethod(persistenceContext, beanClass, "preUpdates");
}
@Override
- public Method getPreRemoveMethod(Class beanClass, EntityManager entityManager)
+ public Method getPreRemoveMethod(Class beanClass, Object persistenceContext)
{
- return getCallbackMethod(entityManager, beanClass, "preRemoves");
- }
+ return getCallbackMethod(persistenceContext, beanClass, "preRemoves");
+ }*/
private Session getSession(EntityManager entityManager)
{
16 years, 11 months
Seam SVN: r7685 - branches/Seam_2_0/src/main/org/jboss/seam/persistence.
by seam-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-03-25 07:08:19 -0400 (Tue, 25 Mar 2008)
New Revision: 7685
Modified:
branches/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java
Log:
Maintain API compatibility
Modified: branches/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java 2008-03-25 11:07:21 UTC (rev 7684)
+++ branches/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java 2008-03-25 11:08:19 UTC (rev 7685)
@@ -171,4 +171,30 @@
return Entity.forClass(beanClass).getPreRemoveMethod();
}
+ @Deprecated
+ public Method getPreRemoveMethod(Class beanClass)
+ {
+ return Entity.forClass(beanClass).getPreRemoveMethod();
+ }
+
+ @Deprecated
+ public Method getPostLoadMethod(Class beanClass)
+ {
+ return Entity.forClass(beanClass).getPostLoadMethod();
+ }
+
+ @Deprecated
+ public Method getPrePersistMethod(Class beanClass)
+ {
+ return Entity.forClass(beanClass).getPrePersistMethod();
+ }
+
+ @Deprecated
+ public Method getPreUpdateMethod(Class beanClass)
+ {
+ return Entity.forClass(beanClass).getPreUpdateMethod();
+ }
+
+
+
}
16 years, 11 months
Seam SVN: r7684 - branches/Seam_2_0/src/main/org/jboss/seam/security.
by seam-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-03-25 07:07:21 -0400 (Tue, 25 Mar 2008)
New Revision: 7684
Modified:
branches/Seam_2_0/src/main/org/jboss/seam/security/Identity.java
Log:
Remove unused imports
Modified: branches/Seam_2_0/src/main/org/jboss/seam/security/Identity.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/security/Identity.java 2008-03-25 10:47:38 UTC (rev 7683)
+++ branches/Seam_2_0/src/main/org/jboss/seam/security/Identity.java 2008-03-25 11:07:21 UTC (rev 7684)
@@ -5,7 +5,6 @@
import java.io.IOException;
import java.io.Serializable;
-import java.lang.reflect.Method;
import java.security.Principal;
import java.security.acl.Group;
import java.util.ArrayList;
@@ -23,22 +22,18 @@
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.Scope;
import org.jboss.seam.annotations.Startup;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.core.Events;
import org.jboss.seam.core.Expressions;
import org.jboss.seam.core.Expressions.MethodExpression;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
-import org.jboss.seam.persistence.PersistenceProvider;
-import org.jboss.seam.util.Strings;
import org.jboss.seam.web.Session;
/**
16 years, 11 months
Seam SVN: r7683 - tags.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2008-03-25 06:47:38 -0400 (Tue, 25 Mar 2008)
New Revision: 7683
Added:
tags/JBPAPP_4_2_CP03/
Log:
creating tag for EAP 4.2 CP03 and EAP 4.3 CP01
Copied: tags/JBPAPP_4_2_CP03 (from rev 7682, branches/Seam_1_2_1_AP)
16 years, 11 months
Seam SVN: r7682 - in branches/Seam_2_0: src/main/org/jboss/seam/persistence and 1 other directories.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2008-03-24 20:57:14 -0400 (Mon, 24 Mar 2008)
New Revision: 7682
Added:
branches/Seam_2_0/src/main/org/jboss/seam/security/EntityPermissionChecker.java
Modified:
branches/Seam_2_0/build/core.pom.xml
branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
branches/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java
branches/Seam_2_0/src/main/org/jboss/seam/security/EntitySecurityListener.java
branches/Seam_2_0/src/main/org/jboss/seam/security/HibernateSecurityInterceptor.java
branches/Seam_2_0/src/main/org/jboss/seam/security/Identity.java
Log:
JBSEAM-2029
Modified: branches/Seam_2_0/build/core.pom.xml
===================================================================
--- branches/Seam_2_0/build/core.pom.xml 2008-03-24 21:03:57 UTC (rev 7681)
+++ branches/Seam_2_0/build/core.pom.xml 2008-03-25 00:57:14 UTC (rev 7682)
@@ -42,7 +42,6 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
- <scope>runtime</scope>
<optional>true</optional>
</dependency>
Modified: branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2008-03-24 21:03:57 UTC (rev 7681)
+++ branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2008-03-25 00:57:14 UTC (rev 7682)
@@ -4,6 +4,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityManager;
@@ -15,6 +16,11 @@
import org.hibernate.Session;
import org.hibernate.StaleStateException;
import org.hibernate.TransientObjectException;
+import org.hibernate.ejb.event.Callback;
+import org.hibernate.ejb.event.EJB3PostLoadEventListener;
+import org.hibernate.ejb.event.EntityCallbackHandler;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.event.PostLoadEventListener;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.type.VersionType;
import org.jboss.seam.ScopeType;
@@ -322,30 +328,99 @@
}
}
- /*@Override
- public Method getPostLoadMethod(Class beanClass)
+ /**
+ * A nasty hack until we get a nicer method in Hibernate to use instead
+ *
+ * TODO fix this once Hibernate exposes an API method to return the callback method/s for a
+ * given bean class
+ *
+ * @param entityManager
+ * @return
+ */
+ private EntityCallbackHandler getCallbackHandler(EntityManager entityManager)
{
+ PostLoadEventListener[] listeners = ((SessionImplementor) getSession(entityManager))
+ .getListeners().getPostLoadEventListeners();
+
+ for (PostLoadEventListener listener : listeners)
+ {
+ if (listener instanceof EJB3PostLoadEventListener)
+ {
+ try
+ {
+ Field callbackHandlerField = EJB3PostLoadEventListener.class.getField("callbackHandler");
+ return (EntityCallbackHandler) callbackHandlerField.get(listener);
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * More nastiness
+ *
+ * @param handler
+ * @param fieldName
+ * @return
+ */
+ private Callback[] getCallbacks(EntityCallbackHandler handler, String fieldName, Class beanClass)
+ {
+ try
+ {
+ Field f = EntityCallbackHandler.class.getField(fieldName);
+ HashMap<Class,Callback[]> callbacks = (HashMap<Class,Callback[]>) f.get(handler);
+ return callbacks.get(beanClass);
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private Method getCallbackMethod(EntityManager entityManager, Class beanClass, String callbackFieldName)
+ {
+ Callback[] callbacks = getCallbacks(getCallbackHandler(entityManager), callbackFieldName, beanClass);
+
+ if (callbacks != null)
+ {
+ for (Callback cb : callbacks)
+ {
+ return cb.getCallbackMethod();
+ }
+ }
+
return null;
}
@Override
- public Method getPrePersistMethod(Class beanClass)
+ public Method getPostLoadMethod(Class beanClass, EntityManager entityManager)
{
- return null;
+ return getCallbackMethod(entityManager, beanClass, "postLoads");
}
+
@Override
- public Method getPreUpdateMethod(Class beanClass)
+ public Method getPrePersistMethod(Class beanClass, EntityManager entityManager)
{
- return null;
+ return getCallbackMethod(entityManager, beanClass, "preCreates");
}
@Override
- public Method getPreRemoveMethod(Class beanClass)
+ public Method getPreUpdateMethod(Class beanClass, EntityManager entityManager)
{
- return null;
- }*/
+ return getCallbackMethod(entityManager, beanClass, "preUpdates");
+ }
+ @Override
+ public Method getPreRemoveMethod(Class beanClass, EntityManager entityManager)
+ {
+ return getCallbackMethod(entityManager, beanClass, "preRemoves");
+ }
+
private Session getSession(EntityManager entityManager)
{
Object delegate = entityManager.getDelegate();
Modified: branches/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java 2008-03-24 21:03:57 UTC (rev 7681)
+++ branches/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java 2008-03-25 00:57:14 UTC (rev 7682)
@@ -151,22 +151,22 @@
return Entity.forClass(bean.getClass()).getBeanClass();
}
- public Method getPostLoadMethod(Class beanClass)
+ public Method getPostLoadMethod(Class beanClass, EntityManager entityManager)
{
return Entity.forClass(beanClass).getPostLoadMethod();
}
- public Method getPrePersistMethod(Class beanClass)
+ public Method getPrePersistMethod(Class beanClass, EntityManager entityManager)
{
return Entity.forClass(beanClass).getPrePersistMethod();
}
- public Method getPreUpdateMethod(Class beanClass)
+ public Method getPreUpdateMethod(Class beanClass, EntityManager entityManager)
{
return Entity.forClass(beanClass).getPreUpdateMethod();
}
- public Method getPreRemoveMethod(Class beanClass)
+ public Method getPreRemoveMethod(Class beanClass, EntityManager entityManager)
{
return Entity.forClass(beanClass).getPreRemoveMethod();
}
Added: branches/Seam_2_0/src/main/org/jboss/seam/security/EntityPermissionChecker.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/security/EntityPermissionChecker.java (rev 0)
+++ branches/Seam_2_0/src/main/org/jboss/seam/security/EntityPermissionChecker.java 2008-03-25 00:57:14 UTC (rev 7682)
@@ -0,0 +1,126 @@
+package org.jboss.seam.security;
+
+import static org.jboss.seam.ScopeType.APPLICATION;
+import static org.jboss.seam.annotations.Install.BUILT_IN;
+
+import java.lang.reflect.Method;
+
+import javax.persistence.EntityManager;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.Seam;
+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.annotations.security.Restrict;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.persistence.PersistenceProvider;
+import org.jboss.seam.util.Strings;
+
+/**
+ * Entity permission checks
+ *
+ * @author Shane Bryzak
+ */
+@Name("org.jboss.seam.security.entityPermissionChecker")
+@Scope(APPLICATION)
+@Install(precedence = BUILT_IN)
+@BypassInterceptors
+@Startup
+public class EntityPermissionChecker
+{
+ private String entityManagerName = "entityManager";
+
+ private EntityManager getEntityManager()
+ {
+ return (EntityManager) Component.getInstance(entityManagerName);
+ }
+
+ public String getEntityManagerName()
+ {
+ return entityManagerName;
+ }
+
+ public void setEntityManagerName(String name)
+ {
+ 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;
+
+ Identity identity = Identity.instance();
+
+ identity.isLoggedIn(true);
+
+ PersistenceProvider provider = PersistenceProvider.instance();
+ Class beanClass = provider.getBeanClass(entity);
+
+ if (beanClass != null)
+ {
+ String name = Seam.getComponentName(entity.getClass());
+ if (name == null) name = beanClass.getName();
+
+ Method m = null;
+ switch (action)
+ {
+ case READ:
+ m = provider.getPostLoadMethod(beanClass, getEntityManager());
+ break;
+ case INSERT:
+ m = provider.getPrePersistMethod(beanClass, getEntityManager());
+ break;
+ case UPDATE:
+ m = provider.getPreUpdateMethod(beanClass, getEntityManager());
+ break;
+ case DELETE:
+ m = provider.getPreRemoveMethod(beanClass, getEntityManager());
+ }
+
+ Restrict restrict = null;
+
+ if (m != null && m.isAnnotationPresent(Restrict.class))
+ {
+ restrict = m.getAnnotation(Restrict.class);
+ }
+ else if (entity.getClass().isAnnotationPresent(Restrict.class))
+ {
+ restrict = entity.getClass().getAnnotation(Restrict.class);
+ }
+
+ if (restrict != null)
+ {
+ if (Strings.isEmpty(restrict.value()))
+ {
+ identity.checkPermission(name, action.toString(), entity);
+ }
+ else
+ {
+ identity.checkRestriction(restrict.value());
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: branches/Seam_2_0/src/main/org/jboss/seam/security/EntitySecurityListener.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/security/EntitySecurityListener.java 2008-03-24 21:03:57 UTC (rev 7681)
+++ branches/Seam_2_0/src/main/org/jboss/seam/security/EntitySecurityListener.java 2008-03-25 00:57:14 UTC (rev 7682)
@@ -21,36 +21,24 @@
@PostLoad
public void postLoad(Object entity)
{
- if (Identity.isSecurityEnabled())
- {
- Identity.instance().checkEntityPermission(entity, READ);
- }
+ EntityPermissionChecker.instance().checkEntityPermission(entity, READ);
}
@PrePersist
public void prePersist(Object entity)
{
- if (Identity.isSecurityEnabled())
- {
- Identity.instance().checkEntityPermission(entity, INSERT);
- }
+ EntityPermissionChecker.instance().checkEntityPermission(entity, INSERT);
}
@PreUpdate
public void preUpdate(Object entity)
{
- if (Identity.isSecurityEnabled())
- {
- Identity.instance().checkEntityPermission(entity, UPDATE);
- }
+ EntityPermissionChecker.instance().checkEntityPermission(entity, UPDATE);
}
@PreRemove
public void preRemove(Object entity)
{
- if (Identity.isSecurityEnabled())
- {
- Identity.instance().checkEntityPermission(entity, DELETE);
- }
+ EntityPermissionChecker.instance().checkEntityPermission(entity, DELETE);
}
}
Modified: branches/Seam_2_0/src/main/org/jboss/seam/security/HibernateSecurityInterceptor.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/security/HibernateSecurityInterceptor.java 2008-03-24 21:03:57 UTC (rev 7681)
+++ branches/Seam_2_0/src/main/org/jboss/seam/security/HibernateSecurityInterceptor.java 2008-03-25 00:57:14 UTC (rev 7682)
@@ -30,10 +30,8 @@
public boolean onLoad(Object entity, Serializable id, Object[] state,
String[] propertyNames, Type[] types)
{
- if (Identity.isSecurityEnabled())
- {
- Identity.instance().checkEntityPermission(entity, READ);
- }
+ EntityPermissionChecker.instance().checkEntityPermission(entity, READ);
+
return wrappedInterceptor != null ?
wrappedInterceptor.onLoad(entity, id, state, propertyNames, types) :
false;
@@ -43,10 +41,8 @@
public void onDelete(Object entity, Serializable id, Object[] state,
String[] propertyNames, Type[] types)
{
- if (Identity.isSecurityEnabled())
- {
- Identity.instance().checkEntityPermission(entity, DELETE);
- }
+ EntityPermissionChecker.instance().checkEntityPermission(entity, DELETE);
+
if (wrappedInterceptor != null)
wrappedInterceptor.onDelete(entity, id, state, propertyNames, types);
}
@@ -55,10 +51,8 @@
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState,
Object[] previousState, String[] propertyNames, Type[] types)
{
- if (Identity.isSecurityEnabled())
- {
- Identity.instance().checkEntityPermission(entity, UPDATE);
- }
+ EntityPermissionChecker.instance().checkEntityPermission(entity, UPDATE);
+
return wrappedInterceptor != null ?
wrappedInterceptor.onFlushDirty(entity, id, currentState,
previousState, propertyNames, types) : false;
@@ -68,10 +62,8 @@
public boolean onSave(Object entity, Serializable id, Object[] state,
String[] propertyNames, Type[] types)
{
- if (Identity.isSecurityEnabled())
- {
- Identity.instance().checkEntityPermission(entity, INSERT);
- }
+ EntityPermissionChecker.instance().checkEntityPermission(entity, INSERT);
+
return wrappedInterceptor != null ?
wrappedInterceptor.onSave(entity, id, state, propertyNames, types) :
false;
Modified: branches/Seam_2_0/src/main/org/jboss/seam/security/Identity.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/security/Identity.java 2008-03-24 21:03:57 UTC (rev 7681)
+++ branches/Seam_2_0/src/main/org/jboss/seam/security/Identity.java 2008-03-25 00:57:14 UTC (rev 7682)
@@ -626,58 +626,5 @@
principal = savedPrincipal;
subject = savedSubject;
}
- }
-
- public void checkEntityPermission(Object entity, EntityAction action)
- {
- isLoggedIn(true);
-
- PersistenceProvider provider = PersistenceProvider.instance();
- Class beanClass = provider.getBeanClass(entity);
-
- if (beanClass != null)
- {
- String name = Seam.getComponentName(entity.getClass());
- if (name == null) name = beanClass.getName();
-
- Method m = null;
- switch (action)
- {
- case READ:
- m = provider.getPostLoadMethod(beanClass);
- break;
- case INSERT:
- m = provider.getPrePersistMethod(beanClass);
- break;
- case UPDATE:
- m = provider.getPreUpdateMethod(beanClass);
- break;
- case DELETE:
- m = provider.getPreRemoveMethod(beanClass);
- }
-
- Restrict restrict = null;
-
- if (m != null && m.isAnnotationPresent(Restrict.class))
- {
- restrict = m.getAnnotation(Restrict.class);
- }
- else if (entity.getClass().isAnnotationPresent(Restrict.class))
- {
- restrict = entity.getClass().getAnnotation(Restrict.class);
- }
-
- if (restrict != null)
- {
- if (Strings.isEmpty(restrict.value()))
- {
- checkPermission(name, action.toString(), entity);
- }
- else
- {
- checkRestriction(restrict.value());
- }
- }
- }
- }
+ }
}
16 years, 11 months
Seam SVN: r7681 - trunk/seam-gen/icefaces/build-scripts and 1 other directory.
by seam-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-03-24 17:03:57 -0400 (Mon, 24 Mar 2008)
New Revision: 7681
Modified:
branches/Seam_2_0/seam-gen/icefaces/build-scripts/build-war.xml
branches/Seam_2_0/seam-gen/icefaces/build-scripts/build.xml
trunk/seam-gen/icefaces/build-scripts/build-war.xml
trunk/seam-gen/icefaces/build-scripts/build.xml
Log:
JBSEAM-2573, thanks to Joshua Partogi!
Modified: branches/Seam_2_0/seam-gen/icefaces/build-scripts/build-war.xml
===================================================================
--- branches/Seam_2_0/seam-gen/icefaces/build-scripts/build-war.xml 2008-03-24 17:35:22 UTC (rev 7680)
+++ branches/Seam_2_0/seam-gen/icefaces/build-scripts/build-war.xml 2008-03-24 21:03:57 UTC (rev 7681)
@@ -337,12 +337,18 @@
<target name="test" depends="buildtest" description="Run the tests">
<taskdef resource="testngtasks" classpath="${testng.jar}" />
- <testng outputdir="${basedir}/test-report">
- <classpath path="${test.dir}" />
- <classpath path="${bootstrap.dir}" />
- <classpath refid="build.classpath" />
- <xmlfileset dir="${test.dir}" includes="*Test.xml" />
- </testng>
+ <path id="test.path">
+ <path path="${test.dir}" />
+ <fileset dir="${lib.dir}/test">
+ <include name="*.jar" />
+ </fileset>
+ <path path="${bootstrap.dir}" />
+ <path refid="build.classpath" />
+ </path>
+ <testng outputdir="${basedir}/test-report">
+ <classpath refid="test.path" />
+ <xmlfileset dir="${test.dir}" includes="*Test.xml" />
+ </testng>
</target>
<target name="freshen" description="grab fresh icefaces jars">
Modified: branches/Seam_2_0/seam-gen/icefaces/build-scripts/build.xml
===================================================================
--- branches/Seam_2_0/seam-gen/icefaces/build-scripts/build.xml 2008-03-24 17:35:22 UTC (rev 7680)
+++ branches/Seam_2_0/seam-gen/icefaces/build-scripts/build.xml 2008-03-24 21:03:57 UTC (rev 7681)
@@ -302,12 +302,18 @@
<target name="test" depends="buildtest" description="Run the tests">
<taskdef resource="testngtasks" classpath="${testng.jar}" />
- <testng outputdir="${basedir}/test-report">
- <classpath path="${test.dir}" />
- <classpath path="${bootstrap.dir}" />
- <classpath refid="build.classpath" />
- <xmlfileset dir="${test.dir}" includes="*Test.xml" />
- </testng>
+ <path id="test.path">
+ <path path="${test.dir}" />
+ <fileset dir="${lib.dir}/test">
+ <include name="*.jar" />
+ </fileset>
+ <path path="${bootstrap.dir}" />
+ <path refid="build.classpath" />
+ </path>
+ <testng outputdir="${basedir}/test-report">
+ <classpath refid="test.path" />
+ <xmlfileset dir="${test.dir}" includes="*Test.xml" />
+ </testng>
</target>
<target name="validateConfiguration" depends="war,ear,jar" description="Validate the xml configuration files">
Modified: trunk/seam-gen/icefaces/build-scripts/build-war.xml
===================================================================
--- trunk/seam-gen/icefaces/build-scripts/build-war.xml 2008-03-24 17:35:22 UTC (rev 7680)
+++ trunk/seam-gen/icefaces/build-scripts/build-war.xml 2008-03-24 21:03:57 UTC (rev 7681)
@@ -337,12 +337,18 @@
<target name="test" depends="buildtest" description="Run the tests">
<taskdef resource="testngtasks" classpath="${testng.jar}" />
- <testng outputdir="${basedir}/test-report">
- <classpath path="${test.dir}" />
- <classpath path="${bootstrap.dir}" />
- <classpath refid="build.classpath" />
- <xmlfileset dir="${test.dir}" includes="*Test.xml" />
- </testng>
+ <path id="test.path">
+ <path path="${test.dir}" />
+ <fileset dir="${lib.dir}/test">
+ <include name="*.jar" />
+ </fileset>
+ <path path="${bootstrap.dir}" />
+ <path refid="build.classpath" />
+ </path>
+ <testng outputdir="${basedir}/test-report">
+ <classpath refid="test.path" />
+ <xmlfileset dir="${test.dir}" includes="*Test.xml" />
+ </testng>
</target>
<target name="freshen" description="grab fresh icefaces jars">
Modified: trunk/seam-gen/icefaces/build-scripts/build.xml
===================================================================
--- trunk/seam-gen/icefaces/build-scripts/build.xml 2008-03-24 17:35:22 UTC (rev 7680)
+++ trunk/seam-gen/icefaces/build-scripts/build.xml 2008-03-24 21:03:57 UTC (rev 7681)
@@ -302,12 +302,18 @@
<target name="test" depends="buildtest" description="Run the tests">
<taskdef resource="testngtasks" classpath="${testng.jar}" />
- <testng outputdir="${basedir}/test-report">
- <classpath path="${test.dir}" />
- <classpath path="${bootstrap.dir}" />
- <classpath refid="build.classpath" />
- <xmlfileset dir="${test.dir}" includes="*Test.xml" />
- </testng>
+ <path id="test.path">
+ <path path="${test.dir}" />
+ <fileset dir="${lib.dir}/test">
+ <include name="*.jar" />
+ </fileset>
+ <path path="${bootstrap.dir}" />
+ <path refid="build.classpath" />
+ </path>
+ <testng outputdir="${basedir}/test-report">
+ <classpath refid="test.path" />
+ <xmlfileset dir="${test.dir}" includes="*Test.xml" />
+ </testng>
</target>
<target name="validateConfiguration" depends="war,ear,jar" description="Validate the xml configuration files">
16 years, 11 months