KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jguard > example > struts > admin > actions > CaptchaAction


1 /*
2  jGuard is a security framework based on top of jaas (java authentication and authorization security).
3  it is written for web applications, to resolve simply, access control problems.
4  version $Name$
5  http://sourceforge.net/projects/jguard/
6
7  Copyright (C) 2004 Charles GAY
8
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23
24  jGuard project home page:
25  http://sourceforge.net/projects/jguard/
26
27  */

28 package net.sf.jguard.example.struts.admin.actions;
29
30 import java.io.IOException JavaDoc;
31
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34
35 import net.sf.jguard.example.struts.actions.BaseAction;
36 import net.sf.jguard.jee.authentication.http.CaptchaChallengeBuilder;
37
38 import org.apache.log4j.Logger;
39 import org.apache.struts.action.ActionForm;
40 import org.apache.struts.action.ActionForward;
41 import org.apache.struts.action.ActionMapping;
42
43 import com.octo.captcha.service.CaptchaServiceException;
44 import com.sun.image.codec.jpeg.ImageFormatException;
45
46 /**
47  * Struts action called with the image 'src' link, which generate CAPTCHA image.
48  *
49  * @author <a HREF="mailto:diabolo512@users.sourceforge.net">Charles Gay</a>
50  *
51  */

52 public class CaptchaAction extends BaseAction {
53     private static Logger logger = Logger.getLogger(CaptchaAction.class);
54
55     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
56         
57         try {
58             CaptchaChallengeBuilder.buildCaptchaChallenge(request, response);
59         } catch (IllegalArgumentException JavaDoc e) {
60             logger.error(e.getMessage());
61             return mapping.findForward("CaptchaKO");
62         } catch (CaptchaServiceException e) {
63             logger.error(e.getMessage());
64             return mapping.findForward("CaptchaKO");
65         } catch (ImageFormatException e) {
66             logger.error(e.getMessage());
67             return mapping.findForward("CaptchaKO");
68         } catch (IOException JavaDoc e) {
69             logger.error(e.getMessage());
70             return mapping.findForward("CaptchaKO");
71         }
72
73         return null;
74     }
75
76     
77     
78 }
79
Popular Tags