[seam-commits] Seam SVN: r9659 - in trunk/examples/jee5: booking/resources/WEB-INF and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Nov 26 02:57:13 EST 2008


Author: dan.j.allen
Date: 2008-11-26 02:57:13 -0500 (Wed, 26 Nov 2008)
New Revision: 9659

Modified:
   trunk/examples/jee5/booking/resources/META-INF/application.xml
   trunk/examples/jee5/booking/resources/META-INF/ejb-jar.xml
   trunk/examples/jee5/booking/resources/WEB-INF/web.xml
   trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/Authenticator.java
   trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/AuthenticatorAction.java
   trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/BookingListAction.java
   trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/ChangePasswordAction.java
   trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/HotelBookingAction.java
   trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java
   trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/RegisterAction.java
   trunk/examples/jee5/remoting/resources/META-INF/application.xml
   trunk/examples/jee5/remoting/resources/WEB-INF/web.xml
Log:
JBSEAM-3034


Modified: trunk/examples/jee5/booking/resources/META-INF/application.xml
===================================================================
--- trunk/examples/jee5/booking/resources/META-INF/application.xml	2008-11-26 07:56:46 UTC (rev 9658)
+++ trunk/examples/jee5/booking/resources/META-INF/application.xml	2008-11-26 07:57:13 UTC (rev 9659)
@@ -8,12 +8,12 @@
     
     <module>
         <web>
-            <web-uri>jboss-seam-jee5.war</web-uri>
-            <context-root>/seam-jee5</context-root>
+            <web-uri>jboss-seam-jee5-booking.war</web-uri>
+            <context-root>/seam-jee5-booking</context-root>
         </web>
     </module>
     <module>
-        <ejb>jboss-seam-jee5.jar</ejb>
+        <ejb>jboss-seam-jee5-booking.jar</ejb>
     </module>
     <module>
         <ejb>jboss-seam.jar</ejb>

Modified: trunk/examples/jee5/booking/resources/META-INF/ejb-jar.xml
===================================================================
--- trunk/examples/jee5/booking/resources/META-INF/ejb-jar.xml	2008-11-26 07:56:46 UTC (rev 9658)
+++ trunk/examples/jee5/booking/resources/META-INF/ejb-jar.xml	2008-11-26 07:57:13 UTC (rev 9659)
@@ -1,16 +1,28 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" 
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
          version="3.0">
-   
-   
+
+   <enterprise-beans>
+      <!-- EJB reference required when one Seam EJB component references another Seam EJB component using @In -->
+      <!-- Not required if you inject using @EJB, but then you lose state management and client-side interceptors (e.g., security) -->
+      <session>
+         <ejb-name>RegisterAction</ejb-name>
+         <ejb-local-ref>
+            <ejb-ref-name>jboss-seam-jee5/AuthenticatorAction/local</ejb-ref-name>
+            <ejb-ref-type>Session</ejb-ref-type>
+            <local>org.jboss.seam.example.booking.Authenticator</local>
+         </ejb-local-ref>
+      </session>
+   </enterprise-beans>
+
    <interceptors>
      <interceptor>
        <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
      </interceptor>
    </interceptors>
-   
+
    <assembly-descriptor>
       <interceptor-binding>
          <ejb-name>*</ejb-name>

Modified: trunk/examples/jee5/booking/resources/WEB-INF/web.xml
===================================================================
--- trunk/examples/jee5/booking/resources/WEB-INF/web.xml	2008-11-26 07:56:46 UTC (rev 9658)
+++ trunk/examples/jee5/booking/resources/WEB-INF/web.xml	2008-11-26 07:57:13 UTC (rev 9659)
@@ -1,15 +1,15 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<web-app version="2.5"    
-    xmlns="http://java.sun.com/xml/ns/javaee"    
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
-    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">           
-  
+<web-app version="2.5"
+    xmlns="http://java.sun.com/xml/ns/javaee"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
   <!-- Seam -->
-  
-  <listener>        
-    <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>    
-  </listener>    
 
