struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hus...@apache.org
Subject svn commit: r389644 - in /struts/sandbox/trunk/action2: ./ apps/mailreader/src/java/ apps/mailreader/src/java/mailreader2/ apps/mailreader/src/webapp/pages/
Date Wed, 29 Mar 2006 00:55:26 GMT
Author: husted
Date: Tue Mar 28 16:55:24 2006
New Revision: 389644

URL: http://svn.apache.org/viewcvs?rev=389644&view=rev
Log:
Action2 Apps
* Mailreader 
** Add double-submit guard
** Add custom AuthenticationInterceptor



Added:
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/AuthenticationInterceptor.java
  (with props)
Modified:
    struts/sandbox/trunk/action2/PRACTICES.txt
    struts/sandbox/trunk/action2/README.txt
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java
    struts/sandbox/trunk/action2/apps/mailreader/src/java/resources.properties
    struts/sandbox/trunk/action2/apps/mailreader/src/java/resources_ja.properties
    struts/sandbox/trunk/action2/apps/mailreader/src/java/resources_ru.properties
    struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml
    struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Error.jsp
    struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Registration.jsp
    struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Subscription.jsp

Modified: struts/sandbox/trunk/action2/PRACTICES.txt
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/PRACTICES.txt?rev=389644&r1=389643&r2=389644&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/PRACTICES.txt (original)
+++ struts/sandbox/trunk/action2/PRACTICES.txt Tue Mar 28 16:55:24 2006
@@ -37,3 +37,6 @@
 * Do not embed business logic in action classes.
  ** Remove business logic to a business facade that the actions can call. (Spring is an excellent
way to build a business facade.)
  ** Actions are a necessary evil. Every line of code in an Action is guilty until proven
innocent. Ideally, there should be one line of code that calls the business facade, and every
other line of a code in an action should be bound to the framework.
+
+* Centralize other application and business logic into a base class that action can share.

+

Modified: struts/sandbox/trunk/action2/README.txt
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/README.txt?rev=389644&r1=389643&r2=389644&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/README.txt (original)
+++ struts/sandbox/trunk/action2/README.txt Tue Mar 28 16:55:24 2006
@@ -136,7 +136,7 @@
 + Cancel 
 + Submit 
 + Submit (bad data)
-  Double submit
++ Double submit
 
 ----
 
@@ -157,7 +157,7 @@
 + Submit (invalid data)
 + Submit (data)
 + Submit (duplicate data)
-  Double submit
++ Double submit
 
 ----
 

Added: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/AuthenticationInterceptor.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/AuthenticationInterceptor.java?rev=389644&view=auto
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/AuthenticationInterceptor.java
(added)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/AuthenticationInterceptor.java
Tue Mar 28 16:55:24 2006
@@ -0,0 +1,31 @@
+package mailreader2;
+
+import com.opensymphony.xwork.interceptor.Interceptor;
+import com.opensymphony.xwork.ActionInvocation;
+import com.opensymphony.xwork.Action;
+import java.util.Map;
+import org.apache.struts.apps.mailreader.dao.User;
+
+public class AuthenticationInterceptor implements Interceptor  {
+
+    public void destroy () {}
+
+    public void init() {}
+
+    public String intercept(ActionInvocation actionInvocation) throws Exception {
+
+        Map session = actionInvocation.getInvocationContext().getSession();
+
+        User user = (User) session.get(Constants.USER_KEY);
+
+        boolean isAuthenticated = (null!=user) && (null!=user.getDatabase());
+
+        if (!isAuthenticated) {
+            return Action.LOGIN;            
+        }
+        else {
+            return actionInvocation.invoke();
+        }
+
+    }
+}

Propchange: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/AuthenticationInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java?rev=389644&r1=389643&r2=389644&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java
(original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java
Tue Mar 28 16:55:24 2006
@@ -363,9 +363,8 @@
         User user;
 
         try {
-
-            user = findUser(username, password);
-        }
+            user = database.findUser(username);
+         }
 
         catch (ExpiredPasswordException e) {
             user = getUser(); // Just so that it is not null

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/java/resources.properties
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/resources.properties?rev=389644&r1=389643&r2=389644&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/resources.properties (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/resources.properties Tue Mar 28
16:55:24 2006
@@ -21,7 +21,7 @@
 error.password.match=Password and confirmation password must match
 error.password.mismatch=Invalid username and/or password, please try again
 error.replyToAddress.format=Invalid format for Reply To Address
-error.transaction.token=Cannot submit this form out of order
+webwork.messages.invalid.token=Cannot submit this form out of order
 error.type.invalid=Server Type must be 'imap' or 'pop3'
 error.type.required=Server Type is required
 error.username.required=Username is required

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/java/resources_ja.properties
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/resources_ja.properties?rev=389644&r1=389643&r2=389644&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/resources_ja.properties (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/resources_ja.properties Tue Mar
28 16:55:24 2006
@@ -18,7 +18,7 @@
 error.password.match=\u30D1\u30B9\u30EF\u30FC\u30C9\u3068\u78BA\u8A8D\u7528\u30D1\u30B9\u30EF\u30FC\u30C9\u304C\u4E00\u81F4\u3057\u3066\u3044\u307E\u305B\u3093
 error.password.mismatch=\u30E6\u30FC\u30B6\u540D\u307E\u305F\u306F\u30D1\u30B9\u30EF\u30FC\u30C9\u304C\u4E0D\u6B63\u3067\u3059\u3002\u518D\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044
 error.replyToAddress.format=\u8FD4\u4FE1\u30A2\u30C9\u30EC\u30B9\u306E\u66F8\u5F0F\u304C\u6B63\u3057\u304F\u3042\u308A\u307E\u305B\u3093
-error.transaction.token=\u3053\u306E\u30D5\u30A9\u30FC\u30E0\u306E\u5185\u5BB9\u304C\u6B63\u3057\u304F\u306A\u3044\u305F\u3081\u9001\u4FE1\u3059\u308B\u3053\u3068\u304C\u51FA\u6765\u307E\u305B\u3093
+webwork.messages.invalid.token=\u3053\u306E\u30D5\u30A9\u30FC\u30E0\u306E\u5185\u5BB9\u304C\u6B63\u3057\u304F\u306A\u3044\u305F\u3081\u9001\u4FE1\u3059\u308B\u3053\u3068\u304C\u51FA\u6765\u307E\u305B\u3093
 error.type.invalid=\u30B5\u30FC\u30D0\u30BF\u30A4\u30D7\u306F 'imap' \u304B 'pop3'\u306E\u3069\u3061\u3089\u304B\u3067\u306A\u3051\u308C\u3070\u306A\u308A\u307E\u305B\u3093
 error.type.required=\u30B5\u30FC\u30D0\u30BF\u30A4\u30D7\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044
 error.username.required=\u30E6\u30FC\u30B6\u540D\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/java/resources_ru.properties
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/resources_ru.properties?rev=389644&r1=389643&r2=389644&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/resources_ru.properties (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/resources_ru.properties Tue Mar
28 16:55:24 2006
@@ -18,7 +18,7 @@
 error.password.match=\u041f\u0430\u0440\u043e\u043b\u044c \u0438 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435
\u043f\u0430\u0440\u043e\u043b\u044f \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442.
 error.password.mismatch=\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435
\u0438\u043c\u044f \u0438/\u0438\u043b\u0438 \u043f\u0430\u0440\u043e\u043b\u044c - \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435,
\u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0441\u043d\u043e\u0432\u0430.
 error.replyToAddress.format=\u0412 \u043f\u043e\u043b\u0435 '\u0410\u0434\u0440\u0435\u0441
\u041e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430:' \u0443\u043a\u0430\u0437\u0430\u043d
\u0430\u0434\u0440\u0435\u0441 \u0432 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c
\u0444\u043e\u0440\u043c\u0430\u0442\u0435.
-error.transaction.token=\u042d\u0442\u0430 \u0444\u043e\u0440\u043c\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442
\u0431\u044b\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430 - \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0435
\u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0437\u0430\u043d\u0435\u0441\u0435\u043d\u0438\u044f
\u0434\u0430\u043d\u043d\u044b\u0445.
+webwork.messages.invalid.token=\u042d\u0442\u0430 \u0444\u043e\u0440\u043c\u0430 \u043d\u0435
\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430
- \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430
\u0437\u0430\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.
 error.type.invalid=\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0438\u043f\u0430
\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c
\u0443\u043a\u0430\u0437\u0430\u043d\u044b \u043b\u0438\u0448\u044c 'imap' \u0438\u043b\u0438
'pop3'
 error.type.required=\u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u044c
\u0442\u0438\u043f \u0441\u0435\u0440\u0432\u0435\u0440\u0430
 error.username.required=\u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u044c
\u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml?rev=389644&r1=389643&r2=389644&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml Tue Mar 28 16:55:24 2006
@@ -5,10 +5,30 @@
 
     <package name="default" namespace="/" extends="webwork-default">
 
+        <interceptors>
+
+            <interceptor name="authenticate" class="mailreader2.AuthenticationInterceptor"/>
+
+            <interceptor-stack name="access" >
+                <interceptor-ref name="authenticate" />
+                <interceptor-ref name="defaultStack"/>
+            </interceptor-stack>
+
+            <interceptor-stack name="submit">
+                <interceptor-ref name="token-session" />
+                <interceptor-ref name="authenticate-access" />
+            </interceptor-stack>
+
+        </interceptors>
+
+        <default-interceptor-ref name="access"/>
+        
         <!-- default-action-ref name="Welcome"/ -->
 
         <global-results>
             <result name="error">/pages/Error.jsp</result>
+            <result name="invalid.token">/pages/Error.jsp</result>
+            <result name="login" type="redirect-action">Logon!input</result>
         </global-results>
 
         <global-exception-mappings>
@@ -26,15 +46,16 @@
          the framework logs an exception.
         -->
         <action name="Welcome" class="mailreader2.MailreaderSupport">
+            <interceptor-ref name="defaultStack"/>
             <result>/pages/Welcome.jsp</result>
         </action>
 
-        <action name="Logon"
-                class="mailreader2.Logon">
+        <action name="Logon" class="mailreader2.Logon">
+            <interceptor-ref name="defaultStack"/>
             <exception-mapping
                     exception="org.apache.struts.apps.mailreader.dao.ExpiredPasswordException"
                     result="expired"/>
-            <result>/pages/MainMenu.jsp</result>
+            <result type="redirect-action">MainMenu</result>
             <result name="input">/pages/Logon.jsp</result>
             <result name="expired" type="chain">ChangePassword</result>
         </action>
@@ -55,6 +76,7 @@
         </action>
 
         <action name="RegistrationSave" class="mailreader2.RegistrationSave">
+            <interceptor-ref name="submit" />
             <result name="input">/pages/Registration.jsp</result>
             <result type="redirect-action">MainMenu</result>
         </action>
@@ -65,6 +87,7 @@
         </action>
 
         <action name="SubscriptionSave" class="mailreader2.SubscriptionSave">
+            <interceptor-ref name="submit" />
             <result name="input">/pages/Subscription.jsp</result>
             <result type="redirect-action">Registration!input</result>
         </action>

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Error.jsp
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Error.jsp?rev=389644&r1=389643&r2=389644&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Error.jsp (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Error.jsp Tue Mar 28 16:55:24
2006
@@ -20,6 +20,8 @@
 
 <h3>Error Message</h3>
 
+<saf:actionerror />
+
 <p>
     <saf:property value="%{exception.message}"/>
 </p>

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Registration.jsp
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Registration.jsp?rev=389644&r1=389643&r2=389644&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Registration.jsp (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Registration.jsp Tue Mar
28 16:55:24 2006
@@ -18,6 +18,7 @@
 
 <saf:actionerror/>
 <saf:form method="POST" validate="false">
+    <saf:token />
     <saf:hidden name="task"/>
     <saf:if test="task == 'Create'">
         <saf:textfield label="%{getText('username')}" name="username"/>

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Subscription.jsp
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Subscription.jsp?rev=389644&r1=389643&r2=389644&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Subscription.jsp (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Subscription.jsp Tue Mar
28 16:55:24 2006
@@ -21,6 +21,7 @@
 
 <saf:actionerror/>
 <saf:form method="POST" action="SubscriptionSave" validate="false">
+    <saf:token />
     <saf:hidden name="task"/>
     <saf:label label="%{getText('username')}" name="user.username"/>
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message