- 浏览: 217025 次
- 性别:
- 来自: 湖北->上海
最新评论
-
苹果超人:
我也遇到这个问题,我想在ConfigurationAction ...
杀千刀的PortletPreferences -
flago:
Liferay 的论坛设置的默认显示多少条帖子怎么设置??
liferay中vm中如何调用java类代码 -
ofdata:
遭遇此问题
杀千刀的PortletPreferences -
yaokaiwen99:
大哥求一个简单的flexigrid在liferay中应用的例 ...
Liferay异步提交 -
gaigai511225:
你好 插件环境那个url 具体怎么写 我照您的方式写了出错 ...
Liferay异步提交
生成验证码相关:
验证码配置相关:
读取配置文件相关:
check验证码相关:
显示标签相关:
现在变懒了,不知道各位能看得明白不?最关键的是nl.captcha.servlet.CaptchaProducer和nl.captcha.util.Helper这个.
/** * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package com.liferay.portal.captcha; import com.liferay.portal.struts.ActionConstants; import com.liferay.portal.struts.PortletAction; import com.liferay.portal.util.PropsFiles; import com.liferay.portal.util.WebKeys; import com.liferay.portlet.ActionResponseImpl; import com.liferay.util.ExtPropertiesLoader; import java.util.Properties; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.PortletConfig; import javax.portlet.PortletSession; import javax.servlet.http.HttpServletResponse; import nl.captcha.servlet.CaptchaProducer; import nl.captcha.util.Helper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; /** * <a href="CaptchaPortletAction.java.html"><b><i>View Source</i></b></a> * * @author Brian Wing Shun Chan * */ public class CaptchaPortletAction extends PortletAction { public CaptchaPortletAction() { Properties props = ExtPropertiesLoader.getInstance( PropsFiles.CAPTCHA).getProperties(); _producer = (CaptchaProducer)Helper.ThingFactory.loadImpl( Helper.ThingFactory.CPROD, props); } public void processAction( ActionMapping mapping, ActionForm form, PortletConfig config, ActionRequest req, ActionResponse res) throws Exception { try { PortletSession ses = req.getPortletSession(); String captchaText = _producer.createText(); ses.setAttribute(WebKeys.CAPTCHA_TEXT, captchaText); HttpServletResponse httpRes = ((ActionResponseImpl)res).getHttpServletResponse(); _producer.createImage(httpRes.getOutputStream(), captchaText); setForward(req, ActionConstants.COMMON_NULL); } catch (Exception e) { _log.error(e); } } protected boolean isCheckMethodOnProcessAction() { return _CHECK_METHOD_ON_PROCESS_ACTION; } private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false; private static Log _log = LogFactory.getLog(CaptchaPortletAction.class); private CaptchaProducer _producer; }
验证码配置相关:
include-and-override=captcha-ext.properties cap.border=yes cap.border.c=black cap.border.th=1 cap.image.height=50 cap.image.width=150 #cap.text.producer=com.liferay.portal.captcha.DictionaryWordTextProducer cap.text.producer=com.liferay.portal.captcha.PinNumberTextProducer
读取配置文件相关:
/** * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package com.liferay.util; import com.germinus.easyconf.ComponentConfiguration; import com.germinus.easyconf.ComponentProperties; import com.germinus.easyconf.EasyConf; import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.model.Company; import com.liferay.portal.service.CompanyLocalServiceUtil; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; /** * <a href="ExtPropertiesLoader.java.html"><b><i>View Source</i></b></a> * * @author Brian Wing Shun Chan * */ public class ExtPropertiesLoader { public static ExtPropertiesLoader getInstance(String name) { ExtPropertiesLoader props = _propsPool.get(name); if (props == null) { props = new ExtPropertiesLoader(name); _propsPool.put(name, props); } return props; } public static ExtPropertiesLoader getInstance(String name, long companyId) { String key = name + _COMPANY_ID_SEPARATOR + companyId; ExtPropertiesLoader props = _propsPool.get(key); if (props == null) { props = new ExtPropertiesLoader(name, companyId); _propsPool.put(key, props); } return props; } public boolean containsKey(String key) { return getComponentProperties().containsKey(key); } public String get(String key) { if (_PRINT_DUPLICATE_KEYS) { if (_keys.contains(key)) { System.out.println("Duplicate key " + key); } else { _keys.add(key); } } return getComponentProperties().getString(key); } public void set(String key, String value) { getComponentProperties().setProperty(key, value); } public String[] getArray(String key) { String[] array = getComponentProperties().getStringArray(key); if (array == null) { return new String[0]; } else if (array.length > 0) { // Commons Configuration parses an empty property into a String // array with one String containing one space. It also leaves a // trailing array member if you set a property in more than one // line. if (Validator.isNull(array[array.length - 1])) { String[] subArray = new String[array.length - 1]; System.arraycopy(array, 0, subArray, 0, subArray.length); array = subArray; } } return array; } public Properties getProperties() { // For some strange reason, componentProperties.getProperties() returns // values with spaces after commas. So a property setting of "xyz=1,2,3" // actually returns "xyz=1, 2, 3". This can break applications that // don't expect that extra space. However, getting the property value // directly through componentProperties returns the correct value. This // method fixes the weird behavior by returing properties with the // correct values. Properties props = new Properties(); ComponentProperties componentProps = getComponentProperties(); Iterator<Map.Entry<Object, Object>> itr = componentProps.getProperties().entrySet().iterator(); while (itr.hasNext()) { Map.Entry<Object, Object> entry = itr.next(); String key = (String)entry.getKey(); String value = (String)entry.getValue(); props.setProperty(key, value); } return props; } public ComponentProperties getComponentProperties() { return _conf.getProperties(); } private ExtPropertiesLoader(String name) { _conf = EasyConf.getConfiguration(name); _printSources(name); } private ExtPropertiesLoader(String name, long companyId) { String webId = null; if (companyId > 0) { try { Company company = CompanyLocalServiceUtil.getCompanyById( companyId); webId = company.getWebId(); } catch (Exception e) { } } _conf = EasyConf.getConfiguration(webId, name); _printSources(name, companyId, webId); } private void _printSources(String name) { _printSources(name, 0, null); } private void _printSources(String name, long companyId, String webId) { List<String> sources = getComponentProperties().getLoadedSources(); for (int i = sources.size() - 1; i >= 0; i--) { String source = sources.get(i); String info = "Loading " + source; if (companyId > 0) { info += " for {companyId=" + companyId + ", webId=" + webId + "}"; } System.out.println(info); } } private static Map<String, ExtPropertiesLoader> _propsPool = new ConcurrentHashMap<String, ExtPropertiesLoader>(); private static final String _COMPANY_ID_SEPARATOR = "_COMPANY_ID_"; private static final boolean _PRINT_DUPLICATE_KEYS = false; private ComponentConfiguration _conf; private Set<String> _keys = new HashSet<String>(); }
check验证码相关:
/** * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package com.liferay.portal.captcha; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.util.PropsValues; import com.liferay.portal.util.WebKeys; import javax.portlet.PortletRequest; import javax.portlet.PortletSession; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * <a href="CaptchaUtil.java.html"><b><i>View Source</i></b></a> * * @author Brian Wing Shun Chan * */ public class CaptchaUtil { public static void check(HttpServletRequest req) throws CaptchaTextException { if (isEnabled(req)) { HttpSession ses = req.getSession(); String captchaText = (String)ses.getAttribute(WebKeys.CAPTCHA_TEXT); if (captchaText != null) { if (!captchaText.equals( ParamUtil.getString(req, "captchaText"))) { throw new CaptchaTextException(); } else { if (_log.isDebugEnabled()) { _log.debug("Captcha text is valid"); } ses.removeAttribute(WebKeys.CAPTCHA_TEXT); if ((PropsValues.CAPTCHA_MAX_CHALLENGES > 0) && (Validator.isNotNull(req.getRemoteUser()))) { Integer count = (Integer)ses.getAttribute( WebKeys.CAPTCHA_COUNT); if (count == null) { count = new Integer(1); } else { count = new Integer(count.intValue() + 1); } ses.setAttribute(WebKeys.CAPTCHA_COUNT, count); } } } else { if (_log.isErrorEnabled()) { _log.error( "Captcha text is null. User " + req.getRemoteUser() + " may be trying to circumvent the captcha."); } throw new CaptchaTextException(); } } } public static void check(PortletRequest req) throws CaptchaTextException { if (isEnabled(req)) { PortletSession ses = req.getPortletSession(); String captchaText = (String)ses.getAttribute(WebKeys.CAPTCHA_TEXT); if (captchaText != null) { if (!captchaText.equals( ParamUtil.getString(req, "captchaText"))) { throw new CaptchaTextException(); } else { if (_log.isDebugEnabled()) { _log.debug("Captcha text is valid"); } ses.removeAttribute(WebKeys.CAPTCHA_TEXT); if ((PropsValues.CAPTCHA_MAX_CHALLENGES > 0) && (Validator.isNotNull(req.getRemoteUser()))) { Integer count = (Integer)ses.getAttribute( WebKeys.CAPTCHA_COUNT); if (count == null) { count = new Integer(1); } else { count = new Integer(count.intValue() + 1); } ses.setAttribute(WebKeys.CAPTCHA_COUNT, count); } } } else { if (_log.isErrorEnabled()) { _log.error( "Captcha text is null. User " + req.getRemoteUser() + " may be trying to circumvent the captcha."); } throw new CaptchaTextException(); } } } public static boolean isEnabled(HttpServletRequest req) { if (PropsValues.CAPTCHA_MAX_CHALLENGES > 0) { HttpSession ses = req.getSession(); Integer count = (Integer)ses.getAttribute(WebKeys.CAPTCHA_COUNT); if ((count != null) && (PropsValues.CAPTCHA_MAX_CHALLENGES <= count.intValue())) { return false; } else { return true; } } else if (PropsValues.CAPTCHA_MAX_CHALLENGES < 0) { return false; } else { return true; } } public static boolean isEnabled(PortletRequest req) { if (PropsValues.CAPTCHA_MAX_CHALLENGES > 0) { PortletSession ses = req.getPortletSession(); Integer count = (Integer)ses.getAttribute(WebKeys.CAPTCHA_COUNT); if ((count != null) && (PropsValues.CAPTCHA_MAX_CHALLENGES <= count.intValue())) { return false; } else { return true; } } else if (PropsValues.CAPTCHA_MAX_CHALLENGES < 0) { return false; } else { return true; } } private static Log _log = LogFactory.getLog(CaptchaUtil.class); }
显示标签相关:
<%@ include file="/html/taglib/init.jsp" %> <%@ page import="com.liferay.portal.captcha.CaptchaUtil" %> <% String url = (String)request.getAttribute("liferay-ui:captcha:url"); boolean captchaEnabled = false; if (renderRequest != null) { captchaEnabled = CaptchaUtil.isEnabled(renderRequest); } else { captchaEnabled = CaptchaUtil.isEnabled(request); } %> <c:if test="<%= captchaEnabled %>"> <div> <img src="<%= url %>" /> </div> <br /> <table class="lfr-table"> <tr> <td> <liferay-ui:message key="text-verification" /> </td> <td> <input name="<%= namespace %>captchaText" size="10" type="text" value="" /> </td> </tr> </table> <br /> </c:if>
现在变懒了,不知道各位能看得明白不?最关键的是nl.captcha.servlet.CaptchaProducer和nl.captcha.util.Helper这个.
发表评论
-
JSR 286 Portlet 的新特性,第 3 部分: Portlet 过滤器和 Portlet 窗口
2010-06-01 10:24 2488在 本系列 的 第 1 部分 简要回顾了JSR 1 ... -
JSR 286 Portlet 的新特性,第 2 部分: 资源服务、事件与共享呈现参数
2010-05-31 18:42 2201在本系列的 第 1 部分 简要回顾了 J ... -
JSR 286 Portlet 的新特性,第 1 部分: Portlet 2.0 新特性介绍
2010-05-31 17:55 2379本系列文章专门针 ... -
Session share
2010-05-14 12:18 0Tomcat Server.xml <Servi ... -
Liferay集群负载均衡配置
2009-10-30 11:14 4882先介绍一下项目系统的环境, Liferay Version: ... -
Liferay 集群部署
2009-10-30 00:00 0十二点了,明天断续 -
Liferay 权限策略
2009-10-29 23:45 3094先上一张大家都很熟悉的图 这张图可以说是整 ... -
Liferay Portlet之间的通信
2009-10-29 19:12 5007从我做Liferay到现在,这个问题一直都存在着,直到最近我才 ... -
Liferay异步提交
2009-10-29 18:06 3396liferay的异步提交其实是非常简单的,他用的是json & ... -
Liferay异步刷新
2009-10-29 18:05 3171Liferay portlet异步刷新,分为两种情况。 ... -
准备开始整理半年来对lifeay新的学习成果
2009-10-29 18:04 1491有半年没有写过liferay的blog了,不过对life ... -
Ajax知识
2009-06-11 17:50 0<SCRIPT LANGUAGE=" ... -
改变Liferay Portal Context(让Liferay不在使用ROOT目录)
2009-05-25 22:46 1825在部署的时候如果遇到我们会遇到让liferay与其他的项目并存 ... -
velocity调用DB持久层,生成actionurl
2009-05-22 17:42 1173#set($hostelCacheService = $ser ... -
liferay 所有版本下载地址
2009-05-21 13:29 3207从1.7.5一直到现在的5.2.3,应有尽有。 htt ... -
liferay ldap配置与相关代码
2008-11-28 11:06 38221.下载LDAP server 并安装, liferay支 ... -
liferay 的加密技术(CRYPT,SHA,SSHA,MD2,MD5)
2008-11-27 15:59 4286package com.liferay.util; impo ... -
liferay openid配置与代码详解
2008-11-21 21:14 28251.liferay的openid的配置很简单的,先去 open ... -
很烦,想站在阳台上大声的喊
2008-08-20 19:42 1794终于到回家了,好累, ... -
网络爬虫相关(自已记下来,怕以后忘记)
2008-08-16 13:15 1926package com.taobao.html; impor ...
相关推荐
Liferay Portal Liferay IDE
Liferay是一款开源的企业级门户平台,它提供了丰富的功能和高度可定制性,广泛应用于构建企业网站、内部系统、协作平台等。在这个“liferay详细讲解 liferay项目完全讲解”的资料包中,我们可以期待深入了解到关于...
标题 "Liferay扩展环境 Liferay Ext" 涉及到的是Liferay门户平台的一个关键概念,Liferay Ext是用于扩展和定制Liferay功能的核心工具。Liferay是一个开源的企业级内容管理平台,它允许用户根据需求构建自定义的数字...
- 在Liferay中,你需要配置服务提供者(Service Provider)以识别CAS服务器作为认证源。这通常涉及修改Liferay的配置文件,如`portal-ext.properties`,并启用CAS插件或模块。 6. **配置CAS客户端** - 配置...
3. **设置Liferay安全策略**:在Liferay的控制台中,你需要为你的站点或特定的Web内容设置安全策略,启用CAS认证,并指定相应的CAS服务器配置。 4. **测试SSO功能**:完成配置后,可以通过尝试登录Liferay并访问受...
### Liferay环境搭建详解 #### 一、简介 Liferay是一款功能强大的开源企业级门户平台,主要用于构建企业级Web应用程序和服务。本文档旨在详细介绍如何利用Eclipse集成开发环境(IDE)来搭建Liferay开发环境,并...
7. **安全与权限**:掌握Liferay的安全模型,包括用户认证、授权和权限控制。 8. **性能优化**:学习如何调整Liferay的配置以提高系统性能,包括缓存策略、数据库调优等。 9. **API与插件开发**:熟悉Liferay的...
### Liferay快速入门知识点详解 #### 一、Liferay Portal简介与快速启动 Liferay Portal是一款功能强大且灵活的企业级门户平台,它基于Java技术,遵循JSR-168标准,提供了丰富的特性来满足企业内外部网站的需求。...
【Liferay 6 入门教程】 Liferay是一款开源的企业级门户平台,广泛用于构建企业网站、社交网络和协作工具。Liferay 6是其一个重要的版本,提供了丰富的功能和改进,包括更好的用户体验、增强的社区参与度以及更强大...
Liferay 6.2是一款流行的开源企业级门户平台,它提供了丰富的功能,包括内容管理、社交媒体集成、工作流程以及自定义开发能力。本指南将基于提供的"liferay 6.2开发指南+用户手册"来深入讲解其核心知识点。 1. **...
Liferay是一款开源的企业级门户平台,它提供了丰富的功能来构建和管理数字体验,包括网站创建、内容管理、社交协作以及工作流程。以下是对这8本Liferay经典书籍的知识点总结,旨在帮助读者深入理解并掌握Liferay的...
Liferay是一款开源的企业级门户平台,它提供了丰富的功能和高度的可扩展性。Struts则是一个经典的MVC(模型-视图-控制器)框架,用于构建Java Web应用程序。将Liferay与Struts整合,可以充分利用Struts的业务逻辑...
Liferay 是一个开源的企业级门户平台,它提供了一个强大的框架,用于构建和管理Web应用程序、内容和工作流程。本超学习文档将深入探讨Liferay的核心特性、开发环境、Java技术的应用以及Hibernate在Liferay中的整合。...
《Liferay开发文档集合》是针对企业级门户平台Liferay的一系列技术指南,涵盖了从基础安装到高级定制的全方位知识。这些PDF文档旨在帮助开发者、系统管理员和IT专业人员更好地理解和利用Liferay Portal来构建和管理...
- **集成 Liferay**:在 Liferay 中配置 CAS 作为认证提供者,这可能涉及修改 Liferay 的 `portal-ext.properties` 文件,添加 CAS 服务器的相关配置,比如 CAS 服务器的 URL、服务验证 URL 等。 - **测试集成**:...
《Liferay Portal 6.0.6 学习手册》是针对企业级开源门户平台Liferay Portal的一个详细学习指南,由作者李少华编写。本文将深入探讨Liferay Portal的基础知识,安装配置,源码分析,开发环境设置,以及基于Struts2的...
Liferay入门帮助文档是针对Liferay开发的一份指南,它主要涵盖了如何开始使用这个全面的门户解决方案。Liferay是一个基于Java Enterprise Edition (J2EE) 的应用,它整合了多种技术,如EJB (Enterprise JavaBeans) ...
### Liferay Portal 二次开发详解 #### 一、Liferay Portal 概览 **Liferay Portal** 是一款开源的企业级门户平台,它基于Java技术构建,支持多种标准,包括JSR 168 和 WSRP (Web Services for Remote Portlets)。...
**Liferay简介** Liferay是一款开源的企业级门户平台,它提供了强大的内容管理、协作和社交功能,被广泛用于构建企业内部或外部的Web应用程序。Liferay的核心特性包括网站构建、内容管理、工作流程、社区参与以及与...