+  <listener>
+    <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
+  </listener>
+
   <filter>
     <filter-name>Seam Filter</filter-name>
     <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
@@ -19,96 +19,88 @@
     <filter-name>Seam Filter</filter-name>
     <url-pattern>/*</url-pattern>
   </filter-mapping>
-  
+
   <servlet>
     <servlet-name>Seam Resource Servlet</servlet-name>
     <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
   </servlet>
-  
+
   <servlet-mapping>
     <servlet-name>Seam Resource Servlet</servlet-name>
     <url-pattern>/seam/resource/*</url-pattern>
-  </servlet-mapping>   
-  
+  </servlet-mapping>
+
   <!-- JSF and Facelets -->
-  
-  <context-param>        
-    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>        
-    <param-value>.xhtml</param-value>    
+
+  <context-param>
+    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
+    <param-value>.xhtml</param-value>
   </context-param>
-    
-  <context-param>        
-    <param-name>facelets.DEVELOPMENT</param-name>        
-    <param-value>true</param-value>    
-  </context-param>    
-  
+
+  <context-param>
+    <param-name>facelets.DEVELOPMENT</param-name>
+    <param-value>true</param-value>
+  </context-param>
+
   <!-- Faces Servlet -->
-  
-  <servlet>        
-    <servlet-name>Faces Servlet</servlet-name>        
-    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>        
-    <load-on-startup>1</load-on-startup>    
+
+  <servlet>
+    <servlet-name>Faces Servlet</servlet-name>
+    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+    <load-on-startup>1</load-on-startup>
   </servlet>
-  
-  <servlet-mapping>        
-    <servlet-name>Faces Servlet</servlet-name>        
-    <url-pattern>*.seam</url-pattern>    
+
+  <servlet-mapping>
+    <servlet-name>Faces Servlet</servlet-name>
+    <url-pattern>*.seam</url-pattern>
   </servlet-mapping>
-  
+
   <!-- JEE5 EJB3 names -->
-  
-  <ejb-local-ref>              
-    <ejb-ref-name>jboss-seam-jee5/AuthenticatorAction/local</ejb-ref-name>           
+
+  <ejb-local-ref>
+    <ejb-ref-name>jboss-seam-jee5/AuthenticatorAction/local</ejb-ref-name>
     <ejb-ref-type>Session</ejb-ref-type>
-    <local>org.jboss.seam.example.booking.Authenticator</local>               
-    <ejb-link>AuthenticatorAction</ejb-link>        
-  </ejb-local-ref>	  
-  
-  <ejb-local-ref>       
-    <ejb-ref-name>jboss-seam-jee5/BookingListAction/local</ejb-ref-name>       
-    <ejb-ref-type>Session</ejb-ref-type>       
-    <local>org.jboss.seam.example.booking.BookingList</local>       
-    <ejb-link>BookingListAction</ejb-link>    
-  </ejb-local-ref>    
-  
-  <ejb-local-ref>       
-    <ejb-ref-name>jboss-seam-jee5/RegisterAction/local</ejb-ref-name>       
-    <ejb-ref-type>Session</ejb-ref-type>       
-    <local>org.jboss.seam.example.booking.Register</local>       
-    <ejb-link>RegisterAction</ejb-link>    
-  </ejb-local-ref>    
-  
-  <ejb-local-ref>       
-    <ejb-ref-name>jboss-seam-jee5/ChangePasswordAction/local</ejb-ref-name>       
-    <ejb-ref-type>Session</ejb-ref-type>       
-    <local>org.jboss.seam.example.booking.ChangePassword</local>       
-    <ejb-link>ChangePasswordAction</ejb-link>    
-  </ejb-local-ref>    
-  
-  <ejb-local-ref>       
-    <ejb-ref-name>jboss-seam-jee5/HotelBookingAction/local</ejb-ref-name>       
-    <ejb-ref-type>Session</ejb-ref-type>       
-    <local>org.jboss.seam.example.booking.HotelBooking</local>       
-    <ejb-link>HotelBookingAction</ejb-link>    
-  </ejb-local-ref>    
-  
-  <ejb-local-ref>       
-    <ejb-ref-name>jboss-seam-jee5/HotelSearchingAction/local</ejb-ref-name>       
-    <ejb-ref-type>Session</ejb-ref-type>       
-    <local>org.jboss.seam.example.booking.HotelSearching</local>       
-    <ejb-link>HotelSearchingAction</ejb-link>    
-  </ejb-local-ref>    
-    
+    <local>org.jboss.seam.example.booking.Authenticator</local>
+  </ejb-local-ref>	
+
   <ejb-local-ref>
-    <ejb-ref-name>jboss-seam-jee5/EjbSynchronizations/local</ejb-ref-name>  
+    <ejb-ref-name>jboss-seam-jee5/BookingListAction/local</ejb-ref-name>
     <ejb-ref-type>Session</ejb-ref-type>
+    <local>org.jboss.seam.example.booking.BookingList</local>
+  </ejb-local-ref>
+
+  <ejb-local-ref>
+    <ejb-ref-name>jboss-seam-jee5/RegisterAction/local</ejb-ref-name>
+    <ejb-ref-type>Session</ejb-ref-type>
+    <local>org.jboss.seam.example.booking.Register</local>
+  </ejb-local-ref>
+
+  <ejb-local-ref>
+    <ejb-ref-name>jboss-seam-jee5/ChangePasswordAction/local</ejb-ref-name>
+    <ejb-ref-type>Session</ejb-ref-type>
+    <local>org.jboss.seam.example.booking.ChangePassword</local>
+  </ejb-local-ref>
+
+  <ejb-local-ref>
+    <ejb-ref-name>jboss-seam-jee5/HotelBookingAction/local</ejb-ref-name>
+    <ejb-ref-type>Session</ejb-ref-type>
+    <local>org.jboss.seam.example.booking.HotelBooking</local>
+  </ejb-local-ref>
+
+  <ejb-local-ref>
+    <ejb-ref-name>jboss-seam-jee5/HotelSearchingAction/local</ejb-ref-name>
+    <ejb-ref-type>Session</ejb-ref-type>
+    <local>org.jboss.seam.example.booking.HotelSearching</local>
+  </ejb-local-ref>
+
+  <ejb-local-ref>
+    <ejb-ref-name>jboss-seam-jee5/EjbSynchronizations/local</ejb-ref-name>
+    <ejb-ref-type>Session</ejb-ref-type>
     <local>org.jboss.seam.transaction.LocalEjbSynchronizations</local>
-    <ejb-link>EjbSynchronizations</ejb-link>
   </ejb-local-ref>
 
-  
   <session-config>
-    <session-timeout>10</session-timeout> 
-  </session-config>   
-  
+    <session-timeout>10</session-timeout>
+  </session-config>
+
 </web-app>

Modified: trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/Authenticator.java
===================================================================
--- trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/Authenticator.java	2008-11-26 07:56:46 UTC (rev 9658)
+++ trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/Authenticator.java	2008-11-26 07:57:13 UTC (rev 9659)
@@ -6,4 +6,5 @@
 public interface Authenticator
 {
    public boolean authenticate();
+   public boolean isUsernameAvailable();
 }

Modified: trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/AuthenticatorAction.java
===================================================================
--- trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/AuthenticatorAction.java	2008-11-26 07:56:46 UTC (rev 9658)
+++ trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/AuthenticatorAction.java	2008-11-26 07:57:13 UTC (rev 9659)
@@ -9,21 +9,30 @@
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Logger;
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.log.Log;
 
 @Stateless
 @Name("authenticator")
 public class AuthenticatorAction implements Authenticator, Serializable
 {
+   @Logger private Log log;
+   
    @PersistenceContext EntityManager em;
    
-   @Out(required=false, scope = SESSION)
+   @In(required = false)
+   @Out(required = false, scope = SESSION)
    private User user;
    
    public boolean authenticate()
    {
-      List results = em.createQuery("select u from User u where u.username=#{identity.username} and u.password=#{identity.password}")
+      log.info("Authenticating #{identity.username}");
+      List results = em.createQuery(
+            "select u from User u where u.username = #{identity.username} and u.password = #{identity.password}")
             .getResultList();
       
       if ( results.size()==0 )
@@ -36,5 +45,30 @@
          return true;
       }
    }
+   
+   public boolean isUsernameAvailable()
+   {
+      // check if user is available in context
+      // we are proving that bijection is working on inter-EJB calls
+      if (user == null)
+	  {
+          throw new IllegalStateException("No user available in context.");
+	  }
 
+      log.info("Checking if username is available: {0}", user.getUsername());
+      List results = em.createQuery(
+            "select u.username from User u where u.username = :username")
+            .setParameter("username", user.getUsername())
+            .getResultList();
+      
+      if ( results.size() == 0 )
+      {
+         return true;
+      }
+      else
+      {
+         return false;
+      }
+   }
+
 }

Modified: trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/BookingListAction.java
===================================================================
--- trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/BookingListAction.java	2008-11-26 07:56:46 UTC (rev 9658)
+++ trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/BookingListAction.java	2008-11-26 07:57:13 UTC (rev 9659)
@@ -22,13 +22,14 @@
 import org.jboss.seam.annotations.Scope;
 import org.jboss.seam.annotations.datamodel.DataModel;
 import org.jboss.seam.annotations.datamodel.DataModelSelection;
+import org.jboss.seam.annotations.security.Restrict;
 import org.jboss.seam.faces.FacesMessages;
 import org.jboss.seam.log.Log;
 
 @Stateful
 @Scope(SESSION)
 @Name("bookingList")
-// @LoggedIn
+ at Restrict("#{identity.loggedIn}")
 @TransactionAttribute(REQUIRES_NEW)
 public class BookingListAction implements BookingList, Serializable
 {

Modified: trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/ChangePasswordAction.java
===================================================================
--- trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/ChangePasswordAction.java	2008-11-26 07:56:46 UTC (rev 9658)
+++ trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/ChangePasswordAction.java	2008-11-26 07:57:13 UTC (rev 9659)
@@ -15,12 +15,13 @@
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Out;
 import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.security.Restrict;
 import org.jboss.seam.faces.FacesMessages;
 
 @Stateful
 @Scope(EVENT)
 @Name("changePassword")
-// @LoggedIn
+ at Restrict("#{identity.loggedIn}")
 public class ChangePasswordAction implements ChangePassword, Serializable
 {
 

Modified: trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/HotelBookingAction.java
===================================================================
--- trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/HotelBookingAction.java	2008-11-26 07:56:46 UTC (rev 9658)
+++ trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/HotelBookingAction.java	2008-11-26 07:57:13 UTC (rev 9659)
@@ -20,13 +20,14 @@
 import org.jboss.seam.annotations.Logger;
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.security.Restrict;
 import org.jboss.seam.core.Events;
 import org.jboss.seam.faces.FacesMessages;
 import org.jboss.seam.log.Log;
 
 @Stateful
 @Name("hotelBooking")
-// @LoggedIn
+ at Restrict("#{identity.loggedIn}")
 public class HotelBookingAction implements HotelBooking, Serializable
 {
    
@@ -60,7 +61,7 @@
    @Begin
    public void selectHotel(Hotel selectedHotel)
    {
-      hotel = em.merge(selectedHotel);
+      hotel = em.find(Hotel.class, selectedHotel.getId());
    }
    
    public void bookHotel()

Modified: trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java
===================================================================
--- trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java	2008-11-26 07:56:46 UTC (rev 9658)
+++ trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java	2008-11-26 07:57:13 UTC (rev 9659)
@@ -20,7 +20,6 @@
 @Stateful
 @Name("hotelSearch")
 @Scope(ScopeType.SESSION)
-// @LoggedIn
 public class HotelSearchingAction implements HotelSearching, Serializable
 {
    
@@ -48,10 +47,6 @@
       
    private void queryHotels()
    {
-      // String searchPattern = searchString==null ? "%" : '%' + searchString.toLowerCase().replace('*', '%') + '%';
-      // hotels = em.createQuery("select h from Hotel h where lower(h.name) like :search or lower(h.city) like :search or lower(h.zip) like :search or lower(h.address) like :search")
-      //       .setParameter("search", searchPattern)
-
        hotels = em.createQuery("select h from Hotel h where lower(h.name) like #{pattern} or lower(h.city) like #{pattern} or lower(h.zip) like #{pattern} or lower(h.address) like #{pattern}")
             .setMaxResults(pageSize)
             .setFirstResult( page * pageSize )

Modified: trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/RegisterAction.java
===================================================================
--- trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/RegisterAction.java	2008-11-26 07:56:46 UTC (rev 9658)
+++ trunk/examples/jee5/booking/src/org/jboss/seam/example/booking/RegisterAction.java	2008-11-26 07:57:13 UTC (rev 9659)
@@ -25,10 +25,15 @@
 
    @In
    private User user;
-   
+
    @PersistenceContext
    private EntityManager em;
    
+   // if use @EJB, you don't need the ejb-local-ref defined in ejb-jar.xml,
+   // but you also lose state management and client-side interceptors
+   @In(create = true)
+   private Authenticator authenticator;
+   
    @In
    private FacesMessages facesMessages;
    
@@ -40,15 +45,10 @@
    {
       if ( user.getPassword().equals(verify) )
       {
-         // List existing = em.createQuery("select u.username from User u where u.username=:username")
-         //   .setParameter("username", user.getUsername())
-         List existing = em.createQuery("select u.username from User u where u.username=#{user.username}")
-            .getResultList();
-         if (existing.size()==0)
+         if ( authenticator.isUsernameAvailable() )
          {
             em.persist(user);
-            // facesMessages.add("Successfully registered as #{user.username}");
-            facesMessages.addToControl("username", "Username #{user.username} already exists");
+            facesMessages.add("Successfully registered as #{user.username}");
             registered = true;
          }
          else

Modified: trunk/examples/jee5/remoting/resources/META-INF/application.xml
===================================================================
--- trunk/examples/jee5/remoting/resources/META-INF/application.xml	2008-11-26 07:56:46 UTC (rev 9658)
+++ trunk/examples/jee5/remoting/resources/META-INF/application.xml	2008-11-26 07:57:13 UTC (rev 9659)
@@ -8,12 +8,12 @@
     
     <module>
         <web>
-            <web-uri>jboss-seam-remoting.war</web-uri>
-            <context-root>/seam-remoting</context-root>
+            <web-uri>jboss-seam-jee5-remoting.war</web-uri>
+            <context-root>/seam-jee5-remoting</context-root>
         </web>
     </module>
     <module>
-        <ejb>jboss-seam-remoting.jar</ejb>
+        <ejb>jboss-seam-jee5-remoting.jar</ejb>
     </module>
     <module>
         <ejb>jboss-seam.jar</ejb>

Modified: trunk/examples/jee5/remoting/resources/WEB-INF/web.xml
===================================================================
--- trunk/examples/jee5/remoting/resources/WEB-INF/web.xml	2008-11-26 07:56:46 UTC (rev 9658)
+++ trunk/examples/jee5/remoting/resources/WEB-INF/web.xml	2008-11-26 07:57:13 UTC (rev 9659)
@@ -55,27 +55,12 @@
     <url-pattern>*.seam</url-pattern>    
   </servlet-mapping>
   
-  <!-- MyFaces -->    
-  <!--    
-  <listener>        
-    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>    
-  </listener>    
-  -->        
-  
-  <!-- JSF RI -->
-  
-  <listener>        
-    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>    
-  </listener>        
-  
   <!-- JEE5 EJB3 names -->
   
   <ejb-local-ref>              
     <ejb-ref-name>jboss-seam-remoting/HelloAction/local</ejb-ref-name>
     <ejb-ref-type>Session</ejb-ref-type>
-    <local-home/>
     <local>org.jboss.seam.example.remoting.HelloLocal</local>               
-    <ejb-link>HelloAction</ejb-link>        
   </ejb-local-ref>	  
   
   <session-config>




More information about the seam-commits mailing list