cas复杂问题

我按照以下步骤做了


1. 生成密钥对

keytool -genkey -alias tomcat-server -keyalg RSA -keypass changeit -storepass changeit -keystore server.keystore  

2 将服务器证书导出为证书文件:

keytool -export -alias tomcat-server -storepass changeit -file server.cer -keystore server.keystore  
 输入密码(changeit):

Keytool返回下列消息:

Certificate stored in file <server.cer>  

 


3 用keytool在所选的keystore文件中创建客户端证书:

keytool -genkey -alias tomcat-client -keyalg RSA -keypass changeit -storepass changeit -keystore client.keystore  

4 将新客户端证书从keystore导出到证书文件:

keytool -export -alias tomcat-client -storepass changeit -file client.cer -keystore client.keystore  

输入keystore密码(changeit)。Keytool将返回该消息:

Certificate stored in file <client.cer>  


5 将上述步骤所得到的tomcat根目录下server.cer以及client.cer证书文件导入到cacerts 文件中,
cacerts文件默认生成在tomcat根目录下

keytool -import -trustcacerts -alias server -file server.cer -keystore cacerts -storepass changeit  

keytool -import -trustcacerts -alias client -file client.cer -keystore cacerts -storepass changeit  

6在tomcat根目录下找到cacerts文件,拷贝到<JAVA_HOME>\jre\lib\security文件下


从下载得cas-server3最新版本中找到target文件下面得cas.war,拷贝到<TOMCAT_HOME>/webapp目录下
,修改<TOMCAT_HOME>/conf下面得server.xml文件,添加如下:

<Connector port="8443" maxHttpHeaderSize="8192"
  maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
  enableLookups="false" disableUploadTimeout="true"
  acceptCount="100" scheme="https" secure="true"
  clientAuth="false" sslProtocol="TLS" keystoreFile="/server.keystore" keystorePass="changeit"/>
    
   
  7 CAS默认设置为只要用户名和密码相同,即可进行登录,这在现实使用中是不允许的。我们修改为使用MySQL的test数据库中的app_user表作为用户数据源。首先,我们在test库中创建一个表:
CREATE TABLE `app_user` (
  `username` varchar(30) NOT NULL default '',
  `password` varchar(45) NOT NULL default '',
  PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
并添加如下用户:
INSERT INTO `app_user` (`username`,`password`) VALUES  
 ('dianne','emu'),
 ('marissa','koala'),
 ('peter','opal'),
 ('scott','wombat');
用编辑器打开%CATALINA_HOME%/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 app_user where username=?" />
  <property name="dataSource" ref="dataSource" />
  </bean>
并添加一个bean:
  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
  <property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
  <property name="url"><value>jdbc:mysql://localhost:3306/test</value></property>
  <property name="username"><value>test</value></property>
  <property name="password"><value>test</value></property>
  </bean>
拷贝cas-server-jdbc-3.0.5-rc2.jar和mysql-connector-java-3.1.12-bin.jar到%CATALINA_HOME%/webapps/cas/WEB-INF/lib下。

   

8启动startup.bat,运行tomcat之后,新打开得浏览器中输入:https://localhost:8443即可看到安全连接对话框,选择之后可以看到正常运行得tomcat!




我启动了startup.bat 可是在控制台下很多异常,异常如下









org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'centralAuthenticationService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'authenticationManager' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationManager' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Cannot create inner bean 'org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler#127a6bc' of type [org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler] while setting bean property 'authenticationHandlers' with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler#127a6bc' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource' is defined
Caused by:  
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationManager' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Cannot create inner bean 'org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler#127a6bc' of type [org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler] while setting bean property 'authenticationHandlers' with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler#127a6bc' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource' is defined
Caused by:  
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler#127a6bc' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource' is defined
Caused by:  

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource' is defined


解答:

如果大家都是按照楼主的步骤来做,是没问题的。

大家出的问题其实就在一个地方,就是放错了问题。。

请注意下面这句话

并添加一个bean:
  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
  <property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
  <property name="url"><value>jdbc:mysql://localhost:3306/test</value></property>
  <property name="username"><value>test</value></property>
  <property name="password"><value>test</value></property>
  </bean>


这个并不是直接放在<list>中,而是放在<list>之外的,

部分配置显示如下,按照这样就不会有错了:
<bean id="authenticationManager"
class="org.jasig.cas.authentication.AuthenticationManagerImpl">

<property name="credentialsToPrincipalResolvers">
<list>

<bean
class="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver" />

<bean
class="org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver" />
</list>
</property>


<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" />

<!--
<bean
class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" />
-->
<bean class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">
<property name="sql" value="select password from app_user where username=?" />
<property name="dataSource" ref="dataSource"/>
</bean>
</list>
</property>
</bean>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
<property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
<property name="url"><value>jdbc:mysql://localhost:3306/test</value></property>
<property name="username"><value>root</value></property>
<property name="password"><value>123456</value></property>
</bean>

你可能感兴趣的:(tomcat,bean,exception,Class,reference,nested)