`

CAS单点登录学习笔记五之CAS服务器数据源

阅读更多

CAS服务器数据源的配置真实验证,在前面的示例中,使用的用户名和密码都是自己捏造出来的,而在实际的应用系统中,都需要从应用数据库中读取用户名和密码,下面就进行自定义CAS服务器的数据源的实验

 

1、创建数据库表结构user_info 用户表

2、cas服务器配置

打开cas-serverapache-tomcat-6.0.36\webapps\cas\WEB-INF\deployerConfigContext.xml文件,找到其中的authenticationManagerauthenticationHandlers属性配置。默认的配置是这样的

 

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

 

 

 

这里配置了一个SimpleTestUsernamePasswordAuthenticationHandler,这个用户名密码的认证器在认证用户时,只要用户名和密码保持一致,就认为是有效的用户,这也是为什么在前面的测试中,只要输入的用户名和密码一致就能登录的原因。在实际的生产环境中,应该将该认证器取替换为

 

<bean
					class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">
					<property name="dataSource" ref="casDataSource" />
					<property name="sql"
						value="select passwd from mall_user_info where lower(user_name) = lower(?)" />
					<property name="passwordEncoder" ref="myPasswordEncoder" />
				</bean>

 

 

 

 

<bean id="casDataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName">
			<value>oracle.jdbc.driver.OracleDriver</value>
		</property>
		<property name="url">
			<value>jdbc:oracle:thin:@127.0.0.1:1521:orcl</value>
		</property>
		<property name="username">
			<value>system</value>
		</property>
		<property name="password">
			<value>password</value>
		</property>
	</bean>

	<bean id="myPasswordEncoder" class="org.jasig.cas.authentication.handler.MyPasswordEncoder" />
	<bean id="MD5PasswordEncoder"
		class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder">
		<constructor-arg index="0">
			<value>MD5</value>
		</constructor-arg>
	</bean>

    这样CAS Server服务器会采用QueryDatabaseAuthenticationHandler方式认证,该认证器位于cas-server-support-jdbc包中,需要在项目中增加相应的jar包、同时我们采用了ORACLE数据库oracle10g.jar 添加两个数据相关jar包。

 

重启cas-server服务器,进入登录页面 此时用户名或密码不正确会ERRO提示凭证有误



 

输入正确数据



 

 

  • 大小: 31.1 KB
  • 大小: 13.3 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics