0

我在使用 WSO2is-5.2.0 SCIM 接口时遇到了一些奇怪的问题。

这是一个移动应用项目,我们决定使用 WSO2 IS 作为身份管理。客户注册是通过 WSO2 IS 的 SCIM 接口完成的。

在移动设备上通过带有 content-type = application/json 的 Restful post 消息输入并提交用户名和密码(参见下面的 TS 代码)

 public signin(){
    let data = {"userName":this.sf.get("userName").value,
    "password":this.sf.get("password").value};
    debugger;
    this.gabriel.create(data).subscribe(
      (res) => {
        this. _res = res;
        debugger;
      },
      error => {
          console.log('somthing went wrong ');
        },
      () => {}
    );
  }

网关是 apache cxf JAX-RS;我们使用 wso2 Charon 代码集来确保与 WSO2 IS 的兼容性。

在门口,这个请求被拦截并解释为“org.wso2.charon.core.objects.User”的子类(见下面的代码)

@POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/signin")
    public ScimRes signin(GubUser signin);

GubUser 和ScimRes 的定义

public class GubUser extends User {

    private static final long serialVersionUID = 5431026567781364473L;

    public GubUser() {
        super();
    }
...


public class ScimRes {
    private int state;
    private String id;

    public int getState(){
        return this.state;
    }

    public void setState(int state){
        this.state = state;
    }
    ...

扩展 User 类的原因是我们想要包含来自终端的一些额外信息。并且这些额外信息在传递到 WSO2 IS SCIM 接口之前从对象中删除,以便发送到 WSO2 IS SCIM 接口的数据 100% 符合用户定义(参见下面的代码)

@Override
        public ScimRes signin(GubUser signin) {

            if(signin == null){
                return null;
            }

            Boolean klp = null; 
            String device = null;
            String user = null;
            try {               
                  klp = signin.getKlp();

                  if(klp != null && klp.booleanValue() == true){ 
                    device = signin.getGubDevice();
                    signin.deleteAttribute("klp");
                    signin.deleteAttribute("gubDevice");
                  }

                  Observable.just(signin)
                    .flatMap(in -> {return Observable.just(Scim.createUser(in));})
                    .subscribe(res -> this.scimRes = res);

...

现在,调用 WSO2 IS SCIM(见下面的代码)

 public class Scim {
    private static HttpClient client = new DefaultHttpClient();
    private static String basicAuthToken = setBasicAuthToken();

    public static ScimRes createUser(User user) throws CharonException, ClientProtocolException, IOException, ParseException{
        String encodedUser = new SCIMClient().encodeSCIMObject(user, SCIMConstants.JSON);
        HttpPost post = new HttpPost(Params.scimUrl);
        post.addHeader(SCIMConstants.AUTHORIZATION_HEADER, basicAuthToken);
        post.addHeader("Accept", SCIMConstants.APPLICATION_JSON);
        post.addHeader("Accept-Charset", "utf-8");
        StringEntity entity = new StringEntity(encodedUser, SCIMConstants.APPLICATION_JSON, "UTF-8");
        post.setEntity(entity );
        ScimRes scimRes = new ScimRes();
        HttpResponse res = client.execute(post);
        scimRes.setState(res.getStatusLine().getStatusCode());

        int resStatus = scimRes.getState();
        if(resStatus == HttpStatus.SC_CREATED || resStatus == HttpStatus.SC_OK ){
            InputStream is = res.getEntity().getContent();
            JSONParser jsonParser = new JSONParser();
            JSONObject jo = (JSONObject)jsonParser.parse(new InputStreamReader(is, "UTF-8"));
            scimRes.setId((String)jo.get("id"));
            is.close();

        }
        return scimRes;
    }   

程序被困在

JSONObject jo = (JSONObject)jsonParser.parse(new InputStreamReader(is, "UTF-8"));

我得到了 http 响应消息头的副本(见下文)

HTTP/1.1 200 OK [X-Frame-Options: DENY, X-Content-Type-Options: nosniff, X-XSS-Protection: 1; mode=block, Content-Type: text/html;charset=UTF-8, Content-Length: 1445, Date: Tue, 06 Dec 2016 11:52:39 GMT, Server: WSO2 Carbon Server]

以及堆栈打印输出

Unexpected character (<) at position 0.
at org.json.simple.parser.Yylex.yylex(Yylex.java:610)
at org.json.simple.parser.JSONParser.nextToken(JSONParser.java:269)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:118)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:92)
at com.gubnoi.user.provision.Scim.createUser(Scim.java:52)
at com.gubnoi.gate.Gate.lambda$signin$0(Gate.java:131)
at io.reactivex.internal.operators.observable.ObservableScalarXMap$ScalarXMapObservable.subscribeActual(ObservableScalarXMap.java:141)

似乎消息正文以“<”开头。在 JSON 解析期间触发了异常。

有人有什么想法吗?或任何意见?或建议?

谢谢

4

1 回答 1

0

事实证明这是一场虚惊。

问题在于已设置为“ https://xxx.xxx.xxx:9443/wso2/scim ”的端点值(scimUrl)。

我将其更改为“ https://xxx.xxx.xxx:9443/wso2/scim/Users ”,然后它工作正常。

干杯

于 2016-12-07T07:36:41.080 回答