001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.captcha;
016    
017    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
018    
019    import java.io.IOException;
020    
021    import javax.portlet.PortletRequest;
022    import javax.portlet.PortletResponse;
023    
024    import javax.servlet.http.HttpServletRequest;
025    import javax.servlet.http.HttpServletResponse;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class CaptchaUtil {
031    
032            public static void check(HttpServletRequest request)
033                    throws CaptchaException {
034    
035                    getCaptcha().check(request);
036            }
037    
038            public static void check(PortletRequest portletRequest)
039                    throws CaptchaException {
040    
041                    getCaptcha().check(portletRequest);
042            }
043    
044            public static Captcha getCaptcha() {
045                    PortalRuntimePermission.checkGetBeanProperty(CaptchaUtil.class);
046    
047                    return _captcha;
048            }
049    
050            public static String getTaglibPath() {
051                    return getCaptcha().getTaglibPath();
052            }
053    
054            public static boolean isEnabled(HttpServletRequest request)
055                    throws CaptchaException {
056    
057                    return getCaptcha().isEnabled(request);
058            }
059    
060            public static boolean isEnabled(PortletRequest portletRequest)
061                    throws CaptchaException {
062    
063                    return getCaptcha().isEnabled(portletRequest);
064            }
065    
066            public static void serveImage(
067                            HttpServletRequest request, HttpServletResponse response)
068                    throws IOException {
069    
070                    getCaptcha().serveImage(request, response);
071            }
072    
073            public static void serveImage(
074                            PortletRequest portletRequest, PortletResponse portletResponse)
075                    throws IOException {
076    
077                    getCaptcha().serveImage(portletRequest, portletResponse);
078            }
079    
080            public void setCaptcha(Captcha captcha) {
081                    PortalRuntimePermission.checkSetBeanProperty(getClass());
082    
083                    _captcha = captcha;
084            }
085    
086            private static Captcha _captcha;
087    
088    }