cas5.2.6(2)jdbc数据库认证

环境:jdk1.8,tomcat8,oracle11g

1、添加依赖

cas5.2.6(2)jdbc数据库认证_第1张图片

pom.xml



    4.0.0
    org.apereo.cas
    cas-overlay
    war
    1.0

    
        
            
                com.rimerosolutions.maven.plugins
                wrapper-maven-plugin
                0.0.5
                
                    true
                    MD5
                
            
            
                org.springframework.boot
                spring-boot-maven-plugin
                ${springboot.version}
                
                    ${mainClassName}
                    true
                    ${isExecutable}
                    WAR
                
                
                    
                        
                            repackage
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-war-plugin
                2.6
                
                    cas
                    false
                    false
                    
                        false
                        ${manifestFileToUse}
                    
                    
                        
                            org.apereo.cas
                            cas-server-webapp${app.server}
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.3
            
        
        cas
    

    
        
            org.apereo.cas
            cas-server-webapp${app.server}
            ${cas.version}
            war
            runtime
        
        
        
            com.github.noraui
            ojdbc7
            12.1.0.2
        
        
            org.apereo.cas
            cas-server-support-jdbc
            ${cas.version}
        
    

    
        5.2.6
        1.5.12.RELEASE
        
        -tomcat

        org.springframework.boot.loader.WarLauncher
        false
        ${project.build.directory}/war/work/org.apereo.cas/cas-server-webapp${app.server}/META-INF/MANIFEST.MF

        1.8
        1.8
        UTF-8
    

    
        
            sonatype-releases
            http://oss.sonatype.org/content/repositories/releases/
            
                false
            
            
                true
            
        
        
            sonatype-snapshots
            https://oss.sonatype.org/content/repositories/snapshots/
            
                true
            
            
                false
            
        
        
            shibboleth-releases
            https://build.shibboleth.net/nexus/content/repositories/releases
        
    

我这边用的数据库是oracle,用mysql的可自行添加mysql驱动

2、在application.properties里新增配置(mysql和oracle的配置都有)

先把#cas.authn.accept.users=casuser::Mellon这段注释

cas5.2.6(2)jdbc数据库认证_第2张图片

sql语句区分大小写和关键字!!!

application.properties

##
# CAS Server Context Configuration
#
server.context-path=/cas
server.port=8443

server.ssl.enabled=false
#server.ssl.key-store=file:/etc/cas/thekeystore
#server.ssl.key-store-password=changeit
#server.ssl.key-password=changeit
# server.ssl.ciphers=
# server.ssl.client-auth=

# server.ssl.key-alias=
# server.ssl.key-store-provider=
# server.ssl.key-store-type=
# server.ssl.protocol=
# server.ssl.trust-store=
# server.ssl.trust-store-password=
# server.ssl.trust-store-provider=
# server.ssl.trust-store-type=

server.max-http-header-size=2097152
server.use-forward-headers=true
server.connection-timeout=20000
server.error.include-stacktrace=ALWAYS

server.compression.enabled=true
server.compression.mime-types=application/javascript,application/json,application/xml,text/html,text/xml,text/plain

server.tomcat.max-http-post-size=2097152
server.tomcat.basedir=build/tomcat
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms)
server.tomcat.accesslog.suffix=.log
server.tomcat.max-threads=10
server.tomcat.port-header=X-Forwarded-Port
server.tomcat.protocol-header=X-Forwarded-Proto
server.tomcat.protocol-header-https-value=https
server.tomcat.remote-ip-header=X-FORWARDED-FOR
server.tomcat.uri-encoding=UTF-8

spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true

##
# CAS Cloud Bus Configuration
#
spring.cloud.bus.enabled=false
# spring.cloud.bus.refresh.enabled=true
# spring.cloud.bus.env.enabled=true
# spring.cloud.bus.destination=CasCloudBus
# spring.cloud.bus.ack.enabled=true

endpoints.enabled=false
endpoints.sensitive=true

endpoints.restart.enabled=false
endpoints.shutdown.enabled=false

management.security.enabled=true
management.security.roles=ACTUATOR,ADMIN
management.security.sessions=if_required
management.context-path=/status
management.add-application-context-header=false

security.basic.authorize-mode=role
security.basic.enabled=false
security.basic.path=/cas/status/**

##
# CAS Web Application Session Configuration
#
server.session.timeout=300
server.session.cookie.http-only=true
server.session.tracking-modes=COOKIE

##
# CAS Thymeleaf View Configuration
#
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.cache=true
spring.thymeleaf.mode=HTML
##
# CAS Log4j Configuration
#
# logging.config=file:/etc/cas/log4j2.xml
server.context-parameters.isLog4jAutoInitializationDisabled=true

##
# CAS AspectJ Configuration
#
spring.aop.auto=true
spring.aop.proxy-target-class=true

##
# CAS Authentication Credentials
#
#cas.authn.accept.users=casuser::Mellon

cas.tgc.secure=false 


cas.authn.jdbc.query[0].passwordEncoder.type=DEFAULT
cas.authn.jdbc.query[0].passwordEncoder.characterEncoding=UTF-8
cas.authn.jdbc.query[0].passwordEncoder.encodingAlgorithm=SHA

cas.authn.jdbc.query[0].url=jdbc:oracle:thin:@localhost:1521:orcl
cas.authn.jdbc.query[0].user=JXCJ_XG
cas.authn.jdbc.query[0].password=123456
cas.authn.jdbc.query[0].sql=select * from SSO_USER where "username" = ?
cas.authn.jdbc.query[0].fieldPassword=password
cas.authn.jdbc.query[0].driverClass=oracle.jdbc.driver.OracleDriver


#cas.authn.jdbc.query[0].url=jdbc:mysql://localhost:3306/sso?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
#cas.authn.jdbc.query[0].user=root
#cas.authn.jdbc.query[0].password=root
#cas.authn.jdbc.query[0].sql=select * from user where username=?
#cas.authn.jdbc.query[0].fieldPassword=password
#cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver

3、数据库建表

cas5.2.6(2)jdbc数据库认证_第3张图片

上面用的是sha加密,网上找个在线sha加密就行了

4、测试

根目录下运行cmd

E:\lb\cas-overlay-template>build.cmd run

cas5.2.6(2)jdbc数据库认证_第4张图片

cas5.2.6(2)jdbc数据库认证_第5张图片

数据库驱动版本折腾了好久...出现数据库的报错大多是这个问题

参考:

https://blog.csdn.net/u010475041/article/details/77943965

https://blog.csdn.net/yelllowcong/article/details/79541838

你可能感兴趣的:(cas)