温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CAS4.0连接mysql数据库的详细步骤

发布时间:2020-05-09 11:39:59 来源:亿速云 阅读:595 作者:三月 栏目:数据库

本文主要给大家介绍CAS4.0连接mysql数据库的详细步骤,文章内容都是笔者用心摘选和编辑的,具有一定的针对性,对大家的参考意义还是比较大的,下面跟笔者一起了解下CAS4.0连接mysql数据库的详细步骤吧。

步骤如下

一:

在cas-4.0.0\cas-server-webapp\pom.xml中添加依赖后(如下方所示),打开cmd在cas-4.0.0\cas-server-webapp文件夹下运行mvn clean package,然后将cas-4.0.0\cas-server-webapp\target下的cas.war包部署至tomcat

Xml代码  CAS4.0连接mysql数据库的详细步骤

  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数据库的详细步骤

二:

本地创建数据库,并新建表 cas_user,创建语句如下载 

Sql代码  CAS4.0连接mysql数据库的详细步骤

  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;   

三:

配置数据库相关文件,在tomcat-for-cas\webapps\cas\WEB-INF\deployerConfigContext.xml中配置对应的datasource,数据库地址,用户名,密码,以及查询用户的sql。需要注意的是,如果是自己建的表,要把相应的字段名,数据库名替换掉,以及,不要忘记注释掉默认用户名密码的配置(casuser/Mellon)。下载以下配置可以全拷贝

Xml代码  CAS4.0连接mysql数据库的详细步骤

  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而且是小写否则会导致取不到用户的其它信息,value对应数据库用户名字段,系统会自己匹配 -->  

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

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

  206.    </map>  

  207.   </property>  

  208.   <property name="resultAttributeMapping">  

  209.    <map>  

  210.        <!-- key为对应的数据库字段名称,value为提供给客户端获取的属性名字,系统会自动填充值 -->  

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

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

  213.    </map>  

  214.   </property>  

  215.  </bean>   

  216. </beans>  

看完以上关于CAS4.0连接mysql数据库的详细步骤,很多读者朋友肯定多少有一定的了解,如需获取更多的行业知识信息 ,可以持续关注我们的行业资讯栏目的。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI