做了个手机端利用idp-rest-api进行登录问题?

多个系统进行idp设置,做了个手机端利用idp-rest-api进行登录,获取的idp_ticket是否可以共享?

idp_ticket只能在IDP(身份验证端)获取。然后在服务端用。
这块代码是idp_ticket用过一次,就从队列里删除了,你可以修改那块逻辑,让他不要删除,但是官方不建议。

官方建议的做法是: SP1要登录,就去IDP端拿一个idp_ticket。 这时候SP2要用,需要再从IDP端拿一个。
https://www.cuba-platform.com/discuss/t/why-remove-ticket-session-when-activesessionticket/7124/4

按这个顺序:

  1. http:///idp/auth 获取ticket
  2. http://<sp_2>/rest/v2/idp/token 获取token,这步用到了#1里获取的idp_ticket, 这步结束后 idp_ticket不再有效,以后访问sp_2的资源都用这个token
  3. http://<sp_2>/rest/v2/userInfo 访问api(userInfo),这步用到了#2里获取的token。

对于其他sp, 重复上述1,2, 3。

你之前那个帖子里提到的开启idp不能用普通token的问题给cuba英文论坛提了,他们在看。有回复通知你。

我就是按照这个步骤做的!但是获取实体报错!

我用cuba7.1重复了一下你的这个配置,是可以的:

  1. idp取ticket
    image
  2. sp取idpToken
    image
  3. sp使用idptoken取userinfo:
    image

idp的配置:

cuba.web.idp.enabled = true
cuba.web.idp.baseUrl = http://192.168.7.25:13000/app/idp/
cuba.web.idp.trustedServicePassword = 123456
cuba.idp.serviceProviderUrls = http://localhost:13000/app/,http://192.168.7.25:13000/app/,http://192.168.7.33:8080/ttask/

cuba.rest.idp.baseUrl = ${cuba.web.idp.baseUrl}
cuba.rest.idp.trustedServicePassword = ${cuba.web.idp.trustedServicePassword}
cuba.rest.idp.enabled = true
cuba.rest.idp.defaultRedirectUrl = https://www.baidu.com
cuba.rest.idp.pingSessionOnRequest = false
cuba.idp.trustedServicePassword = 123456

cuba.idp.serviceProviderLogoutUrls=http://192.168.7.25:13000/app/dispatch/idpc/logout,http://192.168.7.33:8080/ttask/dispatch/idpc/logout
cuba.idp.serviceProviderUrlMasks=http://192.168.7.25:13000/app/.*,http://192.168.7.33:8080/ttask/.*

sp的配置:

cuba.web.idp.enabled = true
cuba.web.idp.baseUrl = http://192.168.7.25:13000/app/idp/
cuba.web.idp.trustedServicePassword = 123456
cuba.rest.idp.baseUrl = ${cuba.web.idp.baseUrl}
cuba.rest.idp.trustedServicePassword = ${cuba.web.idp.trustedServicePassword}
cuba.rest.idp.enabled = true
cuba.rest.idp.defaultRedirectUrl = https://www.baidu.com
cuba.rest.idp.pingSessionOnRequest = false
cuba.idp.trustedServicePassword = 123456

跟你不同的在于我没有共用一个库,但我感觉不是公用库的问题。
你查一下你用sp2取ticket的时候,有没有遇到跨域的问题。第一步里的 /idp/auth有跨域限制,如果是浏览器是取不到ticket的。

cuba.idp.serviceProviderUrls ,cuba.idp.serviceProviderLogoutUrls ,cuba.idp.trustedServicePassword 这三个参数的配置我是利用代码直接写到内存中的,并没有在配置文件进行配置!

sp1 提示 17:28:06.982 WARN c.h.a.i.i.controllers.IdpController - Incorrect serviceProviderUrl http://172.16.147.218:5000/dept/rest/v2/entities/dept_Depts passed, will be used default
??

你在sp1的JMX控制台里把参数打出来,看看是不是因为代码设置的,有些什么字符被转义了
按下面的图,但是是sp1里:
image
注意第2步是dept.cuba下,不是图上的dept-core.cuba下
双击第三步那里后:
image
看看实际配置

image

问题存在于,cuba.idp.serviceProviderUrlMasks!!

如果直接将cuba.idp.serviceProviderUrlMasks =http://172.16.147.218:9001/li/.*,http://172.16.147.218:5000/dept/.*进行配置就可以,如果内存中添加就不行!!!!这还是个问题???

我修改了idp源码,因为源码读取cuba.idp.serviceProviderUrlMasks,在项目启动加载idp时就已经读取,所以后续加载到内存的cuba.idp.serviceProviderUrlMasks是无法获取的!!!

cuba.idp.serviceProviderUrl 这个是进行数据通信的时候,获取内存的!

基本完成功能,感谢帮忙!!

2 个赞

1 个帖子被拆分到新主题:IDP Token获取问题