配置通过数据库认证用户登录
打开webapp\WEB-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="primaryAuthenticationHandler" class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">
<property name="dataSource" ref="dataSource" />
<property name="sql" value="select password from table_users where username = ?" />
</bean>
<!-- MySQL connector -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/db_name</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value></value>
</property>
</bean>
使用jdbc的配置
首先把默认编译后生成出来的jdbc.jar(通常名称为cas-server-support-jdbc-xxxxxxxxxx.jar),从cas-server-support-jdbc\target\目录下拷贝到webapp\WEB-INF\lib目录下。
在cas-server-webapp下的pom.xml里添加以下依赖项
<dependency>
<groupId>org.jasig.cas</groupId>
<artifactId>cas-server-support-jdbc</artifactId>
<version>${project.version}</version>
</dependency>
<!--
Apache Commons DBCP
for Java 6 (use version 1.3 for Java 5 or lower)
-->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
<scope>runtime</scope>
</dependency>
<!--
MySQL Connector
-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.20</version>
</dependency>
如果不设置这些依赖项会在编译时出现以下错误:
Cannot find class [org.apache.commons.dbcp.BasicDataSource]
或者是org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]
在这里的注示描述也说了,替换它们以适应工作环境。