【问题标题】:Can't access EntitlementService Webservice on wso2is无法访问 wso2is 上的 EntitlementService Web 服务
【发布时间】:2014-05-05 07:03:57
【问题描述】:

我正在尝试访问在本地主机上的 WSO2 IdentityServer 上运行的 EntitlementService。 我想评估 IS 用作 XACML 引擎。这只是概念验证代码和测试。

我尝试了 Java 客户端和 php 客户端。

可以在这里下载的java代码: https://sites.google.com/site/securedecentralizedblog/is/EntitlementClient.java?attredirects=0&d=1

我只更改了 wso2is 相关内容的目录。在 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/

这似乎很奇怪,因为 localhost 通常总是会解析...

还尝试了手工制作的 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();
}
?>

我通过了登录调用,但在“开始决策调用”之后,我在客户端收到以下错误消息:

Error occurred while evaluating XACML request

在 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)

可能出了什么问题?我需要它来工作,否则我们将无法为我们的项目选择 wso2is。

另外,是否有任何用于此计划的 REST API? 如果是,什么时候?

【问题讨论】:

  • 我们实际上最重要的是需要php版本:)
  • Als 使用来自svn.wso2.org/repos/wso2/people/asela/xacml/sample/atm/client 的客户端代码会产生关于 IdentityCacheKey 的相同错误...
  • 使用 wso2is 管理控制台的“TryIt”页面评估我通过 SOAP 使用的相同策略评估请求工作正常。只有通过webservice访问时它不起作用...

标签: wso2 wso2is


【解决方案1】:

这就是我最终似乎解决它的方法。 我使用了另一个可用的 WSDL 函数,getDecisionByAttributes。

它仍然会在 wso2 IS 服务器中生成一些奇怪的异常,但我实际上得到了返回 值“允许”或“拒绝”(或“不确定”)。

$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();
}

【讨论】:

    【解决方案2】:

    TryIt 也是使用web service 方法...这意味着,当您从web service API 发送请求时,它也必须工作.. 根据null pointer,似乎是XACML 请求是没有出现在您的 SOAP 消息中。我想跟踪来自您的 PHP 客户端的消息...此外,出于调试目的,您可以在 WSO2IS 中启用debug 日志,这有助于您查看 XACML 请求/响应消息。

    【讨论】:

      【解决方案3】:

      在您的 PHP 脚本中,尝试替换该行

      $client->getDecision($request);
      

      作者:

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

      这应该会处理您的 NullPointerException。

      这是因为根据 WSDL,SOAP 方法 getDecision 需要一个名为“request”的 named 参数,其中包含实际的 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>
      

      【讨论】:

        猜你喜欢
        • 2019-09-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-23
        • 2014-07-15
        • 1970-01-01
        • 2018-02-25
        • 1970-01-01
        相关资源
        最近更新 更多