01: /* ZkAuthenticationEntryPoint.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Thu Dec 21 16:17:28 2006, Created by Henri
10: }}IS_NOTE
11:
12: Copyright (C) 2006 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: }}IS_RIGHT
16: */
17: package org.zkoss.zkplus.acegi;
18:
19: import org.zkoss.zk.ui.Page;
20: import org.zkoss.zk.ui.Component;
21: import org.zkoss.zk.ui.UiException;
22: import org.zkoss.zk.ui.event.Event;
23: import org.zkoss.zk.ui.event.Events;
24: import org.zkoss.zk.ui.event.EventListener;
25: import org.zkoss.zk.ui.Execution;
26: import org.zkoss.zk.ui.Executions;
27: import org.zkoss.zk.ui.UiException;
28:
29: import org.zkoss.zul.Textbox;
30: import org.zkoss.zul.Window;
31:
32: import org.acegisecurity.AuthenticationException;
33: import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
34: import org.acegisecurity.ui.webapp.AuthenticationProcessingFilter;
35: import org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint;
36: import org.acegisecurity.context.SecurityContextHolder;
37: import org.springframework.beans.factory.InitializingBean;
38:
39: import org.springframework.util.Assert;
40:
41: import java.util.Map;
42: import java.util.List;
43: import java.util.HashMap;
44: import java.util.ArrayList;
45:
46: import java.io.IOException;
47:
48: import javax.servlet.http.HttpServletRequestWrapper;
49: import javax.servlet.RequestDispatcher;
50: import javax.servlet.ServletException;
51: import javax.servlet.ServletRequest;
52: import javax.servlet.ServletResponse;
53: import javax.servlet.http.HttpServletRequest;
54: import javax.servlet.http.HttpServletResponse;
55:
56: /**
57: * <p>This implementation would forward to onAcegiLogin event and popup a login page.</p>
58: *
59: * @see ZkAuthenticationProcessingFilter
60: * @see ShowWindowEventListener
61: * @author Henri
62: */
63: public class ZkAuthenticationEntryPoint extends
64: AuthenticationProcessingFilterEntryPoint {
65: /*package*/static final String ON_ACEGILOGIN = "onAcegiLogin";
66:
67: /** <p>This implmentation forward request to onAcegiLogin command.</p>
68: */
69: public void commence(ServletRequest request,
70: ServletResponse response,
71: AuthenticationException authException) throws IOException,
72: ServletException {
73: final Component comp = (Component) request
74: .getAttribute(ZkEventExceptionFilter.COMPONENT);
75:
76: //remember the original event that cause the security login in session
77: final Event evt = (Event) request
78: .getAttribute(ZkEventExceptionFilter.EVENT);
79: ((HttpServletRequest) request).getSession().setAttribute(
80: ZkEventExceptionFilter.EVENT, evt);
81:
82: if (!comp.isListenerAvailable(ON_ACEGILOGIN, true)) {
83: final EventListener listener = new ShowWindowEventListener();
84: comp.setAttribute(ON_ACEGILOGIN, listener);
85: comp.addEventListener(ON_ACEGILOGIN, listener);
86: }
87: final String url = getLoginFormUrl();
88: Events.postEvent(new Event(ON_ACEGILOGIN, comp,
89: url != null ? url : "~./acegilogin.zul"));
90: }
91: }
|