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.portlet.login.action;
016    
017    import com.liferay.portal.kernel.captcha.CaptchaUtil;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.kernel.portlet.bridges.mvc.MVCResourceCommand;
021    import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
022    import com.liferay.portal.util.PortletKeys;
023    
024    import javax.portlet.ResourceRequest;
025    import javax.portlet.ResourceResponse;
026    
027    /**
028     * @author Pei-Jung Lan
029     */
030    @OSGiBeanProperties(
031            property = {
032                    "javax.portlet.name=" + PortletKeys.LOGIN,
033                    "mvc.command.name=/login/captcha"
034            },
035            service = MVCResourceCommand.class
036    )
037    public class CaptchaMVCResourceCommand implements MVCResourceCommand {
038    
039            @Override
040            public boolean serveResource(
041                    ResourceRequest resourceRequest, ResourceResponse resourceResponse) {
042    
043                    try {
044                            CaptchaUtil.serveImage(resourceRequest, resourceResponse);
045    
046                            return false;
047                    }
048                    catch (Exception e) {
049                            _log.error(e, e);
050    
051                            return true;
052                    }
053            }
054    
055            private static final Log _log = LogFactoryUtil.getLog(
056                    CaptchaMVCResourceCommand.class);
057    
058    }