zl程序教程

您现在的位置是:首页 >  后端

当前栏目

cas server 端部署

2023-09-11 14:18:43 时间

 

首先在 was7.0 上安装 cas-server-webapp-3.4.8.war

安装完成后 , 启动时会报错。

1.     日志中会提示 persistence.xml 中的 version 属性为【 1 】。将 \cas-server-webapp-3_4_8_war.ear\cas-server-webapp-3.4.8.war\WEB-INF\classes\META-INF\persistence.xml  

version="2.0" 改为  version="1.0"

2.    会提示一些类的方法找不到,原因是由于 jar 包冲突 , 需要就将 \cas-server-webapp-3_4_8_war.ear\cas-server-webapp-3.4.8.war\WEB-INF\lib\hibernate-jpa-2.0-api-1.0.0.Final.jar  删除 . 建议复制到其他目录 , 以免出现错误 , 无法返回 .

然后修改以下配置文件中的内容,去除( https 安全认证的验证方式),可以免除数字证书的生成的导入。

1\cas-server-webapp-3_4_8_war.ear\cas-server-webapp-3.4.8.war\WEB-INF\spring-configuration\warnCookieGenerator.xml  p:cookieSecure="true" 改为  p:cookieSecure="false"
2.\cas-server-webapp-3_4_8_war.ear\cas-server-webapp-3.4.8.war\WEB-INF\spring-configuration\ticketGrantingTicketCookieGenerator.xml  p:cookieSecure="true" 改为  p:cookieSecure="false"
3.\cas-server-webapp-3_4_8_war.ear\cas-server-webapp-3.4.8.war\WEB-INF\deployerConfigContext.xml    
<bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"
p:httpClient-ref="httpClient" />
改为
<bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"
p:httpClient-ref="httpClient" p:requireSecure="false" />

<?xml:namespace prefix = ons = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

最后将以下文件中的请求地址改为 cas server 所在的地址和端口。

\cas-server-webapp-3_4_8_war.ear\cas-server-webapp-3.4.8.war\WEB-INF\cas.properties

二 casclient端部署,这边比较简单,主要是修改web.xml.具体内容如下:(当客户端需要部署在was上时,需要使用websphere7.0.0.7及以上的版本。本人在was7.0.0.0上测试部署客户端时,遇到客户端请求不能被拦截跳转等问题。)
1. 首先导入jar包 : cas-client-core-3.2.0.jar
2. 修改web.xml,添加以下内容

<!-- 该过滤器用于实现单点登出功能,可选配置。-->
 <!--用于单点退出,该过滤器用于实现单点登出功能,通知其他应用单点登出-->
 <listener>
  <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>
 </listener>
 <filter>
  <filter-name>CASSingle Sign OutFilter</filter-name>
  <filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>CASSingle Sign OutFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <!-- 该过滤器负责用户的认证工作,必须启用它-->
 <filter>
  <filter-name>CASAuthenticationFilter</filter-name>
  <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
  <init-param>
   <param-name>casServerLoginUrl</param-name>
   <!--下面这个地址是cas server端的登录请求地址 -->
   <param-value>http://localhost:9080/cas/login</param-value>
  </init-param>
  <init-param>
   <param-name>serverName</param-name>
   <!--下面这个地址是本应用所部署的访问地址,不加上下文 -->
   <param-value>http://localhost:8080</param-value>
  </init-param>
  <init-param>
           <param-name>renew</param-name>
           <param-value>false</param-value>
       </init-param>
       <init-param>
           <param-name>gateway</param-name>
           <param-value>false</param-value>
       </init-param>
 </filter>
 <filter-mapping>
  <filter-name>CASAuthenticationFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <!-- 该过滤器负责对Ticket的校验工作,必须启用它-->
 <filter>
  <filter-name>CASValidation Filter</filter-name>
  <filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>
  <init-param>
   <param-name>casServerUrlPrefix</param-name>
   <!--下面这个地址是cas server端的地址 -->
   <param-value>http://localhost:9080/cas</param-value>
  </init-param>
  <init-param>
   <param-name>serverName</param-name>
   <!--下面这个地址是本应用所部署的访问地址,不加上下文 -->
   <param-value>http://localhost:8080</param-value>
  </init-param>
    <init-param>    
           <param-name>useSession</param-name>    
           <param-value>true</param-value>    
       </init-param>    
       <init-param>    
           <param-name>redirectAfterValidation</param-name>    
           <param-value>true</param-value>    
       </init-param>  
 </filter>
 <filter-mapping>
  <filter-name>CASValidation Filter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

 <!--
  该过滤器负责实现HttpServletRequest请求的包裹,比如允许开发者通过HttpServletRequest 的
  getRemoteUser()方法获得SSO登录用户的登录名,可选配置。
 -->
 <filter>
  <filter-name>CASHttpServletRequest WrapperFilter</filter-name>
  <filter-class>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>CASHttpServletRequest WrapperFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <!--
  为每一个线程创建资源副本
 -->
 <filter>
  <filter-name>CASAssertion Thread LocalFilter</filter-name>
  <filter-class>org.jasig.cas.client.util.AssertionThreadLocalFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>CASAssertion Thread LocalFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <!--
  自动根据单点登录的结果设置本系统的用户信息,可以从cas中获取登录用户的登录账户,通过此账户在本系统获取登录用户的相关信息
 -->
 <filter>
  <display-name>AutoSetUserAdapterFilterImp</display-name>
  <filter-name>AutoSetUserAdapterFilterImp</filter-name>
  <filter-class>com.common.view.filter.AutoSetUserAdapterFilterImp</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>AutoSetUserAdapterFilterImp</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>


三 cas配置LDAP验证机制
1. 在cas server端\cas-server-webapp-3_4_8_war.ear\cas-server-webapp-3.4.8.war\WEB-INF\lib下,加入cas-server-support-ldap-3.4.8.jar,spring-ldap-core-1.3.1.RELEASE.jar,spring-ldap-core-tiger-1.3.1.RELEASE.jar三个jar包
2.修改\cas-server-webapp-3_4_8_war.ear\cas-server-webapp-3.4.8.war\WEB-INF\deployerConfigContext.xml.注意其中修改内容需和实际部署的环境保持一致,如:请求地址,用户名,密码,以及LDAP中的node结构等。
A. 增加
<bean id="contextSource"class="org.springframework.ldap.core.support.LdapContextSource">
<property name="pooled" value="true"/>
<property name="urls">
<list>
<value>ldap://10.48.1.140:389/</value>
</list>
</property>
<property name="userDn"value="cn=root"/>
<property name="password" value="chinasofti"/>
<propertyname="baseEnvironmentPropertie
s">
<map>
<entry key="java.naming.security.authentication"value="simple" />
</map>
</property>
</bean>
B. 将
<beanclass="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswo
rdAuthenticationHandler"/>
修改为:
<beanclass="org.jasig.cas.adaptors.ldap.FastBindLdapAuthenticati
onHandler">
<property name="filter"value="uid=%u,cn=users,DC=HNZY,DC=COM" />
<property name="contextSource" ref="contextSource"/>
</bean>