在java -sig CAS中使用MySQL数据库进行身份验证

时间:2022-03-16 00:38:08

I'm trying to hook my Ja-sig CAS server (v3.5 running on Tomcat7) up to a MySQL database for user authentication. I basically have a table 'users' in the database storing username/password pairs that I want CAS to check against. However, I'm having difficulty even getting my current configuration to deploy.

我正在尝试将我的jar -sig CAS服务器(在Tomcat7上运行的v3.5)连接到MySQL数据库以进行用户身份验证。我基本上在数据库中有一个“用户”表,用于存储用户名/密码对,我想让CAS检查它们。然而,我甚至难以部署当前配置。

This is an excerpt from pom.xml as it relates to database connectivity:

这是pom的摘录。与数据库连接相关的xml:

<dependency>
   <groupId>org.jasig.cas</groupId>
   <artifactId>cas-server-support-jdbc</artifactId>
   <version>${cas.version}</version>
</dependency>

<dependency>
   <groupId>commons-dbcp</groupId>
   <artifactId>commons-dbcp</artifactId>
   <version>1.4</version>
   <scope>runtime</scope>
</dependency>

<dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
   <version>5.1.22-bin</version>
   <scope>provided</scope>
</dependency>

And here is where I try to setup the database connection in WEB-INF/deployerConfigContext.xml:

在这里,我尝试在WEB-INF/deployerConfigContext.xml中设置数据库连接:

<bean
class="org.jasig.cas.adaptors.jdbc.SearchModeSearchDatabaseAuthenticationHandler">
   <property name="tableUsers">
       <value>users</value>
   </property>
   <property name="fieldUser">
       <value>username</value>
   </property>
   <property name="fieldPassword">
       <value>password</value>
   </property>
   <property name="passwordEncoder">
       <bean
             class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder">
        <constructor-arg value="MD5" />
       </bean>
   </property>
   <property name="dataSource" ref="dataSource" />
</bean>

<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/cas_db</value>
    </property>
    <property name="username">
        <value>cas_server</value>
    </property>
    <property name="password">
        <value>pass</value>
    </property>
</bean>

It builds perfectly fine with Maven, but when I try to deploy it with Tomcat it doesn't work. I haven't been able to find anything particularly informative in any of the tomcat logs. I'm wondering if there might be a problem with 'commons-dbcp', since when I comment that out and use a simple authentication handler in deployerConfigContext.xml, I'm able to deploy.

它完全可以与Maven一起构建,但是当我尝试用Tomcat部署它时,它就不起作用了。我没有在tomcat日志中找到任何特别有用的内容。我想知道“common -dbcp”是否存在问题,因为当我注释掉它并在deployerConfigContext中使用一个简单的身份验证处理程序时。xml,我可以部署。

There seems to be little/poor documentation of this from my current web research. If anyone has any good resources they could recommend as well, it would be greatly appreciated.

在我目前的网络研究中,似乎很少有关于这方面的文档。如果任何人有任何好的资源,他们也可以推荐,将非常感谢。

2 个解决方案

#1


3  

I finally found a trace of errors in the tomcat log localhost.YYYY-MM-DD.log. As it turns out, I needed to add commons-pool:

我终于在tomcat log localhost.yyyyyyy - mm - dd .log中找到了错误的踪迹。事实证明,我需要增加公共资源:

<dependency>
   <groupId>commons-pool</groupId>
   <artifactId>commons-pool</artifactId>
   <version>1.6</version>
   <scope>provided</scope>
</dependency>

which commons-dbcp is dependent upon. Installing this with Maven did away with the missing class exception I was getting.

这是常见的dbcp所依赖的。在Maven中安装这个组件,消除了我所获得的丢失的类异常。

My next problem was that I had mistakenly defined my datasource bean in the list of authenticationHandlers in deployerConfigContext.xml, which led to a type conversion exception. Moving the bean out of the list tag did the trick.

我的下一个问题是,我在deployerConfigContext中的authenticationHandlers列表中错误地定义了数据源bean。这导致了类型转换异常。将bean从列表标记中移出就可以了。

#2


0  

On one of the official guides for CAS + JDBC Authentication (https://wiki.jasig.org/display/CASUM/Using+JDBC+for+Authentication), they comment on that:

在CAS +JDBC认证的官方指南(https://wiki.jasig.org/display/CASUM/Using+JDBC+for+Authentication)中,他们对此作出了评论:

Note: It is recommended commons-dbcp 1.2.1 is used with MySQL instead of the newer version. I found that new version (1.2.2) will cause a Socket write error in MySQL, after your CAS is idle for more that 8 hours, which is the time that MySQL will clean up all idle connections.

注意:建议将common -dbcp 1.2.1用于MySQL而不是更新的版本。我发现新的版本(1.2.2)会导致MySQL中的套接字写入错误,当您的CAS空闲时间超过8小时后,MySQL会清理所有的空闲连接。

Your problem might be related to the version of the commons-dbcp. In my case, I have a configuration similar to yours with the difference on the commons-dbcp version, I'm using 1.4 (no problems)

您的问题可能与common -dbcp的版本有关。在我的示例中,我有一个与您的配置相似的配置,但在common -dbcp版本上有不同之处,我使用的是1.4(没有问题)

#1


3  

I finally found a trace of errors in the tomcat log localhost.YYYY-MM-DD.log. As it turns out, I needed to add commons-pool:

我终于在tomcat log localhost.yyyyyyy - mm - dd .log中找到了错误的踪迹。事实证明,我需要增加公共资源:

<dependency>
   <groupId>commons-pool</groupId>
   <artifactId>commons-pool</artifactId>
   <version>1.6</version>
   <scope>provided</scope>
</dependency>

which commons-dbcp is dependent upon. Installing this with Maven did away with the missing class exception I was getting.

这是常见的dbcp所依赖的。在Maven中安装这个组件,消除了我所获得的丢失的类异常。

My next problem was that I had mistakenly defined my datasource bean in the list of authenticationHandlers in deployerConfigContext.xml, which led to a type conversion exception. Moving the bean out of the list tag did the trick.

我的下一个问题是,我在deployerConfigContext中的authenticationHandlers列表中错误地定义了数据源bean。这导致了类型转换异常。将bean从列表标记中移出就可以了。

#2


0  

On one of the official guides for CAS + JDBC Authentication (https://wiki.jasig.org/display/CASUM/Using+JDBC+for+Authentication), they comment on that:

在CAS +JDBC认证的官方指南(https://wiki.jasig.org/display/CASUM/Using+JDBC+for+Authentication)中,他们对此作出了评论:

Note: It is recommended commons-dbcp 1.2.1 is used with MySQL instead of the newer version. I found that new version (1.2.2) will cause a Socket write error in MySQL, after your CAS is idle for more that 8 hours, which is the time that MySQL will clean up all idle connections.

注意:建议将common -dbcp 1.2.1用于MySQL而不是更新的版本。我发现新的版本(1.2.2)会导致MySQL中的套接字写入错误,当您的CAS空闲时间超过8小时后,MySQL会清理所有的空闲连接。

Your problem might be related to the version of the commons-dbcp. In my case, I have a configuration similar to yours with the difference on the commons-dbcp version, I'm using 1.4 (no problems)

您的问题可能与common -dbcp的版本有关。在我的示例中,我有一个与您的配置相似的配置,但在common -dbcp版本上有不同之处,我使用的是1.4(没有问题)