??xml version="1.0" encoding="utf-8" standalone="yes"?>
]]>
q是我自qI出来的Q真的可以说是世界首发了(jin)Q网上也有一些例子,都要么就是老版本,要么q复杂。我的这个方法特单,希望对大家有用,也希望大家珍?/font>
因ؓ(f)公司的需要,直接写的英文版的Q不惛_译回来?jin)。都不难理解Q一看就能明白。不懂的L(fng)a
Introduction
First of all, I should say that setting liferay to connect to another database is very easy. Certainty, all of things to make easy always after numerous attempts . I searched several solutions from website before. But, not only for old version but also too complex. As my understand According to original source, and several trial. I found the way. And I think that it is the World Premiere.^_^
Prerequisites
You should know how to create services with Service Builder, Also You should know how to create new portlet. how to link to database and how it is used inside programming language code.
The steps described here were performed over Liferay 6.0.6.
Let us Beginning
1. Create a file named portal-ext.properties in {WEBSERVER-HOME}\webapps\ROOT\WEB-INF\classes. And type the following code:
2. Create a service.xml file. And type the following code:
3. Ant build-service.xml, let liferay to generate code.
4. Create a new file named ext-spring.xml in src\META-INF folder. And copy the following code:
5. No more. So easy right? About how to call and deploy it. I believe that you can do.
一句话也不用多_(d)
W一Q在Web.xml文g里加上FilterQ对所有页面进行一ơ编码{换.
下面是EncodingFilterc:(x)
W二步,修改CAS登陆验证面的编码,如果你没换过q个主题的话Q默认的是修改WEB-INF\view\jsp\default\ui\casLoginView.jsp文gQ在最上面加上<%@ page pageEncoding="gb2312"%>。这里要特别注意一下,q个面的编码要和上面XML文g里写的编码一致?/p>
W三步,修改验证成功后做跌{的页面。也是WEB-INF\view\jsp\protocol\2.0\casServiceValidationSuccess.jsp文gQ在最上面加上<%@ page pageEncoding="UTF-8"%>。这里特别注意的是这个页面的~码要和你蟩转过ȝ那个面的编码一_(d)换句话说Q客L(fng)的验证页面的~码要和q个地方的一_(d)不一致的话,要{换一下?/p>
l过q三步之后,理论上讲已l可以验证通过?jin)?/p>
打开源代码文件util-taglib/src/com/liferay/taglib/util/VelocityTaglib.java
扑ֈjournalContentSearch()Ҏ(gu)Q再后面增加一个方法:(x)
public String journalArticleSearch() throws Exception {
_res.recycle();
SearchTag.doTag(_ctx, _req, _res);
return _res.getString();
}
重新成生util-taglib.Jar包。发布到服务器?/p>
然后Q修改主题包中原来的$theme.journalContentSearch()?theme.journalArticleSearch()Q即可?/p>
W一步,创徏证书
keytool -genkey -alias tomcat -keystore c:\mykeystore -dname "CN=xyb, OU=localhost, O=localhost, L=SH, ST=SH, C=CN" -keypass 123456 -storepass 123456
PS:
-genkey 创徏一个证?br />
-alias 证书的别?br />
-keystore 指定生成此证书的路径(可不写,默认存在pȝ的Home目录?keystore文g?br />
-storepass 指定密钥库的密码
-keypass 指定别名条目的密?br />
-dname 指定证书拥有者信?可不写,但,pȝ?x)提CZ依次输入q些信息Q特别要注意“CN”的值是你想做ؓ(f)CAS服务器的q台机器的域名或机器名,但就是不能是IP)
-keyalg 指定密钥的算?可不?
-validity 指定创徏的证书有效期多少?可不写,默认?0?
W二步,导出证书
keytool -export -alias tomcat -keystore c:\mykeystore -file c:\mycerts.cer -storepass 123456
PS:
-export 别名指定的证书导出到文?br />
-keystore 指定生成此证书的路径(上一步中写的什么这写什么,如果没写Q这也不?
-file 指定导出到文件的文g?/p>
W三步,把导出的证书导入到客L(fng)服务?/p>
keytool -import -trustcacerts -alias tomcat -keystore "%JAVA_HOME%/JRE/LIB/SECURITY/CACERTS" -storepass 123456 -file c:\mycerts.cer
PS:
-import 已{数字证书导入密钥?br />
-file 指定要导入到密钥库的文g?也就是上一步导出的那个文g)
有一个提C:(x)是否信Qq个证书Q输?YQ回车?/p>
W四步,下蝲cas集成包。将下蝲后的文g改名为cas-webQ放|在liferay的webapps目录下,在conf/server.xml中找C面这D,L原有的注释ƈ修改为:(x)
W五步,在Liferay的webapps\ROOT\WEB-INF\classes\portal-ext.properties下添加如下内容:(x)
cas.auth.enabled=true
cas.login.url=https://xyb:8443/cas-web/login
cas.logout.url=https://xyb:8443/cas-web/logout
cas.server.name=客户端IP:8080
cas.service.url=
#cas.service.url=http://localhost:8080/c/portal/login
cas.validate.url=https://xyb:8443/cas-web/proxyValidate
如果没在Liferay下,只是普通的WebE序可用Filter来实玎ͼ打开Web-INF\Web.XML文gQ增加如下代?/p>
<filter>
<filter-name>CASFilter</filter-name>
<filter-class>edu.yale.its.tp.cas.client.filter.CASFilter</filter-class>
<init-param>
<param-name>edu.yale.its.tp.cas.client.filter.loginUrl</param-name>
<param-value>https://xyb:8443/cas-web/login</param-value>
</init-param><!--q里的xyb是CAS服务端的IP或机器名-->
<init-param>
<param-name>edu.yale.its.tp.cas.client.filter.validateUrl</param-name>
<param-value>https://xyb:8443/cas-web/proxyValidate</param-value>
</init-param>
<init-param>
<param-name>edu.yale.its.tp.cas.client.filter.serverName</param-name>
<param-value>localhost:8080</param-value><!--client:port是需要CAS需要拦截的地址和端口,一般就是这个TOMCAT所启动的IP和port-->
</init-param>
</filter>
<filter-mapping>
<filter-name>CASFilter</filter-name>
<url-pattern>/*</url-pattern><!--q里是你要拦截的URLh-->
</filter-mapping>
最后一步,在客L(fng)获取CAS认证通过的用户名Qƈ修改w䆾验证E序为只通过用户名来验证。如是在Liferay下就不用做这一步了(jin)QLiferay中本w的验证是ScreenName字段
1、在JSP或Servlet中的用法Q?/p>
2、在Java中通过 Session 获取d用户?/p>
3、在 JSTL 中获取用户名的方?/p>
问题汇总:(x)
严重: edu.yale.its.tp.cas.client.CASAuthenticationException: Unable to validate ProxyTicketValidator [[edu.yale.its.tp.cas.client.ProxyTicketValidator prox
yList=[null] [edu.yale.its.tp.cas.client.ServiceTicketValidator casValidateUrl=[https://192.168.1.111:8443/cas/proxyValidate] ticket=[ST-0-9h7Mx5HK3pfsdxRv
MD3y] service=[http%3A%2F%2F192.168.1.222%3A8080%2Fservlets-examples%2Fservlet%2FHelloWorldExample] renew=false]]]
q个CAS异常是从CAS Client里面抛出Q是当我们不使用证书的CN去访问域名的时候(比如上文是用IP讉K而且证书的CN是该IP对应的域名而非该IPQ,CASClient无法信QQ也是我上面特意提到的那个CN的问题。要特别注意?/p>
q有一U情况就是客L(fng)证书没有导入,同样也报q个错误,最l可以归Z句话,肯定是证书验证没有通过所?
INFO [org.jasig.cas.authentication.AuthenticationManager
Impl] - <AuthenticationHandler: cn.com.tiansky.cas.authenticationHandlers.UPAuthenticationHandler successfully authenticated the user which provided the followi
ng credentials: [username: test]>
q错误Q可能是客户端的那个配置文g里写的不太对。也是上面说的W五步,要多注意一下?/p>
java.io.IOException: Cannot recover key
at org.apache.tomcat.util.net.jsse.JSSE14SocketFactory.init(JSSE14Socket
Factory.java:125)
at org.apache.tomcat.util.net.jsse.JSSESocketFactory.createSocket(JSSESo
cketFactory.java:88)
at org.apache.tomcat.util.net.PoolTcpEndpoint.initEndpoint(PoolTcpEndpoi
nt.java:292)
at org.apache.coyote.http11.Http11BaseProtocol.init(Http11BaseProtocol.j
ava:138)
at org.apache.catalina.connector.Connector.initialize(Connector.java:101
q种错误Q可能是你生成的证书有问题,如果keypass和storepass的密码不一致也?x)把q个?不知Z么非要设成一L(fng))