[jboss-jira] [JBoss JIRA] (JGRP-1954) SWIFT_PING discovery protocol fatal error on OpenStack Kilo

Thomas Segismont (JIRA) issues at jboss.org
Tue Sep 1 09:03:05 EDT 2015


    [ https://issues.jboss.org/browse/JGRP-1954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13104055#comment-13104055 ] 

Thomas Segismont commented on JGRP-1954:
----------------------------------------

Hi, I'm the contributor of the SWIFT_PING discovery protocol. For the sake of transparency, I contributed it before joining Red Hat and it's a long time I haven't worked with Openstack+JGroups. That said, here's my opinion.

A {{ScriptEngine}} based solution sounds more appealing, as it allows to keep the protocol implementation in JGroups. It is possible to write it in a way which is compatible with both Java 7 and Java 8

{code:javascript|title=script.js}
var response = JSON.parse(json);

var result = {};

result.id = response.access.token.id;

var serviceCatalog = response.access.serviceCatalog;
for (var i = 0; i < serviceCatalog.length; i++) {
    var service = serviceCatalog[i];
    if (service.type == "object-store") {
        result.url = service.endpoints[0].publicURL;
        break;
    }
}

result;
{code}

{code:json|title=response.json}
{
  "access": {
    "token": {
      "issued_at": "2014-01-30T15:30:58.819584",
      "expires": "2014-01-31T15:30:58Z",
      "id": "aaaaa-bbbbb-ccccc-dddd",
      "tenant": {
        "description": null,
        "enabled": true,
        "id": "fc394f2ab2df4114bde39905f800dc57",
        "name": "demo"
      }
    },
    "serviceCatalog": [
      {
        "endpoints": [
          {
            "adminURL": "http://23.253.72.207:8080",
            "region": "RegionOne",
            "internalURL": "http://23.253.72.207:8080/v1/AUTH_fc394f2ab2df4114bde39905f800dc57",
            "id": "16b76b5e5b7d48039a6e4cc3129545f3",
            "publicURL": "http://23.253.72.207:8080/v1/AUTH_fc394f2ab2df4114bde39905f800dc57"
          }
        ],
        "endpoints_links": [],
        "type": "object-store",
        "name": "swift"
      }
    ],
    "user": {
      "username": "demo",
      "roles_links": [],
      "id": "9a6590b2ab024747bc2167c4e064d00d",
      "roles": [
        {
          "name": "Member"
        },
        {
          "name": "anotherrole"
        }
      ],
      "name": "demo"
    },
    "metadata": {
      "is_admin": 0,
      "roles": [
        "7598ac3c634d4c3da4b9126a5f67ca2b",
        "f95c0ab82d6045d9805033ee1fbc80d4"
      ]
    }
  }
}
{code}

{code:java|title=Parsing.java}
import java.util.Map;

import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.SimpleBindings;

public class Parsing {

    public static void main(String[] args) throws Exception {
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
        System.out.println("engine.getFactory().getEngineName() = " + engine.getFactory().getEngineName());

        String name = "script.js";
        String script = // load script from file;

        String json = // load response sample from file;

        Bindings bindings = new SimpleBindings();
        bindings.put("json", json);
        Map<String, String> result = (Map<String, String>) engine.eval(script, bindings);

        System.out.println("id = " + result.get("id"));
        System.out.println("url = " + result.get("url"));
    }
}
{code}

In the actual implementation we'd have to synchronize on the script engine because it may not be thread-safe (depends on the registered implementation).

[~nsawadsky] Can you elaborate on your security concern? In the example above, we ask the JS engine to parse a JSON string, we're not evaluating the JSON string. Doesn't that mitigate security risks?

> SWIFT_PING discovery protocol fatal error on OpenStack Kilo
> -----------------------------------------------------------
>
>                 Key: JGRP-1954
>                 URL: https://issues.jboss.org/browse/JGRP-1954
>             Project: JGroups
>          Issue Type: Bug
>    Affects Versions: 3.6.4
>         Environment: JGroups client running on Mac OS X - Yosemite
> JDK 1.7.71
> OpenStack Kilo
>            Reporter: Nick Sawadsky
>            Assignee: Bela Ban
>             Fix For: 3.6.5
>
>
> I'm attempting to use the SWIFT_PING discovery protocol on the most recent version of OpenStack, "Kilo". An error occurs during initialization of the protocol stack, the stack trace is provided below.
> The problem appears to be that support for XML-formatted responses has been removed in the OpenStack Identity API (http://developer.openstack.org/api-ref-identity-v2.html). Even though SWIFT_PING sends an Accept header of application/xml, the response still comes back as JSON (around line 286 of SWIFT_PING.java).
> I've been able to repro the issue using Postman in Chrome. I tried providing the *request* in XML , with a Content-Type header of application/xml, but Swift returns an error: "Expecting to find application/json in Content-Type header".
> It seems like the resolution would be for SWIFT_PING to be modified so it can parse the JSON response that it is receiving. If that sounds like a reasonable approach, I can try to create a patch that fixes the issue.
> Stack Trace:
> 2015-08-21 14:30:16,123  FATAL [com.pingidentity.common.util.ErrorHandler] Problem creating factory for multiplexed cluster communications
> org.xml.sax.SAXParseException: Content is not allowed in prolog.
> 	at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257) ~[?:1.8.0_25]
> 	at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:348) ~[?:1.8.0_25]
> 	at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121) ~[?:1.8.0_25]
> 	at org.jgroups.protocols.SWIFT_PING$Keystone_V_2_0_Auth.authenticate(SWIFT_PING.java:307) ~[jgroups.jar:3.6.4.Final]
> 	at org.jgroups.protocols.SWIFT_PING$SwiftClient.authenticate(SWIFT_PING.java:443) ~[jgroups.jar:3.6.4.Final]
> 	at org.jgroups.protocols.SWIFT_PING.init(SWIFT_PING.java:68) ~[jgroups.jar:3.6.4.Final]
> 	at org.jgroups.stack.ProtocolStack.initProtocolStack(ProtocolStack.java:860) ~[jgroups.jar:3.6.4.Final]
> 	at org.jgroups.stack.ProtocolStack.setup(ProtocolStack.java:481) ~[jgroups.jar:3.6.4.Final]
> 	at org.jgroups.JChannel.init(JChannel.java:854) ~[jgroups.jar:3.6.4.Final]
> 	at org.jgroups.JChannel.<init>(JChannel.java:159) ~[jgroups.jar:3.6.4.Final]
> 	at org.jgroups.JChannel.<init>(JChannel.java:120) ~[jgroups.jar:3.6.4.Final]



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


More information about the jboss-jira mailing list