使用keycloak 6.0.1
我已经创建了领域角色和用户。我有用户uuid和角色uuid。
如果我运行
curl -v -X POST -w "\n" http://localhost:8080/auth/admin/realms/SpringBootKeycloak/users/$USER_ID/role-mappings/realm -H "Content-Type: application/json" -H "Authorization: bearer $TOKEN" --data '[{"id":$ROLE_ID,"name":"user"}]'
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /auth/admin/realms/SpringBootKeycloak/users/fe38bcb5-258b-44e4-a056-cf8c1a29b99f/role-mappings/realm HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
> Content-Type: application/json
> Authorization: bearer very long string
> Content-Length: 31
>
* upload completely sent off: 31 out of 31 bytes
< HTTP/1.1 500 Internal Server Error
< Connection: keep-alive
< Content-Length: 0
< Date: Fri, 13 Sep 2019 08:53:14 GMT
<
* Connection #0 to host localhost left intact我得到一个服务器错误和一个日志条目
10:00:55,903 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-10) Uncaught server error: com.fasterxml.jackson.databind.JsonMappingException: Unrecognized token '$ROLE_ID': was expecting ('true', 'false' or 'null')
at [Source: (io.undertow.servlet.spec.ServletInputStreamImpl); line: 1, column: 3] (through reference chain: java.util.ArrayList[0])或者,如果我使用以下数据运行curl
--data '{"id":"$ROLE_ID","name":"user"}‘
然后返回404 not found。
如果我将数据设置为硬编码,那么它就可以工作
--data '{"id":"9b6371f2-646d-4927-b3b6-6e208935517e","name":"user"}‘
但是得到的结果是204没有内容,这就是成功。并添加该角色。
进一步调查-
--数据'{"id":"'$ROLE_ID'","name":"user"}‘
显示204状态,角色将添加到用户。
所以,最终要做到这一点。
发布于 2019-09-15 16:59:57
这是变量替换的一个问题:
$ export ROLE_ID=9b6371f2-646d-4927-b3b6-6e208935517e
$ echo '[{"id":"'$ROLE_ID'","name":"user"}]'
[{"id":"9b6371f2-646d-4927-b3b6-6e208935517e","name":"user"}]
$ echo '[{"id":$ROLE_ID,"name":"user"}]'
[{"id":$ROLE_ID,"name":"user"}]
$ echo '[{"id":"$ROLE_ID","name":"user"}]'
[{"id":"$ROLE_ID","name":"user"}]https://stackoverflow.com/questions/57920597
复制相似问题