`

入门2

阅读更多

客户端配置

cas官方网站上面的客户端下载地址比较隐秘,没有完全公开,具体地址为

http://www.ja-sig.org/downloads/cas-clients/

下载最新的cas-client-3.1.6-release.zip

1.解压后把modules下面的包放到我们的web应用中

2.配置web.xml,注意encodingFilter要提前配置,不然会出现数据插入数据库的时候有乱码。

serverName是我们web应用的地址和端口

XML/HTML代码
  1. <context-param>  
  2.         <param-name>serverName</param-name>  
  3.   
  4.   
  5.         <param-value>192.168.1.145:81</param-value>  
  6.   
  7.     </context-param>  
  8.        
  9.        
  10.     <filter>  
  11.         <filter-name>encodingFilter</filter-name>  
  12.         <filter-class>  
  13.             org.springframework.web.filter.CharacterEncodingFilter   
  14.         </filter-class>  
  15.         <init-param>  
  16.             <param-name>encoding</param-name>  
  17.             <param-value>UTF-8</param-value>  
  18.         </init-param>  
  19.         <init-param>  
  20.             <param-name>forceEncoding</param-name>  
  21.             <param-value>true</param-value>  
  22.         </init-param>  
  23.     </filter>  
  24.        
  25.        
  26.        
  27.     <filter-mapping>  
  28.         <filter-name>encodingFilter</filter-name>  
  29.         <url-pattern>*.htm</url-pattern>  
  30.     </filter-mapping>  
  31.   
  32.     <filter-mapping>  
  33.         <filter-name>encodingFilter</filter-name>  
  34.         <url-pattern>*.ftl</url-pattern>  
  35.     </filter-mapping>  
  36.   
  37.     <filter-mapping>  
  38.         <filter-name>encodingFilter</filter-name>  
  39.         <url-pattern>*.xhtml</url-pattern>  
  40.     </filter-mapping>  
  41.     <filter-mapping>  
  42.         <filter-name>encodingFilter</filter-name>  
  43.         <url-pattern>*.html</url-pattern>  
  44.     </filter-mapping>  
  45.     <filter-mapping>  
  46.         <filter-name>encodingFilter</filter-name>  
  47.         <url-pattern>*.shtml</url-pattern>  
  48.     </filter-mapping>  
  49.   
  50.   
  51.     <filter-mapping>  
  52.         <filter-name>encodingFilter</filter-name>  
  53.         <url-pattern>*.jsp</url-pattern>  
  54.     </filter-mapping>  
  55.     <filter-mapping>  
  56.         <filter-name>encodingFilter</filter-name>  
  57.         <url-pattern>*.do</url-pattern>  
  58.     </filter-mapping>  
  59.     <filter-mapping>  
  60.         <filter-name>encodingFilter</filter-name>  
  61.         <url-pattern>*.vm</url-pattern>  
  62.     </filter-mapping>  
  63.        
  64.        
  65.        
  66.        
  67.        
  68.     <filter>  
  69.         <filter-name>CAS Single Sign Out Filter</filter-name>  
  70.         <filter-class>  
  71.             org.jasig.cas.client.session.SingleSignOutFilter   
  72.         </filter-class>  
  73.     </filter>  
  74.     <filter-mapping>  
  75.         <filter-name>CAS Single Sign Out Filter</filter-name>  
  76.         <url-pattern>/*</url-pattern>  
  77.     </filter-mapping>  
  78.     <listener>  
  79.         <listener-class>  
  80.             org.jasig.cas.client.session.SingleSignOutHttpSessionListener   
  81.         </listener-class>  
  82.     </listener>  
  83.     <filter>  
  84.         <filter-name>CAS Authentication Filter</filter-name>  
  85.         <filter-class>  
  86.             org.jasig.cas.client.authentication.AuthenticationFilter   
  87.         </filter-class>  
  88.         <init-param>  
  89.             <param-name>casServerLoginUrl</param-name>  
  90.             <param-value>http://192.168.1.100/cas/login</param-value>  
  91.         </init-param>  
  92.     </filter>  
  93.     <filter>  
  94.         <filter-name>CAS Validation Filter</filter-name>  
  95.         <filter-class>  
  96.             org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter   
  97.         </filter-class>  
  98.         <init-param>  
  99.             <param-name>casServerUrlPrefix</param-name>  
  100.             <param-value>http://192.168.1.100/cas</param-value>  
  101.         </init-param>  
  102.     </filter>  
  103.   
  104.     <filter>  
  105.         <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>  
  106.         <filter-class>  
  107.             org.jasig.cas.client.util.HttpServletRequestWrapperFilter   
  108.         </filter-class>  
  109.     </filter>  
  110.     <filter>  
  111.         <filter-name>CAS Assertion Thread Local Filter</filter-name>  
  112.         <filter-class>  
  113.             org.jasig.cas.client.util.AssertionThreadLocalFilter   
  114.         </filter-class>  
  115.     </filter>  
  116.     <filter-mapping>  
  117.         <filter-name>CAS Authentication Filter</filter-name>  
  118.         <url-pattern>/*</url-pattern>  
  119.     </filter-mapping>  
  120.     <filter-mapping>  
  121.         <filter-name>CAS Validation Filter</filter-name>  
  122.         <url-pattern>/*</url-pattern>  
  123.     </filter-mapping>  
  124.     <filter-mapping>  
  125.         <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>  
  126.         <url-pattern>/*</url-pattern>  
  127.     </filter-mapping>  
  128.     <filter-mapping>  
  129.         <filter-name>CAS Assertion Thread Local Filter</filter-name>  
  130.         <url-pattern>/*</url-pattern>  
  131.     </filter-mapping>  

 

3.导入证书,如果不用https的话,这步可以跳过,把tomcatsso.crt证书拷贝到c盘下面,在jdk的bin目录下面运行下面的语句。

 

JavaScript代码
  1. rem (注释: 清除系统中可能存在的名字为tomcatsso 的同名证书)   
  2. keytool -delete -alias tomcatsso -keystore "%JAVA_HOME%/jre/lib/security/cacerts" -storepass changeit    
  3. keytool -delete -alias tomcatsso -storepass changeit    
  4.   
  5. rem 在客户端的 JVM 里导入信任的 SERVER 的证书 ( 根据情况有可能需要管理员权限 )    
  6. keytool -import -alias tomcatsso -file "c:/tomcatsso.crt" -keystore "%java_home%/jre/lib/security/cacerts" -storepass changeit   

 

 客户端获取登录用户名和用户信息实例

Java代码
  1. HttpServletRequest request = ServletActionContext.getRequest();   
  2. AttributePrincipal principal = (AttributePrincipal)request.getUserPrincipal();   
  3. String username = principal.getName();   
  4. Long orgnId = Long.parseLong(principal.getAttributes().get("orgnId").toString());  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics