环境:jdk1.8,tomcat8
1、把tomcat下(WEB-INF/classes/services)的services复制到resource下
如果项目中没有这个文件夹,请点击maven边上的刷新按钮
2、在services下新增mytheme-10000002.json、mytheme2-10000003.json文件
mytheme-10000002.json
{
"@class": "org.apereo.cas.services.RegexRegisteredService",
"serviceId": "^(https|imaps|http)://test.*",
"name": "mytheme",
"theme": "mytheme",
"id": 10000002,
"description": "自定义主题",
"evaluationOrder": 1000
}
mytheme2-10000003.json
{
"@class": "org.apereo.cas.services.RegexRegisteredService",
"serviceId": "^(https|imaps|http)://test2.*",
"name": "mytheme2",
"theme": "mytheme2",
"id": 10000003,
"description": "自定义主题2",
"evaluationOrder": 1001
}
id、evaluationOrder、theme这三个属性别和其他json文件里的重名
3、修改HTTPSandIMAPS-10000001.json,使其支持http
{
"@class" : "org.apereo.cas.services.RegexRegisteredService",
"serviceId" : "^(https|imaps|http)://.*",
"name" : "HTTPS and IMAPS",
"id" : 10000001,
"description" : "This service definition authorizes all application urls that support HTTPS and IMAPS protocols.",
"evaluationOrder" : 10000
}
前面三个json文件中都新增了http
4、在application.properties里新增cas.serviceRegistry.initFromJson=true,让json配置文件生效
5、新增mytheme.properties、mytheme2.properties文件
mytheme.properties
cas.css=/themes/mytheme/css/cas.css
cas.pageTitle=\u6d4b\u8bd5\u4e00\u4e0b
mytheme2.properties
cas.css=/themes/mytheme2/css/cas.css
cas.pageTitle=\u6d4b\u8bd5\u4e00\u4e0b2
6、在resources新建如下目录
静态资源(js,css)存放目录为src/main/resources/static/[theme_name]
html资源存(thymeleaf)放目录为src/main/resources/templates/casLoginView.html
主题配置文件存放在src/main/resources并且命名为[theme_name].properties
主题页面html存放目录为src/main/resources/templates/[theme_name]
上面四行都是网上看到的,我把json文件里的theme属性改了也能正常使用(有大佬指导详细、具体的规则请联系我!!!)
mytheme/cas.css
h1 {
color: blue;
}
mytheme2/cas.css
h1 {
color: pink;
}
mytheme/casLoginView.html和mytheme2/casLoginView.html一样
7、修改application.properties
在application.properties里新增cas.theme.defaultThemeName=mythem
大致意思就是使得参数service开头为http的可以进行认证,http://后面的是test1开头使用mytheme主题,test2开头使用mytheme2主题
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.theme.defaultThemeName=mytheme
cas.serviceRegistry.initFromJson=true
#cas.serviceRegistry.watcherEnabled=true
#cas.serviceRegistry.config.location=classpath:/services
8、测试
不带参数访问,跳转到了之前设置的默认主题(mytheme)
test访问,跳转到了mytheme
test2访问,跳转到了mytheme2
参考:
https://blog.csdn.net/yelllowcong/article/details/79236506
https://blog.csdn.net/u010475041/article/details/78201261