Author: [email protected]
Date: Tue Jul 19 14:52:30 2011
New Revision: 1220
Log:
[AMDATUAUTH-68] Added authorization checks and performed other small
improvements
Added:
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/bean/
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/bean/ConsumerBean.java
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/bean/ConsumersBean.java
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/bean/ResultBean.java
Removed:
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthResultBean.java
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthServiceConsumerBean.java
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthServiceConsumersBean.java
Modified:
trunk/amdatu-auth/oauth-api/src/main/java/org/amdatu/authentication/oauth/api/OAuthServiceConsumer.java
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthServiceConsumerRegistryRESTImpl.java
trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/register.jsp
trunk/amdatu-auth/oauth-example/pom.xml
trunk/amdatu-auth/oauth-example/src/main/java/org/amdatu/example/oauth/service/OAuthGadgetsRegistrationServiceImpl.java
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/OAuthServiceConsumerRegistryTest.java
Modified:
trunk/amdatu-auth/oauth-api/src/main/java/org/amdatu/authentication/oauth/api/OAuthServiceConsumer.java
==============================================================================
---
trunk/amdatu-auth/oauth-api/src/main/java/org/amdatu/authentication/oauth/api/OAuthServiceConsumer.java
(original)
+++
trunk/amdatu-auth/oauth-api/src/main/java/org/amdatu/authentication/oauth/api/OAuthServiceConsumer.java
Tue Jul 19 14:52:30 2011
@@ -75,9 +75,7 @@
* @return The URL to which a user will be redirected after a request
token has been authorized.
*/
String getCallbackUrl();
-
- void setCallbackUrl(String callbackUrl);
-
+
/**
* Map of arbitrary additional properties stored in the service consumer.
This could for example be used
* to associated a service consumer with subscribed tenants.
Added:
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/bean/ConsumerBean.java
==============================================================================
--- (empty file)
+++
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/bean/ConsumerBean.java
Tue Jul 19 14:52:30 2011
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * 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.amdatu.authentication.oauth.consumerregistry.bean;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.amdatu.authentication.oauth.api.OAuthServiceConsumer;
+import org.amdatu.libraries.utilities.rest.AtomSyndicationLink;
+import org.apache.commons.beanutils.BeanUtils;
+
+@XmlRootElement(name = "consumer")
+@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
+/**
+ * Implementation of JAXB bean used by the oAuth service consumer registry
REST service.
+ */
+public class ConsumerBean implements OAuthServiceConsumer {
+
+ private String m_consumerKey;
+
+ private String m_consumerSecret;
+
+ private String m_name;
+
+ private String m_callbackUrl;
+
+ private Map<String, String> m_properties;
+
+ private List<AtomSyndicationLink> m_links;
+
+ public String getConsumerKey() {
+ return m_consumerKey;
+ }
+
+ public void setConsumerKey(final String consumerKey) {
+ m_consumerKey = consumerKey;
+ }
+
+ public String getConsumerSecret() {
+ return m_consumerSecret;
+ }
+
+ public void setConsumerSecret(final String consumerSecret) {
+ m_consumerSecret = consumerSecret;
+ }
+
+ public String getName() {
+ return m_name;
+ }
+
+ public void setName(final String name) {
+ m_name = name;
+ }
+
+ public String getCallbackUrl() {
+ return m_callbackUrl;
+ }
+
+ public void setCallbackUrl(final String callbackUrl) {
+ m_callbackUrl = callbackUrl;
+ }
+
+ public Map<String, String> getProperties() {
+ return m_properties;
+ }
+
+ public void setProperties(final Map<String, String> properties) {
+ m_properties = properties;
+ }
+
+ public void addProperty(String key, String value) {
+ if (m_properties == null) {
+ m_properties = new HashMap<String, String>();
+ }
+ m_properties.put(key, value);
+ }
+
+ @XmlElementWrapper(name="links")
+ @XmlElements(@XmlElement(name="link"))
+ public List<AtomSyndicationLink> getLinks() {
+ return m_links;
+ }
+
+ public void setLinks(final List<AtomSyndicationLink> links) {
+ m_links = links;
+ }
+
+ public void addLink(final String href, final String rel, final String
type) {
+ if (m_links == null) {
+ m_links = new ArrayList<AtomSyndicationLink>();
+ }
+ m_links.add(new
AtomSyndicationLink().setRel(rel).setHref(href).setType(type));
+ }
+
+ public static ConsumerBean copy(final OAuthServiceConsumer consumer)
+ throws IllegalAccessException, InvocationTargetException {
+ ConsumerBean bean = new ConsumerBean();
+ BeanUtils.copyProperties(bean, consumer);
+ return bean;
+ }
+
+}
Added:
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/bean/ConsumersBean.java
==============================================================================
--- (empty file)
+++
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/bean/ConsumersBean.java
Tue Jul 19 14:52:30 2011
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * 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.amdatu.authentication.oauth.consumerregistry.bean;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+
+@XmlRootElement(name = "consumers")
+@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
+public class ConsumersBean {
+ @XmlElement(name = "consumer")
+ private List<ConsumerBean> m_consumers;
+
+ public List<ConsumerBean> getConsumers() {
+ return m_consumers;
+ }
+
+ public void setConsumers(final List<ConsumerBean> consumers) {
+ m_consumers = consumers;
+ }
+
+ public void addConsumer(ConsumerBean consumer) {
+ if (m_consumers == null) {
+ m_consumers = new ArrayList<ConsumerBean>();
+ }
+ m_consumers.add(consumer);
+ }
+}
Added:
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/bean/ResultBean.java
==============================================================================
--- (empty file)
+++
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/bean/ResultBean.java
Tue Jul 19 14:52:30 2011
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * 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.amdatu.authentication.oauth.consumerregistry.bean;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "result")
+@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
+public class ResultBean {
+ private String m_message;
+
+ public String getMessage() {
+ return m_message;
+ }
+
+ public void setMessage(String message) {
+ m_message = message;
+ }
+}
Modified:
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthServiceConsumerRegistryRESTImpl.java
==============================================================================
---
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthServiceConsumerRegistryRESTImpl.java
(original)
+++
trunk/amdatu-auth/oauth-consumerregistry/src/main/java/org/amdatu/authentication/oauth/consumerregistry/service/OAuthServiceConsumerRegistryRESTImpl.java
Tue Jul 19 14:52:30 2011
@@ -44,6 +44,9 @@
import org.amdatu.authentication.oauth.api.OAuthServiceConsumer;
import
org.amdatu.authentication.oauth.consumerregistry.OAuthServiceConsumerRegistry;
import
org.amdatu.authentication.oauth.consumerregistry.OAuthServiceConsumerRegistryREST;
+import org.amdatu.authentication.oauth.consumerregistry.bean.ConsumerBean;
+import org.amdatu.authentication.oauth.consumerregistry.bean.ConsumersBean;
+import org.amdatu.authentication.oauth.consumerregistry.bean.ResultBean;
import org.amdatu.authentication.tokenprovider.InvalidTokenException;
import org.amdatu.authentication.tokenprovider.TokenProvider;
import org.amdatu.authentication.tokenprovider.TokenProviderException;
@@ -131,7 +134,7 @@
}
/**
- * REST interface: GET /rest/oauth/consumers/{consumerKey}
+ * REST interface: GET /rest/oauth/consumers
* Returns the requested consumer in application/xml or application/json
format.
*
* @param consumerKey
@@ -148,18 +151,32 @@
}
String filter = "(" + OAuthServiceConsumer.OWNERID + "=" +
user.getName() + ")";
Iterator<OAuthServiceConsumer> consumers =
m_registry.getConsumers(filter);
- OAuthServiceConsumersBean bean = new OAuthServiceConsumersBean();
+ ConsumersBean bean = new ConsumersBean();
while (consumers.hasNext()) {
OAuthServiceConsumer consumer = consumers.next();
- OAuthServiceConsumerBean consumerBean =
OAuthServiceConsumerBean.copy(consumer);
- consumerBean.setEditLink(ALIAS + "/" +
consumer.getConsumerKey());
+ ConsumerBean consumerBean = ConsumerBean.copy(consumer);
+ consumerBean.addLink(ALIAS + "/" + consumer.getConsumerKey(),
"edit", null);
+ consumerBean.addLink(ALIAS + "/" + consumer.getConsumerKey() +
"?alt=xml", "alternate", "application/xml");
+ consumerBean.addLink(ALIAS + "/" + consumer.getConsumerKey() +
"?alt=json", "alternate", "application/json");
bean.addConsumer(consumerBean);
}
return Response.ok(bean).cacheControl(NO_CACHE_CONTROL).build();
}
- catch (Exception e) {
+ catch (InvalidTokenException e) {
+ return
Response.status(HttpStatus.SC_UNAUTHORIZED).cacheControl(NO_CACHE_CONTROL).build();
+ }
+ catch (ConsumerRegistryStorageException e) {
+ throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
+ }
+ catch (TokenProviderException e) {
+ throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
+ }
+ catch (IllegalAccessException e) {
+ throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
+ }
+ catch (InvocationTargetException e) {
throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
- }
+ }
}
/**
@@ -173,25 +190,32 @@
@GET
@Path("{consumerKey}")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
- public Response getConsumer(@PathParam("consumerKey") final String
consumerKey, @Context final UriInfo uriInfo) {
- try {
+ public Response getConsumer(@Context final HttpServletRequest request,
+ @PathParam("consumerKey") final String consumerKey, @Context final
UriInfo uriInfo) {
+ try {
+ if (!isAuthorized(request)) {
+ return
Response.status(HttpStatus.SC_UNAUTHORIZED).cacheControl(NO_CACHE_CONTROL).build();
+ }
OAuthServiceConsumer consumer =
m_registry.getConsumer(consumerKey);
- if (consumer != null) {
- return
Response.ok(OAuthServiceConsumerBean.copy(consumer)).cacheControl(NO_CACHE_CONTROL)
- .build();
+ if (consumer != null) {
+ ConsumerBean consumerBean = ConsumerBean.copy(consumer);
+ consumerBean.addLink(ALIAS + "/" + consumer.getConsumerKey(),
"edit", null);
+ consumerBean.addLink(ALIAS + "/" + consumer.getConsumerKey() +
"?alt=xml", "alternate", "application/xml");
+ consumerBean.addLink(ALIAS + "/" + consumer.getConsumerKey() +
"?alt=json", "alternate", "application/json");
+ return
Response.ok(consumerBean).cacheControl(NO_CACHE_CONTROL).build();
}
else {
return
Response.status(HttpStatus.SC_NOT_FOUND).cacheControl(NO_CACHE_CONTROL).build();
}
}
- catch (IllegalAccessException e) {
- throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
- }
catch (InvocationTargetException e) {
throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
- }
- catch (ConsumerRegistryStorageException e) {
- throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
+ }
+ catch (ConsumerRegistryStorageException e) {
+ throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
+ }
+ catch (IllegalAccessException e) {
+ throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
}
}
@@ -203,14 +227,17 @@
*/
@PUT
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
- public Response addConsumer(final OAuthServiceConsumerBean consumer) {
- try {
+ public Response addConsumerJSONXML(@Context final HttpServletRequest
request, final ConsumerBean consumer) {
+ try {
+ if (!isAuthorized(request)) {
+ return
Response.status(HttpStatus.SC_UNAUTHORIZED).cacheControl(NO_CACHE_CONTROL).build();
+ }
m_registry.addConsumer(consumer);
return Response.ok().cacheControl(NO_CACHE_CONTROL).build();
}
catch (ConsumerAlreadyExistsException e) {
throw new WebApplicationException(Response.Status.NOT_MODIFIED);
- }
+ }
catch (ConsumerRegistryStorageException e) {
throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
}
@@ -226,7 +253,7 @@
@POST
@Consumes("application/x-www-form-urlencoded")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
- public Response createConsumer(@Context final HttpServletRequest request,
+ public Response addConsumerFormEncoded(@Context final HttpServletRequest
request,
@FormParam("name") final String name, @FormParam("callbackurl") final
String callbackUrl) {
try {
// First check if the user is authorized to register applications
@@ -238,7 +265,7 @@
OAuthServiceConsumer existingConsumer =
m_registry.getConsumerByName(name);
if (existingConsumer != null) {
// In case a consumer with this name already exists, we return
a 400 (bad request)
- OAuthResultBean bean = new OAuthResultBean();
+ ResultBean bean = new ResultBean();
bean.setMessage("The Application could not be registered, the
name '"
+ existingConsumer.getName() + "' is already in use.
Register your application with a different name.");
return
Response.status(HttpStatus.SC_BAD_REQUEST).cacheControl(NO_CACHE_CONTROL).entity(bean).build();
@@ -246,20 +273,22 @@
// Verify that the callback URL starts with http, https or equals
'oob'
if (!callbackUrl.startsWith("http://") &&
!callbackUrl.startsWith("https://") && !"oob".equals(callbackUrl)) {
- OAuthResultBean bean = new OAuthResultBean();
+ ResultBean bean = new ResultBean();
bean.setMessage("The callback URL is invalid. The callback URL
must start with 'http://', 'https://' or equal 'oob'.");
return
Response.status(HttpStatus.SC_BAD_REQUEST).cacheControl(NO_CACHE_CONTROL).entity(bean).build();
}
// Generate a new consumer key and secret for this consumer
- OAuthServiceConsumerBean consumer = new OAuthServiceConsumerBean();
+ ConsumerBean consumer = new ConsumerBean();
consumer.setConsumerKey(generateNonce());
consumer.setConsumerSecret(generateNonce());
consumer.setName(name);
consumer.setCallbackUrl(callbackUrl);
// Add the edit link
- consumer.setEditLink(ALIAS + "/" + consumer.getConsumerKey());
+ consumer.addLink(ALIAS + "/" + consumer.getConsumerKey(), "edit",
"");
+ consumer.addLink(ALIAS + "/" + consumer.getConsumerKey() +
"?alt=xml", "alternate", "application/xml");
+ consumer.addLink(ALIAS + "/" + consumer.getConsumerKey() +
"?alt=json", "alternate", "application/json");
consumer.addProperty(OAuthServiceConsumer.OWNERID,
getCurrentUser(request).getName());
m_registry.addConsumer(consumer);
@@ -286,10 +315,14 @@
@PUT
@Consumes("application/x-www-form-urlencoded")
@Path("{consumerKey}")
- public Response updateConsumer(@PathParam("consumerKey") final String
consumerKey,
+ public Response updateConsumer(@Context final HttpServletRequest request,
@PathParam("consumerKey") final String consumerKey,
@FormParam("callbackurl") final String callbackUrl) {
- try {
- OAuthServiceConsumer consumer =
m_registry.getConsumer(consumerKey);
+ try {
+ if (!isAuthorized(request)) {
+ return
Response.status(HttpStatus.SC_UNAUTHORIZED).cacheControl(NO_CACHE_CONTROL).build();
+ }
+ OAuthServiceConsumer oriConsumer =
m_registry.getConsumer(consumerKey);
+ ConsumerBean consumer = ConsumerBean.copy(oriConsumer);
consumer.setCallbackUrl(callbackUrl);
m_registry.updateConsumer(consumer);
return Response.ok().cacheControl(NO_CACHE_CONTROL).build();
@@ -299,15 +332,24 @@
}
catch (ConsumerRegistryStorageException e) {
throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
+ }
+ catch (IllegalAccessException e) {
+ throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
+ }
+ catch (InvocationTargetException e) {
+ throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
}
}
@PUT
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Path("{consumerKey}")
- public Response updateConsumerWithBean(@PathParam("consumerKey") final
String consumerKey,
- final OAuthServiceConsumerBean consumer) {
+ public Response updateConsumerWithBean(@Context final HttpServletRequest
request,@PathParam("consumerKey") final String consumerKey,
+ final ConsumerBean consumer) {
try {
+ if (!isAuthorized(request)) {
+ return
Response.status(HttpStatus.SC_UNAUTHORIZED).cacheControl(NO_CACHE_CONTROL).build();
+ }
m_registry.updateConsumer(consumer);
return Response.ok().cacheControl(NO_CACHE_CONTROL).build();
}
@@ -327,8 +369,11 @@
*/
@DELETE
@Path("{consumerKey}")
- public Response deleteConsumer(@PathParam("consumerKey") final String
consumerKey) {
- try {
+ public Response deleteConsumer(@Context final HttpServletRequest request,
@PathParam("consumerKey") final String consumerKey) {
+ try {
+ if (!isAuthorized(request)) {
+ return
Response.status(HttpStatus.SC_UNAUTHORIZED).cacheControl(NO_CACHE_CONTROL).build();
+ }
m_registry.removeConsumer(m_registry.getConsumer(consumerKey));
return Response.ok().cacheControl(NO_CACHE_CONTROL).build();
}
Modified:
trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/register.jsp
==============================================================================
---
trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/register.jsp
(original)
+++
trunk/amdatu-auth/oauth-consumerregistry/src/main/resources/jsp/register.jsp
Tue Jul 19 14:52:30 2011
@@ -201,15 +201,15 @@
dataType: "json",
async:true,
success: function(data, textStatus, jqXHR) {
- var consumers = jQuery.parseJSON(jqXHR.responseText).result.consumers;
+ var consumers =
jQuery.parseJSON(jqXHR.responseText).consumers.consumer;
if (typeof consumers != 'undefined') {
var html = "<ul>";
if (typeof consumers.length == 'undefined') {
- html += "<li><a href=\"#\" onclick=\"javascript:editApplication('"
+ consumers.editLink.href + "');\">" + consumers.name + "</a></li>";
+ html += "<li><a href=\"#\" onclick=\"javascript:editApplication('"
+ getEditLink(consumers) + "');\">" + consumers.name + "</a></li>";
}
else {
for (i=0; i<consumers.length; i++) {
- html += "<li><a href=\"#\"
onclick=\"javascript:editApplication('" + consumers[i].editLink.href + "');\">"
+ consumers[i].name + "</a></li>";
+ html += "<li><a href=\"#\"
onclick=\"javascript:editApplication('" + getEditLink(consumers[i]) + "');\">"
+ consumers[i].name + "</a></li>";
}
};
html += "</ul>";
@@ -224,6 +224,16 @@
});
}
+ function getEditLink(consumer) {
+ var links = consumer.links.link;
+ for (j=0; j<links.length; j++) {
+ if (links[j].rel == "edit") {
+ return links[j].href;
+ }
+ }
+ return "";
+ }
+
function editApplication(url) {
showDiv("editApp");
jQuery.ajax({
Modified: trunk/amdatu-auth/oauth-example/pom.xml
==============================================================================
--- trunk/amdatu-auth/oauth-example/pom.xml (original)
+++ trunk/amdatu-auth/oauth-example/pom.xml Tue Jul 19 14:52:30 2011
@@ -76,6 +76,11 @@
<type>bundle</type>
</dependency>
<dependency>
+ <groupId>org.amdatu.auth</groupId>
+ <artifactId>org.amdatu.auth.oauth.consumerregistry</artifactId>
+ <type>bundle</type>
+ </dependency>
+ <dependency>
<groupId>org.amdatu.web</groupId>
<artifactId>org.amdatu.web.jaxrs</artifactId>
<type>bundle</type>
Modified:
trunk/amdatu-auth/oauth-example/src/main/java/org/amdatu/example/oauth/service/OAuthGadgetsRegistrationServiceImpl.java
==============================================================================
---
trunk/amdatu-auth/oauth-example/src/main/java/org/amdatu/example/oauth/service/OAuthGadgetsRegistrationServiceImpl.java
(original)
+++
trunk/amdatu-auth/oauth-example/src/main/java/org/amdatu/example/oauth/service/OAuthGadgetsRegistrationServiceImpl.java
Tue Jul 19 14:52:30 2011
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2010, 2011 The Amdatu Foundation
- *
+ *
* 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
@@ -33,12 +33,12 @@
/**
* This service registers the oAuth example gadgets.
- *
+ *
* @author ivol
*/
public class OAuthGadgetsRegistrationServiceImpl implements ResourceProvider {
private final static GadgetCategory AMDATU_EXAMPLE_CATEGORY = new
GadgetCategory("amdatu_examples", "Amdatu Examples");
-
+
// oAuth properties of this gadget as service consumer
private final static String CONSUMER_CALLBACK_URL =
"/gadgets/oauthcallback";
private final static String CONSUMER_KEY = "example.amdatu.org";
@@ -120,7 +120,7 @@
class InternalOAuthServiceConsumer implements OAuthServiceConsumer {
public String getCallbackUrl() {
return CONSUMER_CALLBACK_URL;
- }
+ }
public String getConsumerKey() {
return CONSUMER_KEY;
@@ -134,7 +134,7 @@
return CONSUMER_NAME;
}
- public Map<String, Object> getProperties() {
+ public Map<String, String> getProperties() {
return null;
}
}
Modified:
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/OAuthServiceConsumerRegistryTest.java
==============================================================================
---
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/OAuthServiceConsumerRegistryTest.java
(original)
+++
trunk/amdatu-auth/test-integration/tests/src/test/java/org/amdatu/auth/test/integration/tests/OAuthServiceConsumerRegistryTest.java
Tue Jul 19 14:52:30 2011
@@ -54,6 +54,17 @@
OAuthTestConsumer consumer = new OAuthTestConsumer();
int statusCode = putConsumer(httpClient, "application/json", consumer,
false);
Assert.assertTrue("OAuth Service Consumer registry REST service
returns " + statusCode + " on addConsumer",
+ statusCode == HttpStatus.SC_UNAUTHORIZED);
+
+ // Log in using an Amdatu account, just after creating it
+ m_logService.log(LogService.LOG_DEBUG, "*** Step 4: Log in with Amdatu
account '" + AuthTest.TEST_USERNAME
+ + "' ***");
+ AuthUtils.addTestUser(m_userAdmin);
+ login();
+
+ // And try again, now we should be authorized
+ statusCode = putConsumer(httpClient, "application/json", consumer,
false);
+ Assert.assertTrue("OAuth Service Consumer registry REST service
returns " + statusCode + " on addConsumer",
statusCode == HttpStatus.SC_OK || statusCode ==
HttpStatus.SC_NOT_MODIFIED);
// Retrieve the new consumer in XML and JSON format
@@ -96,7 +107,13 @@
String url = m_baseUrl + CONSUMERS_REST_RESOURCE;
GetMethod getMethod = new GetMethod(url + "/" + consumerKey);
try {
- // We want JSON!
+ // We want JSON!
+ if (getCookieHeader() != null) {
+ for (String key : getCookieHeader().keySet()) {
+ getMethod.addRequestHeader(key,
getCookieHeader().get(key));
+ }
+ }
+
getMethod.setRequestHeader("Accept", mimeType);
int statusCode = httpClient.executeMethod(getMethod);
Assert.assertTrue("OAuth Service Consumer registry REST service
returns " + statusCode + " on getConsumer",
@@ -134,7 +151,13 @@
m_logService.log(LogService.LOG_DEBUG, "Adding consumer for " +
mimeType + ", url=" + (update ? url + "/"
+ consumer.getConsumerKey() : url) + ", input=" + body);
RequestEntity requestEntity = new StringRequestEntity(body, mimeType,
"UTF-8");
- method.setRequestEntity(requestEntity);
+ method.setRequestEntity(requestEntity);
+
+ if (getCookieHeader() != null) {
+ for (String key : getCookieHeader().keySet()) {
+ method.addRequestHeader(key, getCookieHeader().get(key));
+ }
+ }
// Execute the method, this should return a 200
try {
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits