简体   繁体   English

无法在wso2is上访问EntitlementService Web服务

[英]Can't access EntitlementService Webservice on wso2is

I am trying to access the EntitlementService running on a WSO2 IdentityServer on localhost. 我正在尝试访问在本地主机上的WSO2 IdentityServer上运行的EntitlementService。 I want to evaluate IS for use as XACML engine. 我想评估IS用作XACML引擎。 This is all just Proof-Of-Concept code and tests. 这仅仅是概念验证代码和测试。

I tried both with a Java client and a php client. 我尝试了Java客户端和php客户端。

The java code which can be downloaded here: https://sites.google.com/site/securedecentralizedblog/is/EntitlementClient.java?attredirects=0&d=1 可以在此处下载的Java代码: https : //sites.google.com/site/securedecentralizedblog/is/EntitlementClient.java?attredirects=0&d=1

I only changed the directory for the wso2is related stuff. 我只更改了wso2is相关内容的目录。 Running it gives me these error in the wso2is console: 运行它会在wso2is控制台中给我这些错误:

[2014-05-05 01:36:00,058] ERROR {org.wso2.carbon.core.services.authentication.AuthenticationAdmin} -  Authentication Failed : Invalid remote address passed - https://localhost:9443/
[2014-05-05 01:36:29,127]  WARN {org.wso2.carbon.core.services.authentication.AuthenticationUtil} -  Could not find IP address for domain name : https://localhost:9443/

Which seems really weird as localhost normally always resolves... 这似乎真的很奇怪,因为localhost通常总是可以解析...

Also tried with a hand made php script: 还尝试了手工制作的php脚本:

<?php
$context = stream_context_create(array(
    'ssl' => array(
        'verify_peer' => false,
        'allow_self_signed' => true
    )
));

$auth = array(
        'trace' => true,
        'login'=>'admin',
        'password'=>'admin',
        'stream_context'=>$context
        );

$login_client = new SoapClient('https://localhost:9443/services/AuthenticationAdmin?wsdl',$auth);
$client = new SoapClient('https://localhost:9443/services/EntitlementService?wsdl',$auth);


$request = file_get_contents('../xacml_get_users.xml');


echo "\n\nGoing to start login call...\n\n";
try {
  $login_response = $login_client->login($auth);
  $response_headers = $login_client-> __getLastResponseHeaders();
  $request_cookie = $login_client->_cookies;
  $a_jsessionid = $request_cookie['JSESSIONID'];
  $jsessionid = $a_jsessionid[0];
  $cutstr = substr($response_headers,strpos($response_headers,'Set-Cookie: '));
  $cookie = substr($cutstr,strlen('Set-Cookie: '));
  $cookie = substr($cookie, 0, strpos($cookie,';'));

  echo "\n\nGoing to start decision call...\n\n";

  $cookie_name="JSESSIONID";
  $cookie_value=$jsessionid;
  $client->__setCookie($cookie_name, $cookie_value);
  $client->getDecision($request);
} catch (Exception $e) {
  echo $e->getMessage();
}
?>

I get past the login call, but then after the "start decision call" I get this error message in the client: 我经过了登录调用,但是在“开始决策调用”之后,我在客户端得到了以下错误消息:

Error occurred while evaluating XACML request

And in the wso2is console: 在wso2is控制台中:

[2014-05-05 01:33:03,733] ERROR {org.wso2.carbon.identity.entitlement.EntitlementService} -  Error occurred while evaluating XACML request
java.lang.NullPointerException
    at org.wso2.carbon.identity.entitlement.cache.IdentityCacheKey.hashCode(IdentityCacheKey.java:62)
    at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:333)
    at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:1016)
    at org.wso2.carbon.caching.impl.CacheImpl.containsKey(CacheImpl.java:260)
    at org.wso2.carbon.identity.entitlement.cache.EntitlementBaseCache.getValueFromCache(EntitlementBaseCache.java:144)
    at org.wso2.carbon.identity.entitlement.cache.DecisionCache.getFromCache(DecisionCache.java:49)
    at org.wso2.carbon.identity.entitlement.pdp.EntitlementEngine.getFromCache(EntitlementEngine.java:384)
    at org.wso2.carbon.identity.entitlement.pdp.EntitlementEngine.evaluate(EntitlementEngine.java:229)
    at org.wso2.carbon.identity.entitlement.EntitlementService.getDecision(EntitlementService.java:51)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

What could be going wrong? 可能出什么问题了? I need this to work otherwise we won't be able to choose wso2is for our project. 我需要这项工作,否则我们将无法为我们的项目选择wso2is。

Also, is there any REST API for this planned? 此外,是否为此计划提供了REST API? If yes, for when? 如果是,什么时候?

This is how I finally seem to have solved it. 这就是我终于似乎解决了它的方式。 I used the other available WSDL function, getDecisionByAttributes. 我使用了另一个可用的WSDL函数getDecisionByAttributes。

It still generates some weird exception in the wso2 IS server, but I actually get the return value "Permit" or "Deny" (or "Indeterminate"). 它仍然在wso2 IS服务器中生成一些奇怪的异常,但是我实际上得到了返回值“ Permit”或“ Deny”(或“ Indeterminate”)。

$context = stream_context_create(array(
    'ssl' => array(
        'verify_peer' => false,
        'allow_self_signed' => true
    )
));

$http_auth = array(
        'trace' => true,
        'login'=>'admin',
        'password'=>'admin',
        'stream_context'=>$context
        );

$client = new SoapClient('https://localhost:9443/services/EntitlementService?wsdl',$http_auth);

try {
  $res = $client->getDecisionByAttributes(array("subject"=>"okuser","resource"=>"https://api.example.org/api/v1/users","action"=>"GET"));
  $xml = simplexml_load_string($res->return);
  $decision = $xml->Result->Decision;;
  echo $decision;
} catch (Exception $e) {
  echo $e->getMessage();
}

TryIt also using the web service method... It means, when you are sending the request from web service API, it also must work.. According to the null pointer , it seems to be that XACML request is not coming in your SOAP message. TryIt也使用Web服务方法...这意味着,当您从Web Service API发送请求时,它也必须工作。根据null pointer ,似乎XACML请求没有出现在您的SOAP消息中。 I suppose to tract the message that is going from your PHP client... Also the for debug purpose, you can enable the debug logs in WSO2IS, which helps you to see XACML request/response messages. 我想对来自PHP客户端的消息进行说明...同样出于调试目的,您可以在WSO2IS中启用调试日志,这有助于您查看XACML请求/响应消息。

In your PHP script, try replacing the line 在您的PHP脚本中,尝试替换该行

$client->getDecision($request);

by: 通过:

$client->getDecision(["request" => $request]);

This should take care of your NullPointerException. 这应该照顾到您的NullPointerException。

This is because according the WSDL, the SOAP method getDecision need a named parameter called "request", containing the actual XACML request: 这是因为根据WSDL,SOAP方法getDecision需要一个名为 “ request”的命名参数,其中包含实际的XACML请求:

<xs:element name="getDecision">
  <xs:complexType>
    <xs:sequence>
      <xs:element minOccurs="0" name="request" nillable="true" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM