2016-07-05 59 views
0

打我已经在Liferay中的“ServiceImpl” &取得了远程JSON网络服务它发生在Web服务列表页面http://localhost:8080/api/jsonws &也正在罚款。但只有当我在浏览器中登录应用程序时才有效。 什么,我没有得到的是,我将如何认证命中,如果一些其他非Liferay的应用会使用它,哪里会有没有我的应用程序的会话,从那里我们将获得意味着p_auth令牌。意味着我需要在我的应用程序上的用户会话吗? 谢谢。如何验证Web服务从非Liferay的应用

+0

我该如何验证** **网络服务**使用** OAuth **,意味着如何实现它。我想使用** OAuth **从** Postman **中打开Web服务,然后它应该返回数据。我想要基于** token **的认证,在liferay **中怎么可能。 – sRijit

回答

0

你必须从你使用的是Java可以使用Apache HTTP客户端与preemtive基本身份验证 ClientPreemptiveBasicAuthentication

或使用curl例如这样

curl http://localhost:8080/api/jsonws/user/get-user-by-email-address \ 
    -u [email protected]:test \ 
    -d companyId=20154 \ 
    -d emailAddress='[email protected]' 

调用例如客户端验证更多信息请参见

JSON WS Security

Liferay docs

+0

感谢Sheshi的快速响应,我试过的是**主程序中的正常** java项目** **远程服务**,它正在工作,我想知道它是否正确办法? – sRijit

+0

URL url = new URL(“http://localhost:8080/api/jsonws/survey-portlet.survey/hello-world/world-name/test”); \t \t HttpURLConnection conn =(HttpURLConnection)url.openConnection(); \t \t conn.setRequestMethod(“POST”); \t String encoding = Base64.getEncoder()。encodeToString(new String(“[email protected]:test”)。getBytes()); \t \t \t conn.setRequestProperty(“Authorization”,“Basic”+ encoding); – sRijit