Removed the ApiKeys REST API from Wookie 2.x as this is no longer consistent with the new security model which relies on secrets not being transmitted over HTTP; if admins want to manage keys on the server remotely they need to do so via SSH, VPN etc.
git-svn-id: https://svn.apache.org/repos/asf/wookie/trunk@1576635 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/wookie-connector/java/src/main/java/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java b/wookie-connector/java/src/main/java/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java
index ceab972..2f60283 100644
--- a/wookie-connector/java/src/main/java/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java
+++ b/wookie-connector/java/src/main/java/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java
@@ -538,87 +538,6 @@
}
}
-
- /**
- * Gets a list of all the api keys registered in wookie
- * @param adminUsername
- * @param adminPassword
- * @return
- * @throws WookieConnectorException
- * @throws IOException
- */
- public List<ApiKey> getAPIKeys() throws WookieConnectorException, IOException {
-
- SignedApiRequest request = SignedApiRequest.GET(conn.getURL()+"/keys", conn.getApiKey(), conn.getSecret());
- request.execute();
-
- ArrayList<ApiKey> keys = new ArrayList<ApiKey>();
- try {
- Document doc = parseInputStreamAsDocument ( request.getResponseBodyAsStream() );
- Element rootElement = doc.getDocumentElement();
- NodeList keyNodes = rootElement.getElementsByTagName("key");
- for ( int i = 0; i < keyNodes.getLength(); i++ ) {
- Element keyElement = (Element) keyNodes.item(i);
- ApiKey key = new ApiKey (
- keyElement.getTextContent(),
- null);
- keys.add(key);
- }
- }
- catch ( MalformedURLException e ) {
- throw new WookieConnectorException ( "Bad url: ", e);
- }
- catch (ParserConfigurationException e) {
- e.printStackTrace();
- throw new WookieConnectorException ( "Problem parsing data returned by Wookie: ", e);
- }
- catch (SAXException e) {
- e.printStackTrace();
- throw new WookieConnectorException ( "Problem parsing data returned by Wookie: ", e);
- }
- return keys;
- }
-
-
- /**
- * Creates a new api key
- * @param newKey
- * @param adminUsername
- * @param adminPassword
- * @throws WookieConnectorException
- */
- public void createApiKey ( ApiKey newKey) throws WookieConnectorException {
-
- SignedApiRequest request = SignedApiRequest.POST(conn.getURL()+"/keys", conn.getApiKey(), conn.getSecret());
- request.addParameter("apikey", newKey.getKey());
- request.addParameter("email", newKey.getSecret());
- try {
- request.execute();
- } catch (IOException e) {
- throw new WookieConnectorException("Problem adding an apikey.", e);
- }
- if (request.getStatusCode() != 201){
- throw new WookieConnectorException("Problem adding an apikey. ", new IOException("Error:"+request.getStatusCode()));
- }
- }
-
-
- /**
- * Deletes a specified key
- * @param key
- * @throws IOException
- * @throws WookieConnectorException
- */
- public void removeApiKey ( ApiKey key) throws IOException, WookieConnectorException {
- SignedApiRequest request = SignedApiRequest.DELETE(conn.getURL()+"/keys/"+key.getKey(), conn.getApiKey(), conn.getSecret());
- request.execute();
- if ( request.getStatusCode() != 200 ) {
- throw new IOException ("Problem DELETEing from /keys");
- }
- }
-
-
-
/**
* Returns a full list of policies
* @param adminUsername
diff --git a/wookie-connector/java/src/main/java/org/apache/wookie/connector/framework/ApiKey.java b/wookie-connector/java/src/main/java/org/apache/wookie/connector/framework/ApiKey.java
deleted file mode 100644
index 3758731..0000000
--- a/wookie-connector/java/src/main/java/org/apache/wookie/connector/framework/ApiKey.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wookie.connector.framework;
-
-public class ApiKey {
-
- private String key;
- private String secret;
-
-
-
- public ApiKey ( String key, String secret ) {
- this.key = key;
- this.secret = secret;
- }
-
-
- /**
- * @return the key
- */
- public String getKey() {
- return key;
- }
- /**
- * @param key the key to set
- */
- public void setKey(String key) {
- this.key = key;
- }
- /**
- * @return the secret
- */
- public String getSecret() {
- return secret;
- }
- /**
- * @param email the email to set
- */
- public void setSecret(String secret) {
- this.secret = secret;
- }
-
-
-
-}
diff --git a/wookie-connector/java/src/test/java/org/apache/wookie/tests/connector/framework/impl/WookieConnectorService.java b/wookie-connector/java/src/test/java/org/apache/wookie/tests/connector/framework/impl/WookieConnectorService.java
index da5c5ff..910bf6d 100644
--- a/wookie-connector/java/src/test/java/org/apache/wookie/tests/connector/framework/impl/WookieConnectorService.java
+++ b/wookie-connector/java/src/test/java/org/apache/wookie/tests/connector/framework/impl/WookieConnectorService.java
@@ -21,9 +21,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
-import java.util.ListIterator;
-import org.apache.wookie.connector.framework.ApiKey;
import org.apache.wookie.connector.framework.Policy;
import org.apache.wookie.connector.framework.User;
import org.apache.wookie.connector.framework.Widget;
@@ -237,32 +235,6 @@
@Test
- public void apikeys() throws IOException, WookieConnectorException {
-
- List<ApiKey> apikeys = service.getAPIKeys();
- int apikeysLength = apikeys.size();
- assertTrue ( "Unable to get api keys", ( apikeysLength > 0));
- ApiKey newKey = new ApiKey ("tester", "test@test.com" );
- service.createApiKey(newKey);
-
- apikeys = service.getAPIKeys();
-
- boolean foundKey = false;
- ListIterator<ApiKey> li = apikeys.listIterator();
- while (li.hasNext()) {
- ApiKey akey = li.next();
- if ( akey.getKey().equals("tester")) {
- foundKey = true;
- }
- }
- assertTrue ( "New key not created", foundKey );
-
- service.removeApiKey(newKey);
- assertEquals ( service.getAPIKeys().size(), apikeysLength);
- }
-
-
- @Test
public void policyTest ( ) throws IOException, WookieConnectorException {
List<Policy> policies = service.getPolicies(null);
diff --git a/wookie-server/src/main/java/org/apache/wookie/controller/ApiKeyController.java b/wookie-server/src/main/java/org/apache/wookie/controller/ApiKeyController.java
deleted file mode 100644
index aef3646..0000000
--- a/wookie-server/src/main/java/org/apache/wookie/controller/ApiKeyController.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.wookie.controller;
-
-import java.io.IOException;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.log4j.Logger;
-import org.apache.wookie.exceptions.InvalidParametersException;
-import org.apache.wookie.exceptions.ResourceDuplicationException;
-import org.apache.wookie.exceptions.ResourceNotFoundException;
-import org.apache.wookie.exceptions.UnauthorizedAccessException;
-import org.apache.wookie.helpers.ApiKeyHelper;
-import org.apache.wookie.server.security.ApiKeys;
-
-/**
- * Admin controller for creating, updating and listing API keys
- *
- * <ul>
- * <li>GET /keys - index <em>requires authentication</em></li>
- * <li>POST /keys {apikey, email} - create <em>requires authentication</em></li>
- * <li>PUT /keys/{id} {apikey, email} - update <em>requires authentication</em></li>
- * <li>DELETE /keys/{id} - remove <em>requires authentication</em></li>
- * </ul>
- *
- * Note that PUT support is disabled until a solution is available for migrating
- * widget instances, shared data and participants
- */
-
-public class ApiKeyController extends Controller {
-
- private static final long serialVersionUID = -2985087125119757793L;
- static Logger _logger = Logger.getLogger(ApiKeyController.class.getName());
-
- /* (non-Javadoc)
- * @see org.apache.wookie.controller.Controller#index(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
- */
- @Override
- protected void index(HttpServletRequest request, HttpServletResponse response)
- throws UnauthorizedAccessException, IOException {
- switch (format(request)) {
- case XML: returnXml(ApiKeyHelper.toXml(ApiKeys.getInstance().getKeys()),response);break;
- case JSON: returnJson(ApiKeyHelper.toJson(ApiKeys.getInstance().getKeys()),response);break;
- default: returnXml(ApiKeyHelper.toXml(ApiKeys.getInstance().getKeys()),response);break;
- }
- }
-
- /* (non-Javadoc)
- * @see org.apache.wookie.controller.Controller#create(java.lang.String, javax.servlet.http.HttpServletRequest)
- */
- @Override
- protected boolean create(String resourceId, HttpServletRequest request, HttpServletResponse response)
- throws ResourceDuplicationException, InvalidParametersException,
- UnauthorizedAccessException {
- String value = request.getParameter("apikey");
- String email = request.getParameter("email");
- if (value == null || email == null || value.trim().length() ==0 || email.trim().length() == 0) throw new InvalidParametersException();
-
- try {
- ApiKeys.getInstance().addKey(value, email);
- _logger.info("New API key registered for "+email);
- } catch (Exception e) {
- throw new ResourceDuplicationException();
- }
-
- return true;
- }
-
-
-/*
- @Override
- protected void update(String resourceId, HttpServletRequest request)
- throws ResourceNotFoundException, InvalidParametersException,
- UnauthorizedAccessException {
-
- String value = request.getParameter("apikey");
- String email = request.getParameter("email");
- if (value == null || email == null || value.trim().length() ==0 || email.trim().length() == 0) throw new InvalidParametersException();
-
- IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
- IApiKey apiKey = persistenceManager.findById(IApiKey.class, resourceId);
- if (apiKey == null) throw new ResourceNotFoundException();
- String oldValue = apiKey.getValue();
- String oldEmail = apiKey.getEmail();
- apiKey.setEmail(email);
- apiKey.setValue(value);
- persistenceManager.save(apiKey);
- migrateWidgetInstances(apiKey, oldValue);
- _logger.info("API key updated from "+oldEmail+" : "+oldValue + " to "+email + " : "+value);
-
- }
-*/
-
-
- /**
- * Migrates any widget instances using the previous key to the new key.
- * @param key
- * @param oldValue
- */
- /*
- private void migrateWidgetInstances(IApiKey apiKey, String oldValue){
- IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
- //
- IWidgetInstance[] instances = persistenceManager.findByValue(IWidgetInstance.class, "apiKey", oldValue);
- for (IWidgetInstance instance: instances){
- //FIXME this doesn't really work right now because we can't migrate the shared data key. To do
- // this we would need to store both the original shared data key and the internal version in the WidgetInstance or
- // somewhere. (We then ought to rename one of them to make it clear which it is). We could then transparently
- // update all the sharedDataKeys for instances, participants and shared data
- instance.setApiKey(apiKey.getValue());
- persistenceManager.save(instance);
- }
- }
- */
-
- /* (non-Javadoc)
- * @see org.apache.wookie.controller.Controller#remove(java.lang.String, javax.servlet.http.HttpServletRequest)
- */
- @Override
- protected boolean remove(String resourceId, HttpServletRequest request)
- throws ResourceNotFoundException, UnauthorizedAccessException,
- InvalidParametersException {
-
- ApiKeys.getInstance().removeKey(resourceId);
- _logger.info("API key deleted: "+resourceId);
- return true;
- }
-
-}
diff --git a/wookie-server/src/main/webapp/WEB-INF/web.xml b/wookie-server/src/main/webapp/WEB-INF/web.xml
index 0f7e7d3..7d7ef9e 100644
--- a/wookie-server/src/main/webapp/WEB-INF/web.xml
+++ b/wookie-server/src/main/webapp/WEB-INF/web.xml
@@ -140,20 +140,6 @@
<servlet-name>PropertiesServlet</servlet-name>
<url-pattern>/properties</url-pattern>
</servlet-mapping>
-
- <servlet>
- <description></description>
- <display-name>ApiKeys</display-name>
- <servlet-name>ApiKeyController</servlet-name>
- <servlet-class>
- org.apache.wookie.controller.ApiKeyController
- </servlet-class>
- <load-on-startup>2</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>ApiKeyController</servlet-name>
- <url-pattern>/keys/*</url-pattern>
- </servlet-mapping>
<servlet>
<description></description>
@@ -338,10 +324,6 @@
<filter-name>AuthorizationFilter</filter-name>
<servlet-name>PoliciesServlet</servlet-name>
</filter-mapping>
- <filter-mapping>
- <filter-name>AuthorizationFilter</filter-name>
- <servlet-name>ApiKeyController</servlet-name>
- </filter-mapping>
<filter-mapping>
<filter-name>AuthorizationFilter</filter-name>
<servlet-name>UpdatesServlet</servlet-name>
diff --git a/wookie-server/src/test/java/org/apache/wookie/tests/functional/ApiKeyControllerTest.java b/wookie-server/src/test/java/org/apache/wookie/tests/functional/ApiKeyControllerTest.java
deleted file mode 100644
index d26b564..0000000
--- a/wookie-server/src/test/java/org/apache/wookie/tests/functional/ApiKeyControllerTest.java
+++ /dev/null
@@ -1,411 +0,0 @@
-/*
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.wookie.tests.functional;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.util.Map;
-
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.wookie.tests.helpers.Request;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.JDOMException;
-import org.jdom.input.SAXBuilder;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.mortbay.util.ajax.JSON;
-
-/**
- * Functional tests for API key management
- */
-public class ApiKeyControllerTest extends AbstractControllerTest {
-
- private static final String APIKEY_SERVICE_LOCATION_VALID = TEST_SERVER_LOCATION + "keys";
-
- /**
- * Attempt to get the list of API keys without having authenticated first
- *
- * @throws IOException
- * @throws HttpException
- */
- @Test
- public void getEntriesUnauthorized() throws HttpException, IOException {
- Request request = new Request("GET", APIKEY_SERVICE_LOCATION_VALID);
- request.execute(false, false);
- assertEquals(403, request.getStatusCode());
- }
-
- /**
- * Get the set of API keys using default admin credentials
- *
- * @throws IOException
- * @throws HttpException
- */
- @Test
- public void getKeys() throws HttpException, IOException {
- Request request = new Request("GET", APIKEY_SERVICE_LOCATION_VALID);
- request.execute(true, false);
- assertEquals(200, request.getStatusCode());
- }
-
- /**
- * Get the set of API keys in JSON using default admin credentials
- *
- * @throws IOException
- * @throws HttpException
- */
- @SuppressWarnings("unchecked")
- @Test
- public void getKeysJson() throws HttpException, IOException {
-
- Request request = new Request("GET", APIKEY_SERVICE_LOCATION_VALID);
- request.setAccepts("application/json");
- request.execute(true, false);
- assertEquals(200, request.getStatusCode());
-
- String response = request.getResponseBodyAsString();
- //
- // Parse the response and check the values
- //
- Object[] keys = (Object[]) JSON.parse(response);
- assertEquals("TEST", ((Map<String, String>)keys[0]).get("key"));
-
- //
- // Try again using ?format param overriding the accepts header
- //
- Request request2 = new Request("GET", APIKEY_SERVICE_LOCATION_VALID);
- request2.setAccepts("text/xml");
- request2.addParameter("format", "json");
- request2.execute(true, false);
- assertEquals(200, request2.getStatusCode());
-
- //
- // Parse the response and check the values
- //
- keys = (Object[]) JSON.parse(request2.getResponseBodyAsString());
- assertEquals("TEST", ((Map<String, String>)keys[0]).get("key"));
- }
-
- /**
- * Add a new key
- *
- * @throws IOException
- * @throws HttpException
- */
- @Test
- public void addKey() throws HttpException, IOException {
-
- //
- // POST a new API key
- //
- Request request = new Request("POST", APIKEY_SERVICE_LOCATION_VALID);
- request.addParameter("apikey", "TEST_KEY");
- request.addParameter("email", "test@incubator.apache.org");
- request.execute(true, false);
- int code = request.getStatusCode();
- assertEquals(201, code);
-
- //
- // Test that the set of API keys includes the one we just POSTed
- //
- request = new Request("GET", APIKEY_SERVICE_LOCATION_VALID);
- request.execute(true, false);
- code = request.getStatusCode();
- assertEquals(200, code);
- assertTrue(request.getResponseBodyAsString().contains("TEST_KEY"));
-
- //
- // Remove the key
- //
- request = new Request("DELETE", APIKEY_SERVICE_LOCATION_VALID+"/"+"TEST_KEY");
- request.execute(true, false);
- code = request.getStatusCode();
- assertEquals(200, code);
- }
-
- /**
- * Remove a key
- *
- * @throws IOException
- * @throws JDOMException
- */
- @Test
- public void removeKey() throws JDOMException, IOException {
- String id = null;
-
- //
- // Create a new API key
- //
- Request request = new Request("POST", APIKEY_SERVICE_LOCATION_VALID);
- request.addParameter("apikey", "TEST_KEY_TO_REMOVE");
- request.addParameter("email", "test@incubator.apache.org");
- request.execute(true, false);
- int code = request.getStatusCode();
- assertEquals(201, code);
-
- request = new Request("GET", APIKEY_SERVICE_LOCATION_VALID);
- request.execute(true, false);
- code = request.getStatusCode();
- assertEquals(200, code);
- assertTrue(request.getResponseBodyAsString().contains("TEST_KEY_TO_REMOVE"));
-
- //
- // Get the ID of the key we created
- //
- Document doc = new SAXBuilder().build(request.getResponseBodyAsStream());
- for (Object key : doc.getRootElement().getChildren()) {
- Element keyElement = (Element) key;
- if (keyElement.getText().equals("TEST_KEY_TO_REMOVE")) {
- id = keyElement.getText();
- }
- }
-
- //
- // Delete the API key
- //
- request = new Request("DELETE", APIKEY_SERVICE_LOCATION_VALID+"/"+id);
- request.execute(true, false);
- code = request.getStatusCode();
- assertEquals(200, code);
-
- //
- // Check that the key was deleted
- //
- request = new Request("GET", APIKEY_SERVICE_LOCATION_VALID);
- request.execute(true, false);
- code = request.getStatusCode();
- assertEquals(200, code);
- assertFalse(request.getResponseBodyAsString().contains("TEST_KEY_TO_REMOVE"));
-
- }
-
- /**
- * Try to remove a non-existant API key
- *
- * @throws HttpException
- * @throws IOException
- */
- @Test
- public void removeNonExistantEntry() throws HttpException, IOException {
- Request request = new Request("DELETE", APIKEY_SERVICE_LOCATION_VALID+"/99999999");
- request.execute(true, false);
- int code = request.getStatusCode();
- assertEquals(404, code);
- }
-
- /**
- * Create an API key with missing parameters
- *
- * @throws IOException
- * @throws HttpException
- */
- @Test
- public void addEntryNoEmailOrValue() throws HttpException, IOException {
- Request request = new Request("POST", APIKEY_SERVICE_LOCATION_VALID);
- request.execute(true, false);
- int code = request.getStatusCode();
- assertEquals(400, code);
- }
-
- /**
- * Try to create a new API key that duplicates an existing one
- *
- * @throws IOException
- * @throws HttpException
- * @throws JDOMException
- */
- @Test
- public void addDuplicateEntry() throws HttpException, IOException, JDOMException {
-
- //
- // Create an API key
- //
- Request request = new Request("POST", APIKEY_SERVICE_LOCATION_VALID);
- request.addParameter("apikey", "DUPLICATION_TEST");
- request.addParameter("email", "test@127.0.0.1");
- request.execute(true, false);
- int code = request.getStatusCode();
- assertEquals(201, code);
-
- //
- // Replay the POST
- //
- request.execute(true, false);
- code = request.getStatusCode();
- assertEquals(409, code);
-
- String id = null;
-
- //
- // Clean up
- //
-
- request = new Request("GET",APIKEY_SERVICE_LOCATION_VALID);
- request.execute(true, false);
- code = request.getStatusCode();
- assertEquals(200, code);
- assertTrue(request.getResponseBodyAsString().contains("DUPLICATION_TEST"));
-
- //
- // Get the ID of the key we created
- //
- Document doc = new SAXBuilder().build(request.getResponseBodyAsStream());
- for (Object key : doc.getRootElement().getChildren()) {
- Element keyElement = (Element) key;
- if (keyElement.getText().equals("DUPLICATION_TEST")) {
- id = keyElement.getText();
- }
- }
-
- //
- // Delete the API key
- //
- request = new Request("DELETE",APIKEY_SERVICE_LOCATION_VALID+"/"+id);
- request.execute(true, false);
- code = request.getStatusCode();
- assertEquals(200, code);
-
- //
- // Check that the key was deleted
- //
- request = new Request("GET",APIKEY_SERVICE_LOCATION_VALID);
- request.execute(true, false);
- code = request.getStatusCode();
- assertEquals(200, code);
- assertFalse(request.getResponseBodyAsString().contains("DUPLICATION_TEST"));
- }
-
- /**
- * Complex test for migrating an API key. This test is disabled as there are
- * issues implementing this functionality - for now, migration has been
- * disabled in the REST API.
- *
- * @throws IOException
- * @throws HttpException
- * @throws JDOMException
- */
- @Test
- @Ignore
- public void migrateAPIKey() throws HttpException, IOException, JDOMException {
-
- String keyId = null;
-
- //
- // Create a new key
- //
- HttpClient client = new HttpClient();
- PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
- setAuthenticationCredentials(client);
- post.setParameter("apikey", "MIGRATION_TEST_KEY_1");
- post.setParameter("email", "test@incubator.apache.org");
- client.executeMethod(post);
- int code = post.getStatusCode();
- assertEquals(201, code);
-
- //
- // Get the ID
- //
- GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
- setAuthenticationCredentials(client);
- client.executeMethod(get);
- Document doc = new SAXBuilder().build(get.getResponseBodyAsStream());
- for (Object key : doc.getRootElement().getChildren()) {
- Element keyElement = (Element) key;
- if (keyElement.getAttributeValue("value").equals("MIGRATION_TEST_KEY_1")) {
- keyId = keyElement.getAttributeValue("id");
- }
- }
-
- //
- // Create a widget instance
- //
- String instance_id_key = null;
- client = new HttpClient();
- post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
- post.setQueryString("api_key=MIGRATION_TEST_KEY_1&widgetid="
- + WIDGET_ID_VALID + "&userid=test&shareddatakey=migration_test");
- client.executeMethod(post);
- code = post.getStatusCode();
- String response = post.getResponseBodyAsString();
- instance_id_key = post.getResponseBodyAsString().substring(
- response.indexOf("<identifier>") + 12,
- response.indexOf("</identifier>"));
- assertEquals(201, code);
- post.releaseConnection();
-
- //
- // Set participant
- //
- client = new HttpClient();
- post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
- post.setQueryString("api_key=MIGRATION_TEST_KEY_1&widgetid="
- + WIDGET_ID_VALID
- + "&userid=test&shareddatakey=migration_test&participant_id=1&participant_display_name=bob&participant_thumbnail_url=http://www.test.org");
- client.executeMethod(post);
- code = post.getStatusCode();
- assertEquals(201, code);
- post.releaseConnection();
-
- //
- // Migrate key
- //
- client = new HttpClient();
- PutMethod put = new PutMethod(APIKEY_SERVICE_LOCATION_VALID + "/" + keyId);
- put.setQueryString("apikey=MIGRATION_TEST_KEY_2&email=test@127.0.0.1");
- setAuthenticationCredentials(client);
- client.executeMethod(put);
- code = put.getStatusCode();
- assertEquals(200, code);
- put.releaseConnection();
-
- //
- // Get instance again using the new key - should be 200 not 201
- //
- client = new HttpClient();
- post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
- post.setQueryString("api_key=MIGRATION_TEST_KEY_2&widgetid="
- + WIDGET_ID_VALID + "&userid=test&shareddatakey=migration_test");
- client.executeMethod(post);
- code = post.getStatusCode();
- assertEquals(200, code);
- post.releaseConnection();
-
- //
- // Get participant
- //
- client = new HttpClient();
- get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
- get.setQueryString("api_key=MIGRATION_TEST_KEY_2&id_key=" + instance_id_key);
- client.executeMethod(get);
- code = get.getStatusCode();
- assertEquals(200, code);
- response = get.getResponseBodyAsString();
- assertTrue(response
- .contains("<participant id=\"1\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" />"));
- get.releaseConnection();
-
- }
-}