CAS4.0連接mysql數(shù)據(jù)庫的詳細(xì)步驟

本文主要給大家介紹CAS4.0連接MySQL數(shù)據(jù)庫的詳細(xì)步驟,文章內(nèi)容都是筆者用心摘選和編輯的,具有一定的針對(duì)性,對(duì)大家的參考意義還是比較大的,下面跟筆者一起了解下CAS4.0連接mysql數(shù)據(jù)庫的詳細(xì)步驟吧。

創(chuàng)新互聯(lián)公司專注于企業(yè)全網(wǎng)營銷推廣、網(wǎng)站重做改版、白朗網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5建站、商城開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為白朗等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

步驟如下

一:

在cas-4.0.0\cas-server-webapp\pom.xml中添加依賴后(如下方所示),打開cmd在cas-4.0.0\cas-server-webapp文件夾下運(yùn)行mvn clean package,然后將cas-4.0.0\cas-server-webapp\target下的cas.war包部署至tomcat

Xml代碼  CAS4.0連接mysql數(shù)據(jù)庫的詳細(xì)步驟

  1. <dependency>  

  2.     <groupId>org.jasig.cas</groupId>  

  3.     <artifactId>cas-server-support-jdbc</artifactId>  

  4.     <version>${project.version}</version>  

  5.     <type>jar</type>  

  6. </dependency>  

  7.   

  8. <!-- https://mvnrepository.com/artifact/commons-dbcp/commons-dbcp -->  

  9. <dependency>  

  10.     <groupId>commons-dbcp</groupId>  

  11.     <artifactId>commons-dbcp</artifactId>  

  12.     <version>1.4</version>  

  13. </dependency>  

  14.   

  15. <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->  

  16. <dependency>  

  17.     <groupId>mysql</groupId>  

  18.     <artifactId>mysql-connector-java</artifactId>  

  19.     <version>5.1.6</version>  

  20. </dependency>  

 CAS4.0連接mysql數(shù)據(jù)庫的詳細(xì)步驟

二:

本地創(chuàng)建數(shù)據(jù)庫,并新建表 cas_user,創(chuàng)建語句如下載 

Sql代碼  CAS4.0連接mysql數(shù)據(jù)庫的詳細(xì)步驟

  1. create table cas_user (  

  2.     id bigint not null auto_increment,  

  3.     email varchar(255),  

  4.     username varchar(255) not null unique,  

  5.     name varchar(255),  

  6.     password varchar(255),  

  7.     primary key (id)  

  8. ) ENGINE=InnoDB;   

三:

配置數(shù)據(jù)庫相關(guān)文件,在tomcat-for-cas\webapps\cas\WEB-INF\deployerConfigContext.xml中配置對(duì)應(yīng)的datasource,數(shù)據(jù)庫地址,用戶名,密碼,以及查詢用戶的sql。需要注意的是,如果是自己建的表,要把相應(yīng)的字段名,數(shù)據(jù)庫名替換掉,以及,不要忘記注釋掉默認(rèn)用戶名密碼的配置(casuser/Mellon)。下載以下配置可以全拷貝

