Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* ZkAuthenticationProcessingFilter.java
  
  {{IS_NOTE
  	Purpose:
  		
  	Description:
  		
  	History:
  		Thu Dec 21 16:17:28     2006, Created by Henri
 }}IS_NOTE
 
 Copyright (C) 2006 Potix Corporation. All Rights Reserved.
 
 {{IS_RIGHT
 }}IS_RIGHT
 */
 package org.zkoss.zkplus.acegi;
 
 
 
 import  org.acegisecurity.ui.webapp.AuthenticationProcessingFilter;
 import  org.acegisecurity.context.SecurityContextHolder;
 
 
 import  javax.servlet.http.HttpServletRequest;
 import  javax.servlet.http.HttpServletResponse;

This implementation process zk specific popup login page. If send user login sucessfullly, an "onLoginOK" event would be fired to the component that fired the event and caused the login processing. Since it will be tedious to register "onLoginOK" handler on every possible component, it is better to register an onLoginOK event handler on the concerned page.

Author(s):
Henri
See also:
ZkAuthenticationEntryPoint
ShowWindowEventListener
 
 public class ZkAuthenticationProcessingFilter extends AuthenticationProcessingFilter {
If end user login sucessfully, an ON_LOGIN_OK is fired. Register an associated event listener on the page and operate per the success.
 
 	private static final String ON_LOGIN_OK = "onLoginOK";
 	/*package*/ static final String CURRENT_EVENT = "org.zkoss.zkplus.acegi.CURRENT_EVENT";
 	private boolean _resendZkEvent = false//default to false
 
Whether re-send the ZK event that caused poping the login window after authentication successfully. It is default to false.
 
     public void setSendZkEventAfterSuccessfulAuthentication(boolean b) {
          = b;
     }
 
     protected boolean requiresAuthentication(HttpServletRequest request, HttpServletResponse response) {
     	final Event evt = (Eventrequest.getAttribute();
     	return Objects.equals(getFilterProcessesUrl(), request.getAttribute("j_loginurl")) && 
     			//must check the event name otherwise authentication would be called twice. 
     			//1st the login model window's button click event
     			//2nd the resumed onAcegiLogin thread resume and "cleanup".
     			//we now check only on 2nd event
     }
     
 	protected void sendRedirect(HttpServletRequest request, HttpServletResponse responseString url)
     throws IOException {
     	if (url == null) {
     		return//skip
     	}
 		final Event evt = (Event) ((HttpServletRequest)request).getSession().getAttribute(.);
 		final Component comp = evt.getTarget();
 		final String updateURI = comp.getDesktop().getUpdateURI(null);
     	if (url.indexOf(updateURI) >= 0) { //saved request
     		Events.postEvent(new Event(compnull)); //post onLoginOK event
     		if () {
 				((HttpServletRequest)request).getSession().removeAttribute(.);
 	    		Events.postEvent(evt);
 	    	}
     		return;
     	}
 
 		//must redirect
         if (url.startsWith("http://") || url.startsWith("https://")) {
             Executions.getCurrent().sendRedirect(url);
             return;
         }
 
 		//other url, assume login fail
 			final EventListener listener = new ShowWindowEventListener();
 		}
 		
     	Events.postEvent(new Event(.compurl));
	}
	protected String obtainPassword(HttpServletRequest request) {
        return (Stringrequest.getAttribute(ACEGI_SECURITY_FORM_PASSWORD_KEY);
    }
    protected String obtainUsername(HttpServletRequest request) {
        return (Stringrequest.getAttribute(ACEGI_SECURITY_FORM_USERNAME_KEY);
    }
New to GrepCode? Check out our FAQ X