我使用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解析期间触发了异常 .
谁有任何想法?或任何评论?还是建议?
谢谢
1 回答
结果证明这是一种误报 .
问题在于 endpoints 值(scimUrl)已被设置为“https://xxx.xxx.xxx:9443/wso2/scim” .
我将其更改为“https://xxx.xxx.xxx:9443/wso2/scim/Users”,然后它工作正常 .
干杯