Xml代碼  CAS4.0連接mysql數(shù)據(jù)庫的詳細(xì)步驟

  1. <?xml version="1.0" encoding="UTF-8"?>  

  2. <!--  

  3.     Licensed to Jasig under one or more contributor license  

  4.     agreements. See the NOTICE file distributed with this work  

  5.     for additional information regarding copyright ownership.  

  6.     Jasig licenses this file to you under the Apache License,  

  7.     Version 2.0 (the "License"); you may not use this file  

  8.     except in compliance with the License.  You may obtain a  

  9.     copy of the License at the following location:  

  10.       http://www.apache.org/licenses/LICENSE-2.0  

  11.     Unless required by applicable law or agreed to in writing,  

  12.     software distributed under the License is distributed on an  

  13.     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY  

  14.     KIND, either express or implied.  See the License for the  

  15.     specific language governing permissions and limitations  

  16.     under the License.  

  17. -->  

  18. <!--  

  19. | deployerConfigContext.xml centralizes into one file some of the declarative configuration that  

  20. | all CAS deployers will need to modify.  

  21. |  

  22. | This file declares some of the Spring-managed JavaBeans that make up a CAS deployment.    

  23. | The beans declared in this file are instantiated at context initialization time by the Spring   

  24. | ContextLoaderListener declared in web.xml.  It finds this file because this  

  25. | file is among those declared in the context parameter "contextConfigLocation".  

  26. |  

  27. | By far the most common change you will need to make in this file is to change the last bean  

  28. | declaration to replace the default authentication handler with  

  29. | one implementing your approach for authenticating usernames and passwords.  

  30. +-->  

  31. <beans xmlns="http://www.springframework.org/schema/beans"  

  32.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  

  33.        xmlns:p="http://www.springframework.org/schema/p"  

  34.        xmlns:c="http://www.springframework.org/schema/c"  

  35.        xmlns:tx="http://www.springframework.org/schema/tx"  

  36.        xmlns:util="http://www.springframework.org/schema/util"  

  37.        xmlns:sec="http://www.springframework.org/schema/security"  

  38.        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd  

  39.        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd  

  40.        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd  

  41.        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">  

  42.     <!--  

  43.        | The authentication manager defines security policy for authentication by specifying at a minimum  

  44.        | the authentication handlers that will be used to authenticate credential. While the AuthenticationManager  

  45.        | interface supports plugging in another implementation, the default PolicyBasedAuthenticationManager should  

  46.        | be sufficient in most cases.  

  47.        +-->  下載

  48.     <bean id="authenticationManager" class="org.jasig.cas.authentication.PolicyBasedAuthenticationManager">  

  49.         <constructor-arg>  

  50.             <map>  

  51.                 <!--  

  52.                    | IMPORTANT  

  53.                    | Every handler requires a unique name.  

  54.                    | If more than one instance of the same handler class is configured, you must explicitly  

  55.                    | set its name to something other than its default name (typically the simple class name).  

  56.                      

  57.                    -->  

  58.                     <entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" />  

  59.                  <entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />  

  60.             </map>  

  61.         </constructor-arg>  

  62.         <!-- Uncomment the metadata populator to allow clearpass to capture and cache the password  

  63.              This switch effectively will turn on clearpass.  

  64.         <property name="authenticationMetaDataPopulators">  

  65.            <util:list>  

  66.               <bean class="org.jasig.cas.extension.clearpass.CacheCredentialsMetaDataPopulator"  

  67.                     c:credentialCache-ref="encryptedMap" />  

  68.            </util:list>  

  69.         </property>  

  70.         -->  

  71.         <!--  

  72.            | Defines the security policy around authentication. Some alternative policies that ship with CAS:  

  73.            |  

  74.            | * NotPreventedAuthenticationPolicy - all credential must either pass or fail authentication  

  75.            | * AllAuthenticationPolicy - all presented credential must be authenticated successfully  

  76.            | * RequiredHandlerAuthenticationPolicy - specifies a handler that must authenticate its credential to pass  

  77.            -->  

  78.         <property name="authenticationPolicy">  

  79.             <bean class="org.jasig.cas.authentication.AnyAuthenticationPolicy" />  

  80.         </property>  

  81.     </bean>  

  82.     <!-- Required for proxy ticket mechanism. -->  

  83.     <bean id="proxyAuthenticationHandler"  

  84.           class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"  

  85.           p:httpClient-ref="httpClient" p:requireSecure="true" />  

  86.     <!--  

  87.        | TODO: Replace this component with one suitable for your enviroment.  

  88.        |  

  89.        | This component provides authentication for the kind of credential used in your environment. In most cases  

  90.        | credential is a username/password pair that lives in a system of record like an LDAP directory.  

  91.        | The most common authentication handler beans:  

  92.        |  下載

  93.        | * org.jasig.cas.authentication.LdapAuthenticationHandler  

  94.        | * org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler  

  95.        | * org.jasig.cas.adaptors.x509.authentication.handler.support.X509CredentialsAuthenticationHandler  

  96.        | * org.jasig.cas.support.spnego.authentication.handler.support.JCIFSSpnegoAuthenticationHandler  

  97.        -->  

  98.     <bean id="primaryAuthenticationHandler"  

  99.           class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">  

  100.           <property name="dataSource" ref="dataSource"/>  

  101.           <property name="sql" value="select password from cas_user where username = ?"/>  

  102.     </bean>  

  103.   

  104.     <!-- Required for proxy ticket mechanism -->  

  105.     <bean id="proxyPrincipalResolver"  

  106.           class="org.jasig.cas.authentication.principal.BasicPrincipalResolver" />  

  107.     <!--  

  108.        | Resolves a principal from a credential using an attribute repository that is configured to resolve  

  109.        | against a deployer-specific store (e.g. LDAP).  

  110.        -->  

  111.     <bean id="primaryPrincipalResolver"  

  112.           class="org.jasig.cas.authentication.principal.PersonDirectoryPrincipalResolver" >  

  113.         <property name="attributeRepository" ref="selfAttributeRepository" />  

  114.     </bean>  

  115.   

  116.     <!--  

  117.     Bean that defines the attributes that a service may return.  This example uses the Stub/Mock version.  A real implementation  

  118.     may go against a database or LDAP server.  The id should remain "attributeRepository" though.  

  119.     +-->  

  120.     <bean id="attributeRepository" class="org.jasig.services.persondir.support.StubPersonAttributeDao"  

  121.             p:backingMap-ref="attrRepoBackingMap" />  

  122.       

  123.     <util:map id="attrRepoBackingMap">  

  124.         <entry key="uid" value="uid" />  

  125.         <entry key="eduPersonAffiliation" value="eduPersonAffiliation" />   

  126.         <entry key="groupMembership" value="groupMembership" />  

  127.     </util:map>  

  128.     <!--   

  129.     Sample, in-memory data store for the ServiceRegistry. A real implementation  

  130.     would probably want to replace this with the JPA-backed ServiceRegistry DAO  

  131.     The name of this bean should remain "serviceRegistryDao".  

  132.     +-->  

  133.     <bean id="serviceRegistryDao" class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl"  

  134.             p:registeredServices-ref="registeredServicesList" />  

  135.     <util:list id="registeredServicesList">  

  136.         <bean class="org.jasig.cas.services.RegexRegisteredService"  

  137.               p:id="0" p:name="HTTP and IMAP" p:description="Allows HTTP(S) and IMAP(S) protocols"  

  138.               p:serviceId="^(https?|imaps?)://.*" p:evaluationOrder="10000001" />  

  139.         <!--  

  140.         Use the following definition instead of the above to further restrict access  

  141.         to services within your domain (including sub domains).  

  142.         Note that example.com must be replaced with the domain you wish to permit.  

  143.         This example also demonstrates the configuration of an attribute filter  

  144.         that only allows for attributes whose length is 3.  

  145.         -->  

  146.         <!--  

  147.         <bean class="org.jasig.cas.services.RegexRegisteredService">  

  148.             <property name="id" value="1" />  

  149.             <property name="name" value="HTTP and IMAP on example.com" />  

  150.             <property name="description" value="Allows HTTP(S) and IMAP(S) protocols on example.com" />  

  151.             <property name="serviceId" value="^(https?|imaps?)://([A-Za-z0-9_-]+\.)*example\.com/.*" />  

  152.             <property name="evaluationOrder" value="0" />  

  153.             <property name="attributeFilter">  

  154.               <bean class="org.jasig.cas.services.support.RegisteredServiceRegexAttributeFilter" c:regex="^\w{3}$" />   

  155.             </property>  

  156.         </bean>  

  157.         -->  

  158.     </util:list>  

  159.       

  160.     <bean id="auditTrailManager" class="com.github.inspektr.audit.support.Slf4jLoggingAuditTrailManager" />  

  161.       

  162.     <bean id="healthCheckMonitor" class="org.jasig.cas.monitor.HealthCheckMonitor" p:monitors-ref="monitorsList" />  

  163.     下載

  164.     <util:list id="monitorsList">  

  165.       <bean class="org.jasig.cas.monitor.MemoryMonitor" p:freeMemoryWarnThreshold="10" />  

  166.       <!--  

  167.         NOTE  

  168.         The following ticket registries support SessionMonitor:  

  169.           * DefaultTicketRegistry  

  170.           * JpaTicketRegistry  

  171.         Remove this monitor if you use an unsupported registry.  

  172.       -->  

  173.       <bean class="org.jasig.cas.monitor.SessionMonitor"  

  174.           p:ticketRegistry-ref="ticketRegistry"  

  175.           p:serviceTicketCountWarnThreshold="5000"  

  176.           p:sessionCountWarnThreshold="100000" />  

  177.     </util:list>  

  178.       

  179.     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">  

  180.                    <property name="driverClassName">  

  181.                            <value>com.mysql.jdbc.Driver</value>  

  182.                    </property>  

  183.                    <property name="url">  

  184.                             <value>jdbc:mysql://localhost:3306/test</value>  

  185.                    </property>  

  186.                    <property name="username">  

  187.                             <value>root</value>  

  188.                    </property>  

  189.                    <property name="password">  

  190.                             <value>123456</value>  

  191.                    </property>  

  192.     </bean>  

  193.       

  194.     <bean id="selfAttributeRepository"  

  195.   class="org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao">  

  196.   <constructor-arg index="0" ref="dataSource" />  

  197.   <constructor-arg index="1"  

  198.    value="select username,password from cas_user where {0}" />  

  199.     

  200.   <!-- 組裝sql用的查詢條件屬性 -->   

  201.   <property name="queryAttributeMapping">  

  202.    <map>  

  203.        <!-- key必須是uername而且是小寫否則會(huì)導(dǎo)致取不到用戶的其它信息,value對(duì)應(yīng)數(shù)據(jù)庫用戶名字段,系統(tǒng)會(huì)自己匹配 -->  

  204.     <entry key="username" value="username" />  

  205.     <entry key="password" value="password" />  

  206.    </map>  

  207.   </property>  

  208.   <property name="resultAttributeMapping">  

  209.    <map>  

  210.        <!-- key為對(duì)應(yīng)的數(shù)據(jù)庫字段名稱,value為提供給客戶端獲取的屬性名字,系統(tǒng)會(huì)自動(dòng)填充值 -->  

  211.     <entry key="username" value="username"></entry>  

  212.     <entry key="password" value="password"></entry>  

  213.    </map>  

  214.   </property>  

  215.  </bean>   

  216. </beans>  

看完以上關(guān)于CAS4.0連接mysql數(shù)據(jù)庫的詳細(xì)步驟,很多讀者朋友肯定多少有一定的了解,如需獲取更多的行業(yè)知識(shí)信息 ,可以持續(xù)關(guān)注我們的行業(yè)資訊欄目的。

網(wǎng)站標(biāo)題:CAS4.0連接mysql數(shù)據(jù)庫的詳細(xì)步驟
轉(zhuǎn)載來源:http://www.muchs.cn/article48/geechp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊、搜索引擎優(yōu)化建站公司、品牌網(wǎng)站建設(shè)軟件開發(fā)、標(biāo)簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作