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.ResourceRequest;
023    import javax.portlet.ResourceResponse;
024    
025    import javax.servlet.http.HttpServletRequest;
026    import javax.servlet.http.HttpServletResponse;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class CaptchaUtil {
032    
033            public static void check(HttpServletRequest request)
034                    throws CaptchaException {
035    
036                    getCaptcha().check(request);
037            }
038    
039            public static void check(PortletRequest portletRequest)
040                    throws CaptchaException {
041    
042                    getCaptcha().check(portletRequest);
043            }
044    
045            public static Captcha getCaptcha() {
046                    PortalRuntimePermission.checkGetBeanProperty(CaptchaUtil.class);
047    
048                    return _captcha;
049            }
050    
051            public static String getTaglibPath() {
052                    return getCaptcha().getTaglibPath();
053            }
054    
055            public static boolean isEnabled(HttpServletRequest request)
056                    throws CaptchaException {
057    
058                    return getCaptcha().isEnabled(request);
059            }
060    
061            public static boolean isEnabled(PortletRequest portletRequest)
062                    throws CaptchaException {
063    
064                    return getCaptcha().isEnabled(portletRequest);
065            }
066    
067            public static void serveImage(
068                            HttpServletRequest request, HttpServletResponse response)
069                    throws IOException {
070    
071                    getCaptcha().serveImage(request, response);
072            }
073    
074            public static void serveImage(
075                            ResourceRequest resourceRequest, ResourceResponse resourceResponse)
076                    throws IOException {
077    
078                    getCaptcha().serveImage(resourceRequest, resourceResponse);
079            }
080    
081            public void setCaptcha(Captcha captcha) {
082                    PortalRuntimePermission.checkSetBeanProperty(getClass());
083    
084                    _captcha = captcha;
085            }
086    
087            private static Captcha _captcha;
088    
089    }