Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* ZkEventExceptionFilter.java
  
  {{IS_NOTE
  	Purpose:
  		
  	Description:
  		
  	History:
  		Mon Dec 25 15:08:49     2006, Created by henrichen
 }}IS_NOTE
 
 Copyright (C) 2006 Potix Corporation. All Rights Reserved.
 
 {{IS_RIGHT
 	This program is distributed under GPL Version 3.0 in the hope that
 	it will be useful, but WITHOUT ANY WARRANTY.
 }}IS_RIGHT
 */
 package org.zkoss.zkplus.acegi;
 
 
 import  javax.servlet.ServletContext;
 import  javax.servlet.ServletRequest;
 import  javax.servlet.ServletResponse;
 import  javax.servlet.FilterChain;
 import  javax.servlet.Filter;
 import  javax.servlet.FilterConfig;
 import  javax.servlet.ServletException;
 import  javax.servlet.http.HttpServletRequest;
 import  javax.servlet.http.HttpServletResponse;
 
 
 
 import  org.acegisecurity.AcegiSecurityException;
 
 import  org.springframework.beans.factory.InitializingBean;
 import  org.springframework.util.Assert;

Used to fire exception in the ZK's event processing queue (Used with MethodSecurityInterceptor).

How to handle the ZK's Ajax login support for Acegi Security System:


 <bean id="zkFilterChainProxy" class="org.acegisecurity.util.FilterChainProxy">
  <property name="filterInvocationDefinitionSource">
   <value>
    CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
    PATTERN_TYPE_APACHE_ANT
    /zkau/**=zkAuthenticationProcessingFilter,zkExceptionTranslationFilter,zkEventExceptionFilter
   </value>
  </property>
 </bean>

 <bean id="filterChainProxy" class="org.acegisecurity.util.FilterChainProxy">
  <property name="filterInvocationDefinitionSource">
   <value>
    CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
    PATTERN_TYPE_APACHE_ANT
    /zkau/**=httpSessionContextIntegrationFilter,logoutFilter,rememberMeProcessingFilter,anonymousProcessingFilter
    /**=httpSessionContextIntegrationFilter,logoutFilter,authenticationProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor
   </value>
  </property>
 </bean>

 <bean id="zkEventExceptionFilter" class="org.zkoss.zkplus.acegi.ZkEventExceptionFilter"/>

 <bean id="zkExceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter">
  <property name="authenticationEntryPoint">
   <bean class="org.zkoss.zkplus.acegi.ZkAuthenticationEntryPoint">
    <property name="loginFormUrl" value="~./acegilogin.zul"/>
    <property name="forceHttps" value="false"/>
    <property name="serverSideRedirect" value="true"/>
   </bean>
  </property>
  <property name="accessDeniedHandler">
   <bean class="org.zkoss.zkplus.acegi.ZkAccessDeniedHandler">
    <property name="errorPage" value="~./accessDenied.zul"/>
   </bean>
  </property>
 </bean>

 <bean id="zkAuthenticationProcessingFilter" class="org.zkoss.zkplus.acegi.ZkAuthenticationProcessingFilter">
  <property name="authenticationManager" ref="authenticationManager"/>
  <property name="authenticationFailureUrl" value="~./acegilogin.zul?login_error=1"/>
  <property name="defaultTargetUrl" value="/"/>
  <property name="filterProcessesUrl" value="/j_acegi_security_check"/>
  <property name="rememberMeServices" ref="zkRememberMeServices"/>
 </bean>

 <bean id="zkRememberMeServices" class="org.zkoss.zkplus.acegi.ZkTokenBasedRememberMeServices">
  <property name="userDetailsService" ref="userDetailsService"/>
  <property name="key" value="changeThis"/>
 </bean>

 ...
 

Author(s):
henrichen
public class ZkEventExceptionFilter implements Filter, InitializingBean {
	private static final Log log = Log.lookup(ZkEventExceptionFilter.class);
	/*package*/ static final String EXCEPTION = "org.zkoss.zkplus.acegi.EXCEPTION";
	/*package*/ static final String COMPONENT = "org.zkoss.zkplus.acegi.COMPONENT";
	/*package*/ static final String EVENT = "org.zkoss.zkplus.acegi.EVENT";
    public void afterPropertiesSet() throws Exception {}
	//-- Filter --//
	public void doFilter(ServletRequest request, ServletResponse response,
	FilterChain chainthrows IOException, ServletException {
		chain.doFilter(requestresponse);
		final AcegiSecurityException exception  = (AcegiSecurityException) request.getAttribute();
		if ( exception != null) {
			request.removeAttribute();
			throw exception;
		}
	}
	public void destroy() {}
	public final void init(FilterConfig configthrows ServletException {}
New to GrepCode? Check out our FAQ X