`
xiaolin0199
  • 浏览: 565052 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

测试CAS服务器(二)

    博客分类:
  • CAS
阅读更多

上一篇文章讲了用系统默认的simple验证方式,即用户名=密码来进行CAS的验证。

 

本文我们尝试用mysql来进行验证

 

1,下载cas-server-3.4.2-release.zip及mysql-connector-java-5.1.7-CodePub.zip,cas-client-2.0.11.zip三个文件

    可能有些您已经下载了,本文中最重要的是mysql-connector-java-5.1.7-CodePub.zip这个文件,它是jdbc连接mysql

    的驱动包;

 

2,copy :

 

     cas-server-3.4.2-release.zip -> modules/cas-server-support-jdbc-3.4.2.jar

     mysql-connector-java-5.1.7-CodePub.zip -> mysql-connector-java-5.1.7-bin.jar

     cas-client-2.0.11.zip -> java/lib/casclient.jar

 

三个文件到tomcat_path/webapps/cas/WEB-INF/lib中即可;

 

3,修改配置文件   tomcat_path/webapps/cas/WEB-INF中deployerConfigContext.xml文件

 

  首先注释以下语句:

       <bean
              class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" />

 

  更改为:

                <bean class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">
                         <property name="sql" value="select password from auth_user where username=?" />
                         <property name="dataSource" ref="dataSource" />
                </bean>

 

再在外围加上:

               <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                      <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
                      <property name="url" value="jdbc:mysql://localhost/zhidao"></property>
                      <property name="username" value="root"></property>
                      <property name="password" value="******"></property> 
                 </bean>

 

我的示例:

 

		<property name="authenticationHandlers">
			<list>
				<!--
					| This is the authentication handler that authenticates services by means of callback via SSL, thereby validating
					| a server side SSL certificate.
					+-->
				<bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"
					p:httpClient-ref="httpClient" />
				<!--
					| This is the authentication handler declaration that every CAS deployer will need to change before deploying CAS 
					| into production.  The default SimpleTestUsernamePasswordAuthenticationHandler authenticates UsernamePasswordCredentials
					| where the username equals the password.  You will need to replace this with an AuthenticationHandler that implements your
					| local authentication strategy.  You might accomplish this by coding a new such handler and declaring
					| edu.someschool.its.cas.MySpecialHandler here, or you might use one of the handlers provided in the adaptors modules.
					+-->
                          <!--        <bean      
class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler"
 />   +-->
				<bean class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">
     					<property name="sql" value="select password from auth_user where username=?" />
     					<property name="dataSource" ref="dataSource" />
				</bean>
			</list>
		</property>
	</bean>

				<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  					<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
  					<property name="url" value="jdbc:mysql://localhost/zhidao"></property>
  					<property name="username" value="root"></property>
  					<property name="password" value="******"></property>  
   				 </bean>
 

   最后重启tomcat服务器,这时候验证就去你指定的mysql数据库了.

 

-------------------------------------------------------------------------------------------------------------------------

 

以上做验证的时候密码必须在数据库中是原文存储的才可以正常,所以您的密码是以某种加密方式存储的还需要要加入规则

以下实现了md5加密;

 

1,加入password规则

                 <bean class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">
                    <property name="dataSource" ref="dataSource"  />
                    <property name="sql" value="select password from auth_user where username = ?"  />
                    <property  name="passwordEncoder"  ref="myPasswordEncoder"  />
                </bean>

     上面这段,sql定义了一个查询语句,用来判断用户名,密码是否存 在,myPasswordEncoder是我自定义的一个密码的加密类,实现了passwordEncoder接口及其 encode() 方法。

 

2,配置PasswordEncoder;

 

<bean id="myPasswordEncoder" class="org.jasig.cas.authentication.handler.MyPasswordEncoder"/>
 

3,MyPasswordEncoder
给出源 码,大家自己编译成class吧,然后把MyPasswordEncoder.class放到
Tomcat_path\webapps\cas\WEB-INF\lib\cas-server-core-3.4.2.jar中相应的包下,jar包用winrar打 开后,直接把class拖到相应目录下即可

 

package org.jasig.cas.authentication.handler;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.util.StringUtils;

// Referenced classes of package org.jasig.cas.authentication.handler:
//            PasswordEncoder

public final class MyPasswordEncoder
    implements PasswordEncoder
{

    public MyPasswordEncoder(){};

    public String encode(String password)
    {
        char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'a', 'b', 'c', 'd', 'e', 'f'};
        try {
            byte[] strTemp = password.getBytes();
            MessageDigest mdTemp = MessageDigest.getInstance("MD5");
            mdTemp.update(strTemp);
            byte[] md = mdTemp.digest();
            int j = md.length;
            char str[] = new char[j * 2];
            int k = 0;
            for (int i = 0; i < j; i++) {
                byte byte0 = md[i];
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            return new String(str);
        } catch (Exception e) {
            return null;
        }
    }

    public final static String MD5(String s) {
        char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'a', 'b', 'c', 'd', 'e', 'f'};
        try {
            byte[] strTemp = s.getBytes();
            MessageDigest mdTemp = MessageDigest.getInstance("MD5");
            mdTemp.update(strTemp);
            byte[] md = mdTemp.digest();
            int j = md.length;
            char str[] = new char[j * 2];
            int k = 0;
            for (int i = 0; i < j; i++) {
                byte byte0 = md[i];
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            return new String(str);
        } catch (Exception e) {
            return null;
        }
    }

    public static Date getDateByString(String dateString) {
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            return dateFormat.parse(dateString);
        } catch (Exception e) {
            return null;
        }
    }
    
    public static String getDateString(Date date) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        return dateFormat.format(date);
    }
    
}
 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    cas-pac4j-oauth-demo:CAS服务器演示以测试身份验证委派

    这是什么项目已创建此cas-pac4j-oauth-demo项目以测试CAS服务器中的身份验证委派。构建和测试构建项目: cd cas-pac4j-oauth-demomvn clean package 并将构建的WAR( cas.war )作为JAR(嵌入式Tomcat)运行:它将在...

    gocas:Golang 中的极简 CAS 服务器

    可用的身份验证器是: 虚拟(用户名应等于密码,用于测试目的) LDAP 半径此外,还支持以下服务器协议: CAS(废话!) OAuth2配置可以在gocas.yaml.example 中找到详尽的配置示例。 配置文件的位置可以通过开关-...

    可以直接运行的cas

    可以直接导入到idea直接运行的cas服务器后端,经过各种修改测试啊

    cas实现单点登录服务端及客户端

    cas实现单点登录服务端及客户端,压缩包内提供三个工程,一个cas服务器,两个测试客户端,可同时部署到一个tomcat下,或者分开部署。端口号默认使用的8000

    jason-sso:Jason CAS服务器

    CAS服务器 快速启动和测试 执行sql语句 要快速开始,请构建项目: git clone https://github.com/jasonsoso/jason-sso.git cd jason-sso mvn clean install 要使用码头启动该应用程序: mvn compile jetty:run ...

    CAS单点登录配置步骤说明书

    1. 配置SSL a) 生成证书 b) 将证书导出为证书文件 c) 将证书文件导入到java证书库cacerts中 d) 修改&lt;TOMCAT_HOME&gt;/...2. 部署CAS服务器 3. 修改CAS登录的用户库 4. 测试是否配置成功 5. 配置过程中可能会出现的错误

    配置好的CasServer

    自己搭建的本地CasServer单点登录服务器, 感兴趣的小伙伴可以到 https://gitee.com/XiaoMingLoveJava/CasDemo 这里下载配套CasClient测试(内附使用方法)

    JA-SIG(CAS)学习笔记

    STEP 1,搭建Java Web服务器环境 安装 JDK + Tomcat 6.0.14 , HTTP端口8080 , HTTPS端口8443 JAVA_HOME = D:\Java\jdk1.6.0_04 CATALINA_HOME = D:\Java\apache-tomcat-6.0.14 安装完毕,启动Tomcat ,在...

    django-cas-server:实施CAS协议3.0规范的Django Central Authentication Service服务器

    CAS服务器 CAS Server是实现的Django应用程序。 默认情况下,身份验证过程使用django内部用户,但您可以轻松使用任何源(请参阅auth.py文件中的“部分和auth类) 目录验证设定联盟设置新版本警告设置票证有效期设置...

    cas_validate:CAS客户端,提供单点登录,侦听单点退出,以与node.js和Connect一起使用

    CAS验证这是一个实用工具,可帮助您通过CAS服务器( )验证基于Connect或Express(可能还有其他框架,甚至根本没有)的Web服务。它允许单点登录和。换句话说,如果客户端已到CAS服务器以前记录的,该库将允许您服务...

    Cas单点登录在服务器下部署

    欢迎下载,请多指教。(*^__^*) 嘻嘻……

    cas-sample-boot-application:使用 Spring Boot 的测试应用程序

    默认为8888 本地服务器名称用于 CAS 的服务器名称。 默认为http://localhost:8888 cas.serverUrlPrefix CAS 服务器的服务器前缀。 默认为https://test.scaldingspoon.org/cas spring.profiles.active 要使用什么

    cas:Laravel 5-8的简单CAS身份验证

    该软件包提供并抽象了 (phpCAS),它是一个跨平台的开源CAS客户和服务器提供商。 如果您打算实施AD以外的SSO服务,请务必将其签出。 查看了解更多详细信息。 更新 增加了对Laravel 8.x的支持 增加了对Laravel 7.x...

    strapi-cas-example:演示通过CAS登录到trapi

    例如:stradi-cas 演示通过CAS登录Strapi 在本地运行的先决条件 Docker-运行CAS Intializr Java 11 JDK-构建和运行CAS覆盖(Gradle会自举) ... 然后,它将使用gradle来构建CAS应用程序,为CAS服务器生

    内存测试软件MemTest

    内存测试软件MemTest,适用于电脑内存测试,更重要的是测试服务器大容量内存。无需安装,双机程序即可测试内存。测试过程中cpu和内存使用率均为100%满负载运行。

    Server+2010+从入门到精通(Exchange+Server+2010+配置实战精粹)

    第四节 配置 Exchange Server 2010 CAS服务器(图解) 第五节 Exchange Server 2010向外网发送邮件的配置--(包括简单的HUB配置) 第六节发送邮件测试 第七节 配置exchange Server 2010证书 第八节 Exchange server ...

    meteor-accounts-cas:用于CAS集成的流星包

    如果此错误的details属性是userDoesNotExist,则在数据库中找不到该用户,但已通过CAS服务器对其进行了身份验证。样本settings.json文件{“ public”:{“ cas”:{“ loginUrl”:“ ”,“ logoutUrl”:“ “,...

    cas 配置client 1.0 &2.0 及proxy DEMO 说明

    在生成key的过程,"CN= www.test.com " 中的www.test.com为Server端的域名(必填)。CN要和服务器的域名相同,如果在本地测试,则使用localhost cas 配置client 1.0 &2.0 及proxy DEMO 说明

    原创CAS_SSO单点登录实例详细

    在IDP上下载和部署CAS 服务器..................................................................................... 7 七. 测试SSO............................................................................

    cas-fee-p1:高铁CAS FEE项目1 NotePro

    cas-fee-p1 第三组的HSR CAS FEE ...DESC)上进行第二次单击经过测试的浏览器:Chrome版本43,Firefox 38 改善机会: 脱机功能(仅在用户要求时本地存储和与服务器同步) 将设置保存在localStorage中(排序顺序,

Global site tag (gtag.js) - Google Analytics