001    /**
002     * Copyright (c) 2000-present 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                    return getCaptcha().isEnabled(request);
057            }
058    
059            public static boolean isEnabled(PortletRequest portletRequest) {
060                    return getCaptcha().isEnabled(portletRequest);
061            }
062    
063            public static void serveImage(
064                            HttpServletRequest request, HttpServletResponse response)
065                    throws IOException {
066    
067                    getCaptcha().serveImage(request, response);
068            }
069    
070            public static void serveImage(
071                            ResourceRequest resourceRequest, ResourceResponse resourceResponse)
072                    throws IOException {
073    
074                    getCaptcha().serveImage(resourceRequest, resourceResponse);
075            }
076    
077            public void setCaptcha(Captcha captcha) {
078                    PortalRuntimePermission.checkSetBeanProperty(getClass());
079    
080                    _captcha = captcha;
081            }
082    
083            private static Captcha _captcha;
084    
085    }