23.12.2012 Views

ZK Developer's Guide

ZK Developer's Guide

ZK Developer's Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Is it on the Desktop or on the Web?<br />

username.getValue();<br />

//validate the password<br />

password.getValue();<br />

UserFactory.login(user);<br />

Executions.sendRedirect("index.zul");<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

com.packtpub.zk.media.model.User user = com.packtpub.zk.media.<br />

model.UserFactory.create();<br />

<br />

<br />

The user instance is stored into the session. For minimal security, which isn't enough<br />

for production environments, we use an implementation of javax.servlet.Filter<br />

and register it in web.xml.<br />

<br />

SecurityFilter<br />

com.packtpub.zk.media.controller.SecurityFilter<br />

<br />

loginPage<br />

login.zul<br />

<br />

<br />

<br />

SecurityFilter<br />

*.zul<br />

<br />

To complete the example, implementation of the filter method doFilter is<br />

as follows:<br />

public void doFilter(ServletRequest request, ServletResponse response,<br />

FilterChain chain) throws IOException, ServletException<br />

{<br />

HttpSession session = ((HttpServletRequest) request).getSession();<br />

[ 102 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!