• sso demo mysql ( cas )


    基本配置 参考之前得随笔  http://www.cnblogs.com/rocky-fang/p/5354947.html

    1. tomcat-cas 修改配置

      1.1 在D: estsso omcat-caswebappscasWEB-INF下 找到deployerConfigContext.xml ,修改如下:

    注释掉

        <!--
        <bean id="primaryAuthenticationHandler"
              class="org.jasig.cas.authentication.AcceptUsersAuthenticationHandler">
            <property name="users">
                <map>
                    <entry key="casuser" value="Mellon"/>
                </map>
            </property>
        </bean>
            -->

    增加

    <bean id="dataSource"
         class="com.mchange.v2.c3p0.ComboPooledDataSource"
         p:driverClass="com.mysql.jdbc.Driver"
         p:jdbcUrl="jdbc:mysql://127.0.0.1:3306/cas?useUnicode=true&amp;characterEncoding=UTF-8&amp;zeroDateTimeBehavior=convertToNull"
         p:user="root"
         p:password="root" />
     
         <!-- Define the encode method-->
         <!--<bean id="passwordEncoder" 
           class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder" autowire="byName">     
          <constructor-arg value="MD5"/> 
         </bean> -->
        <bean id="passwordEncoder"
          class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder"
          c:encodingAlgorithm="MD5"
          p:characterEncoding="UTF-8" />
     
         <bean id="dbAuthHandler"
          class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler"
          p:dataSource-ref="dataSource"
          p:sql="select password from user where name=? and used=1"
         p:passwordEncoder-ref="passwordEncoder"/>

    修改

        <bean id="authenticationManager" class="org.jasig.cas.authentication.PolicyBasedAuthenticationManager">
            <constructor-arg>
                <map>
                    <!--
                       | IMPORTANT
                       | Every handler requires a unique name.
                       | If more than one instance of the same handler class is configured, you must explicitly
                       | set its name to something other than its default name (typically the simple class name).
                       -->
                    <entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" />
                    <!--改为--><entry key-ref="dbAuthHandler" value-ref="primaryPrincipalResolver" />
                    <!--注释掉<entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />-->
                </map>
            </constructor-arg>

      1.2 创建数据库 建表 插入数据

    CREATE DATABASE /*!32312 IF NOT EXISTS*/`cas` /*!40100 DEFAULT CHARACTER SET gbk */;
    
    USE `cas`;
    
    /*Table structure for table `user` */
    
    DROP TABLE IF EXISTS `user`;
    
    CREATE TABLE `user` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `name` varchar(255) NOT NULL,
      `password` varchar(255) NOT NULL,
      `used` tinyint(2) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=gbk;
    
    /*Data for the table `user` */
    
    insert  into `user`(`id`,`name`,`password`,`used`) values (1,'casuser','9414f9301cdb492b4dcd83f8c711d8bb',1);

     1.3 加入jar包

    2. 测试

    访问 https://demo.cdv.com:8443/cas/login

    使用 casuser + Mellon 登录

    成功, 此时验证是从数据库查询的密码比较而来。

  • 相关阅读:
    用List绑定GridView的简单辅助类
    宋忠玲(帮读者名字作诗)
    [转帖]每天看一遍,释怀所有难过
    30岁,我们怎么赢?
    柴门远望
    创业,不要被那些成功人士所忽悠
    一只海燕飞过来
    成功者都在用的“成功咒语”
    诗歌复兴
    游熊猫基地有感
  • 原文地址:https://www.cnblogs.com/rocky-fang/p/5957286.html
Copyright © 2020-2023  润新知