美文网首页cas
cas4.2.7数据库配置,读取用户信息

cas4.2.7数据库配置,读取用户信息

作者: sweetMemories | 来源:发表于2017-07-27 16:54 被阅读356次

    配置文件代码

    deployerConfigContext.xml

    代码

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:c="http://www.springframework.org/schema/c"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:util="http://www.springframework.org/schema/util"
           xmlns:sec="http://www.springframework.org/schema/security"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
           http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
    
        <util:map id="authenticationHandlersResolvers">
            <entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" />
            <!-- 默认配置文件用户认证方式,可屏蔽 -->
            <entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />
            <!-- 添加数据库认证 -->
            <entry key-ref="databaseAuthenticationHandler" value-ref="primaryPrincipalResolver" />
        </util:map>
    
        <util:list id="authenticationMetadataPopulators">
            <ref bean="successfulHandlerMetaDataPopulator" />
            <ref bean="rememberMeAuthenticationMetaDataPopulator" />
        </util:list>
    
        <bean id="attributeRepository" class="org.jasig.services.persondir.support.NamedStubPersonAttributeDao"
              p:backingMap-ref="attrRepoBackingMap" />
        <util:map id="attrRepoBackingMap">
            <entry key="uid" value="uid" />
            <entry key="eduPersonAffiliation" value="eduPersonAffiliation" />
            <entry key="groupMembership" value="groupMembership" />
            <entry>
                <key><value>memberOf</value></key>
                <list>
                    <value>faculty</value>
                    <value>staff</value>
                    <value>org</value>
                </list>
            </entry>
        </util:map>
    
        <alias name="acceptUsersAuthenticationHandler" alias="primaryAuthenticationHandler" />
        <alias name="personDirectoryPrincipalResolver" alias="primaryPrincipalResolver" />
    
        <!-- 配置queryDatabaseAuthenticationHandler别名 -->
        <alias name="queryDatabaseAuthenticationHandler" alias="databaseAuthenticationHandler" />
        <!-- 配置dataSource别名 -->
        <alias name="dataSource" alias="queryDatabaseDataSource" />
    
        <!--数据库连接池配置-->
        <bean id="dataSource"
              class="com.mchange.v2.c3p0.ComboPooledDataSource"
              p:driverClass="${cas.audit.database.driverClass}"
              p:jdbcUrl="${cas.audit.database.url}"
              p:user="${cas.audit.database.user}"
              p:password="${cas.audit.database.password}"
              p:initialPoolSize="${cas.audit.database.pool.minSize}"
              p:minPoolSize="${cas.audit.database.pool.minSize}"
              p:maxPoolSize="${cas.audit.database.pool.maxSize}"
              p:maxIdleTimeExcessConnections="${cas.audit.database.pool.maxIdleTime}"
              p:checkoutTimeout="${cas.audit.database.pool.maxWait}"
              p:acquireIncrement="${cas.audit.database.pool.acquireIncrement}"
              p:acquireRetryAttempts="${cas.audit.database.pool.acquireRetryAttempts}"
              p:acquireRetryDelay="${cas.audit.database.pool.acquireRetryDelay}"
              p:idleConnectionTestPeriod="${cas.audit.database.pool.idleConnectionTestPeriod}"
              p:preferredTestQuery="${cas.audit.database.pool.connectionHealthQuery}" />
    
        <alias name="defaultPasswordEncoder" alias="passwordEncoder" />
    
    
    
    
        <alias name="serviceThemeResolver" alias="themeResolver" />
    
        <alias name="jsonServiceRegistryDao" alias="serviceRegistryDao" />
        <!--<alias name="databaseServiceRegistryDao" alias="serviceRegistryDao" />-->
    
        <alias name="defaultTicketRegistry" alias="ticketRegistry" />
        
        <alias name="ticketGrantingTicketExpirationPolicy" alias="grantingTicketExpirationPolicy" />
        <alias name="multiTimeUseOrTimeoutExpirationPolicy" alias="serviceTicketExpirationPolicy" />
    
        <alias name="anyAuthenticationPolicy" alias="authenticationPolicy" />
        <alias name="acceptAnyAuthenticationPolicyFactory" alias="authenticationPolicyFactory" />
    
        <bean id="auditTrailManager"
              class="org.jasig.inspektr.audit.support.Slf4jLoggingAuditTrailManager"
              p:entrySeparator="${cas.audit.singleline.separator:|}"
              p:useSingleLine="${cas.audit.singleline:false}"/>
    
        <alias name="neverThrottle" alias="authenticationThrottle" />
    
        <util:list id="monitorsList">
            <ref bean="memoryMonitor" />
            <ref bean="sessionMonitor" />
        </util:list>
    
        <alias name="defaultPrincipalFactory" alias="principalFactory" />
        <alias name="defaultAuthenticationTransactionManager" alias="authenticationTransactionManager" />
        <alias name="defaultPrincipalElectionStrategy" alias="principalElectionStrategy" />
        <alias name="tgcCipherExecutor" alias="defaultCookieCipherExecutor" />
    </beans>
    

    说明

    • authenticationHandlersResolvers中添加数据库认证
    <!-- 添加数据库认证 -->
    <entry key-ref="databaseAuthenticationHandler" value-ref="primaryPrincipalResolver" />
    
    • 配置queryDatabaseAuthenticationHandler别名
    <!-- 配置queryDatabaseAuthenticationHandler别名 -->
    <alias name="queryDatabaseAuthenticationHandler" alias="databaseAuthenticationHandler" />
    
    • 添加数据库配置
    <!--数据库连接池配置-->
    <bean id="dataSource"
          class="com.mchange.v2.c3p0.ComboPooledDataSource"
          p:driverClass="${cas.audit.database.driverClass}"
          p:jdbcUrl="${cas.audit.database.url}"
          p:user="${cas.audit.database.user}"
          p:password="${cas.audit.database.password}"
          p:initialPoolSize="${cas.audit.database.pool.minSize}"
          p:minPoolSize="${cas.audit.database.pool.minSize}"
          p:maxPoolSize="${cas.audit.database.pool.maxSize}"
          p:maxIdleTimeExcessConnections="${cas.audit.database.pool.maxIdleTime}"
          p:checkoutTimeout="${cas.audit.database.pool.maxWait}"
          p:acquireIncrement="${cas.audit.database.pool.acquireIncrement}"
          p:acquireRetryAttempts="${cas.audit.database.pool.acquireRetryAttempts}"
          p:acquireRetryDelay="${cas.audit.database.pool.acquireRetryDelay}"
          p:idleConnectionTestPeriod="${cas.audit.database.pool.idleConnectionTestPeriod}"
          p:preferredTestQuery="${cas.audit.database.pool.connectionHealthQuery}" />
    
    • 设置数据库bean别名
    <!-- 配置dataSource别名 -->
    <alias name="dataSource" alias="queryDatabaseDataSource" />
    
    • 设置数据库密码加密算法
    <alias name="defaultPasswordEncoder" alias="passwordEncoder" />
    

    cas.properties

    有关代码

    #根据登录名查询数据库
    cas.jdbc.authn.query.sql=select password from cs_user where login_name=?
    
    #设置加密算法
    cas.authn.password.encoding.alg=SHA1
    
    #设置数据库配置
    cas.audit.database.dialect=org.hibernate.dialect.Oracle10gDialect
    #cas.audit.database.batchSize=
    #cas.audit.database.ddl.auto=
    #cas.audit.database.gen.ddl=
    cas.audit.database.show.sql=true
    cas.audit.database.driverClass=oracle.jdbc.driver.OracleDriver
    cas.audit.database.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
    cas.audit.database.user=WDIM
    cas.audit.database.password=WDIM
    cas.audit.database.pool.minSize=6
    cas.audit.database.pool.maxSize=18
    cas.audit.database.pool.maxIdleTime=120
    cas.audit.database.pool.maxWait=10000
    cas.audit.database.pool.acquireIncrement=6
    cas.audit.database.pool.acquireRetryAttempts=5
    cas.audit.database.pool.acquireRetryDelay=2000
    cas.audit.database.pool.idleConnectionTestPeriod=30
    cas.audit.database.pool.connectionHealthQuery=select 1
    

    说明

    • 依次添加数据库查询sql,加密算法,数据库配置

    主目录下build.gradle

    添加代码

    compile group: 'com.oracle', name: 'ojdbc6', version: '12.1.0.1-atlassian-hosted'
    compile project(':cas-server-support-jdbc')
    

    说明

    • 添加oracle的jar包,以及jdbc依赖工程

    相关文章

      网友评论

        本文标题:cas4.2.7数据库配置,读取用户信息

        本文链接:https://www.haomeiwen.com/subject/sfzzkxtx.html