You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Apache Wiki <wi...@apache.org> on 2007/06/30 07:32:52 UTC

[Tapestry Wiki] Update of "AcegiSpringJava5FormBased" by ErikVullings

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for change notification.

The following page has been changed by ErikVullings:
http://wiki.apache.org/tapestry/AcegiSpringJava5FormBased

------------------------------------------------------------------------------
   * AcegiSpringJava5 - First part of the tutorial
+  * AcegiSpringJava5Part2 - Second part
  
- A modern webapplication uses form based logon instead of HTTP Basic authentication. Here is an attempt to add a login form to my solution presented in the first part of the tutorial.
+ A modern web application uses form based logon instead of HTTP Basic authentication. Here is an attempt to add a login form to my solution presented in the first part of the tutorial.
  
  Add these lines to {{{src/main/resources/META-INF/hivemodule.xml}}}
  {{{
  <contribution configuration-id="hivemind.ApplicationDefaults">
-   <default symbol="tapestry.acegi.authenticationProcessingFilter"
-            value="de.zedlitz.tapestry.acegi.FormProcessingFilter"/>
    <default symbol="tapestry.acegi.authenticationEntryPoint"
             value="de.zedlitz.tapestry.acegi.FormAuthenticationEntryPoint"/>
    <!--            ^^^^ 
               you have to adjust this text according to your module id -->
  </contribution>
- 
- <service-point id="FormProcessingFilter" interface="javax.servlet.Filter">
-   <invoke-factory>
-     <construct class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter"
-          initialize-method="afterPropertiesSet">
-       <set property="authenticationFailureUrl" value="/LoginFailed.html"/>
-       <set property="defaultTargetUrl" value="/app"/>
-       <set property="filterProcessesUrl" value="/j_acegi_security_check"/>
-     </construct>
-   </invoke-factory>
- </service-point>
  
  <service-point id="FormAuthenticationEntryPoint"  
                 interface="org.acegisecurity.ui.AuthenticationEntryPoint">
@@ -38, +26 @@

  </service-point>
  }}}
  
- This tells Acegi to redirect all unauthenticated request {{{to /app?page=Login&amp;service=page}}}, our login page.
+ This tells Acegi to redirect all unauthenticated requests {{{to /app?page=Login&amp;service=page}}}, our login page.
  
  Create the login page {{{src/main/webapp/Login.html}}}:
  {{{
@@ -74, +62 @@

  
  import org.apache.tapestry.RedirectException;
  import org.apache.tapestry.annotations.InjectObject;
+ import org.apache.tapestry.engine.IEngineService;
  
  import javax.servlet.http.HttpServletRequest;
  
  
  public abstract class Login extends org.apache.tapestry.html.BasePage {
+ 
      public abstract String getUsername();
  
      public abstract String getPassword();
@@ -89, +79 @@

      @InjectObject("service:tapestry.globals.HttpServletRequest")
      public abstract HttpServletRequest getHttpServletRequest();
  
+     @InjectObject( "engine-service:page")
+     public abstract IEngineService getPageService();
+ 
      public void submit() {
-         SavedRequest savedRequest =
-             (SavedRequest) this.getHttpServletRequest().getSession()
-                                .getAttribute(AbstractProcessingFilter.ACEGI_SAVED_REQUEST_KEY);
- 
          UsernamePasswordAuthenticationToken authRequest =
              new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
          Authentication authResult;
@@ -102, +91 @@

              authResult = this.getAuthenticationManager()
                               .authenticate(authRequest);
          } catch (final AuthenticationException failed) {
-             SecurityContextHolder.getContext().setAuthentication(null);
- 
              return;
          }
  
          SecurityContextHolder.getContext().setAuthentication(authResult);
  
+         SavedRequest savedRequest =
+             (SavedRequest) this.getHttpServletRequest().getSession()
+                                .getAttribute(AbstractProcessingFilter.ACEGI_SAVED_REQUEST_KEY);
+ 
+         if(savedRequest != null)
-         throw new RedirectException(savedRequest.getFullRequestUrl());
+             throw new RedirectException(savedRequest.getFullRequestUrl());
+         else
+             throw new RedirectException(getPageService().getLink(false, "Home").getURL());
      }
+ 
  }
  }}}
  

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