Apereo CAS 5.0.X 启用OAuth2服务时的一个坑
来源:互联网 发布:开源财务系统 php 编辑:程序博客网 时间:2024/06/07 15:35
问题描述
引入cas-server-support-oauth-webflow依赖,启用oauth2服务,保存service先后使用了JSON和JPA的方式(如果不了解,可以参考http://blog.csdn.net/xichenguan/article/details/60770491
补充一下科学知识)。在使用JSON的时候,Tomcat启动,CAS部署过程中,在配置的目录下面会生成一个名为[OAuthCallbackurl-随机数字]格式的文件。内容如下:
{ @class: org.apereo.cas.support.oauth.services.OAuthCallbackAuthorizeService serviceId: https://cas.example.org:8443/cas/oauth2.0/callbackAuthorize.* name: OAuth Callback url id: 32577569223569 description: OAuth Wrapper Callback Url evaluationOrder: -2147483648 logoutType: BACK_CHANNEL attributeReleasePolicy: { @class: org.apereo.cas.services.ReturnAllAttributeReleasePolicy principalAttributesRepository: { @class: org.apereo.cas.authentication.principal.DefaultPrincipalAttributesRepository expiration: 2 timeUnit: HOURS } authorizedToReleaseCredentialPassword: false authorizedToReleaseProxyGrantingTicket: false } multifactorPolicy: { @class: org.apereo.cas.services.DefaultRegisteredServiceMultifactorPolicy failureMode: CLOSED } accessStrategy: { @class: org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy enabled: true ssoEnabled: true requireAllAttributes: true caseInsensitive: false }}
用JPA方式验证,同样是在数据库中生成一条同样含义的记录。
问题处理
第一步
每次生成的时候,大部分内容都是固定不变的,想到这些中肯定有部分或者全部都是静态变量,于是挨个找,在CasOAuthConfiguration中找到下面一段代码:
@PostConstruct public void initializeServletApplicationContext() { final String oAuthCallbackUrl = casProperties.getServer().getPrefix() + BASE_OAUTH20_URL + '/' + OAuthConstants.CALLBACK_AUTHORIZE_URL_DEFINITION; final Service callbackService = this.webApplicationServiceFactory.createService(oAuthCallbackUrl); final RegisteredService svc = servicesManager.findServiceBy(callbackService); if (svc == null || !svc.getServiceId().equals(oAuthCallbackUrl)) { final OAuthCallbackAuthorizeService service = new OAuthCallbackAuthorizeService(); service.setName("OAuth Callback url"); service.setDescription("OAuth Wrapper Callback Url"); service.setServiceId(oAuthCallbackUrl); service.setEvaluationOrder(Integer.MIN_VALUE); service.setAttributeReleasePolicy(new ReturnAllAttributeReleasePolicy()); servicesManager.save(service); servicesManager.load(); } this.validationServiceSelectionStrategies.add(0, oauth20ValidationServiceSelectionStrategy()); }
问题就出在casProperties.getServer().getPrefix()上了,这是一个嵌套的属性配置文件,里面的字段是这么定义的:
public class ServerProperties { private int connectionTimeout = 20000; private String name = "https://cas.example.org:8443"; private String prefix = name.concat("/cas"); private Ajp ajp = new Ajp(); private Http http = new Http(); private ExtendedAccessLog extAccessLog = new ExtendedAccessLog(); }
就是这个prefix字段了,他使用了name变量,也就是配置一下这个name变量就行了。
第二步
于是在application.properties文件中按照命名空间添加下面几个配置:
cas.server.name=https://asdf.com:8443cas.server.prefix=https://asdf.com:8443/cas
asdf.com是我测试CAS过程中,部署CAS服务的操作系统的域名,此域名添加到了需要访问CAS服务器的操作系统的hosts文件里。
第三步
远程debug了好久,发现还是不行,想到可能是其他地方也有配置,被覆盖了,就在项目底下,各种找,完了一会linux命令之后,已经绝望了。
第四步
折腾了两个多小时,挨个文件看,突然发现bootstrap.properies文件中有这么个配置:
spring.cloud.config.server.native.searchLocations=file:///etc/cas/config
疯了一样找这个目录,果然里面有个cas.properties文件:
cas.server.name: https://cas.example.org:8443cas.server.prefix: https://cas.example.org:8443/cascas.adminPagesSecurity.ip=127\.0\.0\.1logging.config: file:/etc/cas/config/log4j2.xml# cas.serviceRegistry.config.location: classpath:/services
呵呵,猜对了一半,是被覆盖了。
- Apereo CAS 5.0.X 启用OAuth2服务时的一个坑
- Apereo CAS 5.0.X 启用OAuth/OpenID认证
- Apereo CAS 5.0.X 认证
- Apereo CAS 5.0.X JPA Service Registry
- Apereo CAS 5.0.X 简明实用教程
- Apereo CAS 5.0.X 默认提供的数据库认证的四种方式
- Apereo CAS 5.0.X 配置数据库认证方式
- Apereo CAS 5.0.X JPA方式持久化票据
- Apereo CAS 5.0.3.1安装配置
- Apereo Cas之Docker
- 使用Apereo Cas 5.1.3的Restful接口实现SSO及TGC分析
- Django实现CAS+OAuth2
- CAS的单点登录和oauth2的最大区别
- 关于Apereo CAS中的几种timeout定义
- 启用路由器的SNMP服务
- 启用ESXi的SSH服务
- 启用ESXi的SSH服务
- CAS不启用HTTPS
- jquery 验证
- 路灯
- hydro下gazebo的Failed to connect to master in 30 seconds 问题
- js中对函数设置默认参数值的3种方法
- 欢迎使用CSDN-markdown编辑器
- Apereo CAS 5.0.X 启用OAuth2服务时的一个坑
- (转载)c++实现反射机制
- 解决js动态改变dom元素属性后页面及时渲染问题
- JAVA学习之this,static,String常用方法
- [编程题]序列和
- 474. Ones and Zeroes
- Android热修复之Tinker
- 购物车项目总结
- java中泛型的使用