上一篇:http://my.oschina.net/u/657390/blog/651499 html
官方文檔:http://jasig.github.io/cas/4.2.x/installation/Database-Authentication.html java
在cas-4.2.0\cas-server-support-jdbc目錄下找到git
QueryAndEncodeDatabaseAuthenticationHandler.javagithub
將@Component("queryAndEncodeDatabaseAuthenticationHandler")註釋掉web
由於目前沒有用到這個功能,不註釋掉在後續啓動tomcat時會報錯sql
在cas-4.2.0\cas-server-support-jdbc目錄下打開命令提示符界面輸入apache
gradle assembletomcat
獲得cas-server-support-jdbc-4.2.0.jaroracle
將cas-server-support-jdbc-4.2.0.jar和oracle驅動拷貝到apache-tomcat-7.0.68\webapps\cas\WEB-INF\libapp
僅供測試用
DROP TABLE "PLATFORM"."P_USER"; CREATE TABLE "PLATFORM"."P_USER" ( "USERNAME" VARCHAR2(255 BYTE) NULL , "PASSWORD" VARCHAR2(255 BYTE) NULL ) LOGGING NOCOMPRESS NOCACHE ; -- ---------------------------- -- Records of P_USER -- ---------------------------- INSERT INTO "PLATFORM"."P_USER" VALUES ('123', '111');
按照官方文檔便可
在deployerConfigContext.xml裏添加
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" p:driverClass="${database.driverClass}" p:jdbcUrl="${database.url}" p:user="${database.user}" p:password="${database.password}" p:initialPoolSize="${database.pool.minSize}" p:minPoolSize="${database.pool.minSize}" p:maxPoolSize="${database.pool.maxSize}" p:maxIdleTimeExcessConnections="${database.pool.maxIdleTime}" p:checkoutTimeout="${database.pool.maxWait}" p:acquireIncrement="${database.pool.acquireIncrement}" p:acquireRetryAttempts="${database.pool.acquireRetryAttempts}" p:acquireRetryDelay="${database.pool.acquireRetryDelay}" p:idleConnectionTestPeriod="${database.pool.idleConnectionTestPeriod}" p:preferredTestQuery="${database.pool.connectionHealthQuery}" />
<alias name="queryDatabaseAuthenticationHandler" alias="primaryAuthenticationHandler" /> <alias name="dataSource" alias="queryDatabaseDataSource" />
註釋掉
<alias name="acceptUsersAuthenticationHandler" alias="primaryAuthenticationHandler" />
在cas.properties裏添加
# == Basic database connection pool configuration == database.driverClass=org.postgresql.Driver database.url=jdbc:postgresql://database.example.com/cas?ssl=true database.user=somebody database.password=meaningless database.pool.minSize=6 database.pool.maxSize=18 # Maximum amount of time to wait in ms for a connection to become # available when the pool is exhausted database.pool.maxWait=10000 # Amount of time in seconds after which idle connections # in excess of minimum size are pruned. database.pool.maxIdleTime=120 # Number of connections to obtain on pool exhaustion condition. # The maximum pool size is always respected when acquiring # new connections. database.pool.acquireIncrement=6 # == Connection testing settings == # Period in s at which a health query will be issued on idle # connections to determine connection liveliness. database.pool.idleConnectionTestPeriod=30 # Query executed periodically to test health database.pool.connectionHealthQuery=select 1 # == Database recovery settings == # Number of times to retry acquiring a _new_ connection # when an error is encountered during acquisition. database.pool.acquireRetryAttempts=5 # Amount of time in ms to wait between successive aquire retry attempts. database.pool.acquireRetryDelay=2000 cas.jdbc.authn.query.sql=SELECT u.PASSWORD password FROM P_USER u WHERE u.USERNAME=?
啓動tomcat
輸入用戶名,錯誤的密碼
輸入用戶名,正確的密碼