You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oltu.apache.org by lm...@apache.org on 2011/06/09 14:55:51 UTC

svn commit: r1133842 - in /incubator/amber/trunk/oauth-2.0: ./ oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/ oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ oauth2-common/src/main/java/org/apache/...

Author: lmoren
Date: Thu Jun  9 12:55:48 2011
New Revision: 1133842

URL: http://svn.apache.org/viewvc?rev=1133842&view=rev
Log:
[AMBER-21] - Update dynamic client registration module to be compliant with the OAuth Dynamic Client Registration Protocol - PUSHED metadata

Added:
    incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/exception/OAuthRuntimeException.java
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/JSONHttpServletRequestWrapper.java
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PushPullValidator.java   (contents, props changed)
      - copied, changed from r1125333, incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PushValidator.java
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/java/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/amber/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/amber/oauth2/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/amber/oauth2/ext/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/amber/oauth2/ext/dynamicreg/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/amber/oauth2/ext/dynamicreg/server/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequestTest.java
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/push_invalid.json
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/push_valid.json
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/log4j.properties
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/pom.xml
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/main/
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/main/java/
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/main/java/org/
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/main/java/org/apache/
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/main/java/org/apache/amber/
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/main/java/org/apache/amber/oauth2/
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/main/java/org/apache/amber/oauth2/utils/
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/main/java/org/apache/amber/oauth2/utils/test/
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/main/java/org/apache/amber/oauth2/utils/test/FileUtils.java
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/test/
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/test/java/
    incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/test/resources/
Removed:
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PullValidator.java
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PushValidator.java
Modified:
    incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/OAuthRequest.java
    incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RegistrationController.java
    incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/utils/OAuthUtils.java
    incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/AbstractValidator.java
    incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/OAuthValidator.java
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/OAuthRegistrationClient.java
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-common/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/common/OAuthRegistration.java
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/pom.xml
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequest.java
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationTest.java
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/RegistrationEndpoint.java
    incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/BodyOAuthValidatorTest.java
    incubator/amber/trunk/oauth-2.0/pom.xml

Modified: incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/OAuthRequest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/OAuthRequest.java?rev=1133842&r1=1133841&r2=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/OAuthRequest.java (original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/main/java/org/apache/amber/oauth2/as/request/OAuthRequest.java Thu Jun  9 12:55:48 2011
@@ -31,6 +31,8 @@ import org.apache.amber.oauth2.common.ex
 import org.apache.amber.oauth2.common.exception.OAuthSystemException;
 import org.apache.amber.oauth2.common.utils.OAuthUtils;
 import org.apache.amber.oauth2.common.validators.OAuthValidator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
@@ -39,6 +41,8 @@ import org.apache.amber.oauth2.common.va
  */
 public abstract class OAuthRequest {
 
+    private Logger log = LoggerFactory.getLogger(OAuthRequest.class);
+
     protected HttpServletRequest request;
     protected OAuthValidator validator;
     protected Map<String, Class> validators = new HashMap<String, Class>();
@@ -58,9 +62,16 @@ public abstract class OAuthRequest {
             validator.validateContentType(request);
             validator.validateRequiredParameters(request);
         } catch (OAuthProblemException e) {
-            String redirectUri = request.getParameter(OAuth.OAUTH_REDIRECT_URI);
-            if (!OAuthUtils.isEmpty(redirectUri)) {
-                e.setRedirectUri(redirectUri);
+            try {
+                String redirectUri = request.getParameter(OAuth.OAUTH_REDIRECT_URI);
+                if (!OAuthUtils.isEmpty(redirectUri)) {
+                    e.setRedirectUri(redirectUri);
+                }
+            } catch (Exception ex) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Cannot read redirect_url from the request: {}",
+                        new String[] {ex.getMessage()});
+                }
             }
 
             throw e;

Modified: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RegistrationController.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RegistrationController.java?rev=1133842&r1=1133841&r2=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RegistrationController.java (original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RegistrationController.java Thu Jun  9 12:55:48 2011
@@ -73,7 +73,7 @@ public class RegistrationController {
                     .setName(oauthRegParams.getName())
                     .setUrl(oauthRegParams.getUrl())
                     .setDescription(oauthRegParams.getDescription())
-                    .setRedirectURI(oauthRegParams.getRedirectUri())
+                    .setRedirectURL(oauthRegParams.getRedirectUri())
                     .setIcon(oauthRegParams.getIcon())
                     .buildBodyMessage();
             }

Added: incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/exception/OAuthRuntimeException.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/exception/OAuthRuntimeException.java?rev=1133842&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/exception/OAuthRuntimeException.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/exception/OAuthRuntimeException.java Thu Jun  9 12:55:48 2011
@@ -0,0 +1,42 @@
+/**
+ *       Copyright 2011 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.amber.oauth2.common.exception;
+
+/**
+ * @author Lukasz Moren
+ */
+public class OAuthRuntimeException extends RuntimeException {
+    public OAuthRuntimeException() {
+        super();    //To change body of overridden methods use File | Settings | File Templates.
+    }
+
+    public OAuthRuntimeException(String message) {
+        super(message);    //To change body of overridden methods use File | Settings | File Templates.
+    }
+
+    public OAuthRuntimeException(String message, Throwable cause) {
+        super(message, cause);    //To change body of overridden methods use File | Settings | File Templates.
+    }
+
+    public OAuthRuntimeException(Throwable cause) {
+        super(cause);    //To change body of overridden methods use File | Settings | File Templates.
+    }
+}

Modified: incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/utils/OAuthUtils.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/utils/OAuthUtils.java?rev=1133842&r1=1133841&r2=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/utils/OAuthUtils.java (original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/utils/OAuthUtils.java Thu Jun  9 12:55:48 2011
@@ -24,6 +24,7 @@ package org.apache.amber.oauth2.common.u
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.Reader;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
@@ -68,6 +69,8 @@ public final class OAuthUtils {
 
     public static final String MULTIPART = "multipart/";
 
+    private static final String DEFAULT_CONTENT_CHARSET = ENCODING;
+
     /**
      * Translates parameters into <code>application/x-www-form-urlencoded</code> String
      *
@@ -113,24 +116,43 @@ public final class OAuthUtils {
      * @param is InputStream to be read
      * @return String that was read from the stream
      */
-    public static String saveStreamAsString(InputStream is) {
-        if (is != null) {
-            InputStreamReader ir = new InputStreamReader(is);
-            StringBuffer sb = new StringBuffer();
-
-            char[] buffer = new char[1000];
-            try {
-                while ((ir.read(buffer)) != -1) {
-                    sb.append(buffer);
-                }
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-            String string = sb.toString();
-            return string.trim();
+    public static String saveStreamAsString(InputStream is) throws IOException {
+        return toString(is, ENCODING);
+    }
+
+    /**
+     * Get the entity content as a String, using the provided default character set
+     * if none is found in the entity.
+     * If defaultCharset is null, the default "UTF-8" is used.
+     *
+     * @param is             input stream to be saved as string
+     * @param defaultCharset character set to be applied if none found in the entity
+     * @return the entity content as a String
+     * @throws IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE
+     * @throws IOException              if an error occurs reading the input stream
+     */
+    public static String toString(
+        final InputStream is, final String defaultCharset) throws IOException {
+        if (is == null) {
+            throw new IllegalArgumentException("InputStream may not be null");
         }
 
-        return null;
+        String charset = defaultCharset;
+        if (charset == null) {
+            charset = DEFAULT_CONTENT_CHARSET;
+        }
+        Reader reader = new InputStreamReader(is, charset);
+        StringBuilder sb = new StringBuilder();
+        int l;
+        try {
+            char[] tmp = new char[4096];
+            while ((l = reader.read(tmp)) != -1) {
+                sb.append(tmp, 0, l);
+            }
+        } finally {
+            reader.close();
+        }
+        return sb.toString();
     }
 
     /**
@@ -150,6 +172,7 @@ public final class OAuthUtils {
      * @param missingParams missing oauth parameters
      * @return OAuthProblemException with user friendly message about missing oauth parameters
      */
+
     public static OAuthProblemException handleMissingParameters(Set<String> missingParams) {
         StringBuffer sb = new StringBuffer("Missing parameters: ");
         if (!OAuthUtils.isEmpty(missingParams)) {
@@ -160,11 +183,10 @@ public final class OAuthUtils {
         return handleOAuthProblemException(sb.toString().trim());
     }
 
-    private static boolean isEmpty(Set<String> missingParams) {
-        if (missingParams == null || missingParams.size() == 0) {
-            return true;
-        }
-        return false;
+    public static OAuthProblemException handleBadContentTypeException(String expectedContentType) {
+        StringBuilder errorMsg = new StringBuilder("Bad request content type. Expecting: ").append(
+            expectedContentType);
+        return handleOAuthProblemException(errorMsg.toString());
     }
 
     public static OAuthProblemException handleNotAllowedParametersOAuthException(
@@ -260,6 +282,13 @@ public final class OAuthUtils {
         return (from == null) ? null : from.toString();
     }
 
+    private static boolean isEmpty(Set<String> missingParams) {
+        if (missingParams == null || missingParams.size() == 0) {
+            return true;
+        }
+        return false;
+    }
+
     public static Object instantiateClass(Class clazz) throws OAuthSystemException {
         try {
             return (Object)clazz.newInstance();

Modified: incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/AbstractValidator.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/AbstractValidator.java?rev=1133842&r1=1133841&r2=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/AbstractValidator.java (original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/AbstractValidator.java Thu Jun  9 12:55:48 2011
@@ -39,7 +39,7 @@ import org.apache.amber.oauth2.common.ut
  * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
  */
 //todo add client secret in header, sect 2.1
-public abstract class AbstractValidator implements OAuthValidator {
+public abstract class AbstractValidator<T extends HttpServletRequest> implements OAuthValidator<T> {
 
     protected List<String> requiredParams = new ArrayList<String>();
     protected Map<String, String[]> optionalParams = new HashMap<String, String[]>();
@@ -47,22 +47,23 @@ public abstract class AbstractValidator 
 
 
     @Override
-    public void validateMethod(HttpServletRequest request) throws OAuthProblemException {
+    public void validateMethod(T request) throws OAuthProblemException {
         if (!request.getMethod().equals(OAuth.HttpMethod.POST)) {
             throw OAuthUtils.handleOAuthProblemException("Method not set to POST.");
         }
     }
 
     @Override
-    public void validateContentType(HttpServletRequest request) throws OAuthProblemException {
+    public void validateContentType(T request) throws OAuthProblemException {
         String contentType = request.getContentType();
-        if (!OAuthUtils.hasContentType(contentType, OAuth.ContentType.URL_ENCODED)) {
-            throw OAuthUtils.handleOAuthProblemException("Bad content type.");
+        final String expectedContentType = OAuth.ContentType.URL_ENCODED;
+        if (!OAuthUtils.hasContentType(contentType, expectedContentType)) {
+            throw OAuthUtils.handleBadContentTypeException(expectedContentType);
         }
     }
 
     @Override
-    public void validateRequiredParameters(HttpServletRequest request) throws OAuthProblemException {
+    public void validateRequiredParameters(T request) throws OAuthProblemException {
         Set<String> missingParameters = new HashSet<String>();
         for (String requiredParam : requiredParams) {
             String val = request.getParameter(requiredParam);
@@ -76,7 +77,7 @@ public abstract class AbstractValidator 
     }
 
     @Override
-    public void validateOptionalParameters(HttpServletRequest request) throws OAuthProblemException {
+    public void validateOptionalParameters(T request) throws OAuthProblemException {
 
         Set<String> missingParameters = new HashSet<String>();
 
@@ -102,7 +103,7 @@ public abstract class AbstractValidator 
     }
 
     @Override
-    public void validateNotAllowedParameters(HttpServletRequest request) throws OAuthProblemException {
+    public void validateNotAllowedParameters(T request) throws OAuthProblemException {
         List<String> notAllowedParameters = new ArrayList<String>();
         for (String requiredParam : notAllowedParams) {
             String val = request.getParameter(requiredParam);
@@ -116,7 +117,7 @@ public abstract class AbstractValidator 
     }
 
     @Override
-    public void performAllValidations(HttpServletRequest request) throws OAuthProblemException {
+    public void performAllValidations(T request) throws OAuthProblemException {
         this.validateContentType(request);
         this.validateMethod(request);
         this.validateRequiredParameters(request);

Modified: incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/OAuthValidator.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/OAuthValidator.java?rev=1133842&r1=1133841&r2=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/OAuthValidator.java (original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/main/java/org/apache/amber/oauth2/common/validators/OAuthValidator.java Thu Jun  9 12:55:48 2011
@@ -30,18 +30,18 @@ import org.apache.amber.oauth2.common.ex
  * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
  * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
  */
-public interface OAuthValidator {
+public interface OAuthValidator<T extends HttpServletRequest> {
 
-    public void validateMethod(HttpServletRequest request) throws OAuthProblemException;
+    public void validateMethod(T request) throws OAuthProblemException;
 
-    public void validateContentType(HttpServletRequest request) throws OAuthProblemException;
+    public void validateContentType(T request) throws OAuthProblemException;
 
-    public void validateRequiredParameters(HttpServletRequest request) throws OAuthProblemException;
+    public void validateRequiredParameters(T request) throws OAuthProblemException;
 
-    public void validateOptionalParameters(HttpServletRequest request) throws OAuthProblemException;
+    public void validateOptionalParameters(T request) throws OAuthProblemException;
 
-    public void validateNotAllowedParameters(HttpServletRequest request) throws OAuthProblemException;
+    public void validateNotAllowedParameters(T request) throws OAuthProblemException;
 
-    public void performAllValidations(HttpServletRequest request) throws OAuthProblemException;
+    public void performAllValidations(T request) throws OAuthProblemException;
 
 }

Modified: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/OAuthRegistrationClient.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/OAuthRegistrationClient.java?rev=1133842&r1=1133841&r2=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/OAuthRegistrationClient.java (original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/OAuthRegistrationClient.java Thu Jun  9 12:55:48 2011
@@ -50,7 +50,7 @@ public class OAuthRegistrationClient ext
         throws IOException, OAuthSystemException, OAuthProblemException {
         String method = OAuth.HttpMethod.POST;
         Map<String, String> headers = new HashMap<String, String>();
-        headers.put(OAuth.HeaderType.CONTENT_TYPE, OAuth.ContentType.URL_ENCODED);
+        headers.put(OAuth.HeaderType.CONTENT_TYPE, OAuth.ContentType.JSON);
 
         return httpClient.execute(request, headers, method, OAuthClientRegistrationResponse.class);
     }

Modified: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java?rev=1133842&r1=1133841&r2=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java (original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java Thu Jun  9 12:55:48 2011
@@ -21,9 +21,10 @@
 
 package org.apache.amber.oauth2.ext.dynamicreg.client.request;
 
-import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration;
 import org.apache.amber.oauth2.client.request.OAuthClientRequest;
-import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.exception.OAuthSystemException;
+import org.apache.amber.oauth2.common.parameters.JSONBodyParametersApplier;
+import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration;
 
 
 /**
@@ -51,29 +52,35 @@ public class OAuthClientRegistrationRequ
         }
 
         public OAuthRegistrationRequestBuilder setName(String value) {
-            this.parameters.put(OAuthRegistration.Request.NAME, value);
+            this.parameters.put(OAuthRegistration.Request.CLIENT_NAME, value);
             return this;
         }
 
         public OAuthRegistrationRequestBuilder setUrl(String value) {
-            this.parameters.put(OAuthRegistration.Request.URL, value);
+            this.parameters.put(OAuthRegistration.Request.CLIENT_URL, value);
             return this;
         }
 
         public OAuthRegistrationRequestBuilder setDescription(String value) {
-            this.parameters.put(OAuthRegistration.Request.DESCRIPTION, value);
+            this.parameters.put(OAuthRegistration.Request.CLIENT_DESCRIPTION, value);
             return this;
         }
 
         public OAuthRegistrationRequestBuilder setIcon(String value) {
-            this.parameters.put(OAuthRegistration.Request.ICON, value);
+            this.parameters.put(OAuthRegistration.Request.CLIENT_ICON, value);
             return this;
         }
 
-        public OAuthRegistrationRequestBuilder setRedirectURI(String uri) {
-            this.parameters.put(OAuth.OAUTH_REDIRECT_URI, uri);
+        public OAuthRegistrationRequestBuilder setRedirectURL(String uri) {
+            this.parameters.put(OAuthRegistration.Request.REDIRECT_URL, uri);
             return this;
         }
 
+        public OAuthClientRequest buildJSONMessage() throws OAuthSystemException {
+            OAuthClientRequest request = new OAuthClientRegistrationRequest(url);
+            this.applier = new JSONBodyParametersApplier();
+            return (OAuthClientRequest)applier.applyOAuthParameters(request, parameters);
+        }
+
     }
 }

Modified: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-common/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/common/OAuthRegistration.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-common/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/common/OAuthRegistration.java?rev=1133842&r1=1133841&r2=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-common/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/common/OAuthRegistration.java (original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-common/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/common/OAuthRegistration.java Thu Jun  9 12:55:48 2011
@@ -43,11 +43,11 @@ public final class OAuthRegistration {
         }
 
         public static final String TYPE = "type";
-        public static final String NAME = "name";
-        public static final String URL = "url";
-        public static final String DESCRIPTION = "description";
-        public static final String ICON = "icon";
-        public static final String REDIRECT_URI = "redirect_uri";
+        public static final String CLIENT_NAME = "client_name";
+        public static final String CLIENT_URL = "client_url";
+        public static final String CLIENT_DESCRIPTION = "client_description";
+        public static final String CLIENT_ICON = "client_icon";
+        public static final String REDIRECT_URL = "redirect_url";
     }
 
     public static final class Response {

Modified: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/pom.xml
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/pom.xml?rev=1133842&r1=1133841&r2=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/pom.xml (original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/pom.xml Thu Jun  9 12:55:48 2011
@@ -22,17 +22,18 @@
 
 -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <artifactId>oauth2-dynamicreg-server</artifactId>
     <name>Apache Amber: OAuth 2.0 Implementation - Dynamic Registration Server</name>
     <packaging>jar</packaging>
-   <version>0.2-SNAPSHOT</version>
+    <version>0.2-SNAPSHOT</version>
 
     <parent>
         <artifactId>amber-oauth2-parent</artifactId>
         <groupId>org.apache.amber</groupId>
-       <version>0.2-SNAPSHOT</version>
+        <version>0.2-SNAPSHOT</version>
     </parent>
 
     <build>
@@ -56,6 +57,24 @@
             <artifactId>oauth2-dynamicreg-common</artifactId>
             <version>${project.version}</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.codehaus.jettison</groupId>
+            <artifactId>jettison</artifactId>
+            <version>${jettison.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>stax</groupId>
+                    <artifactId>stax-api</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.amber</groupId>
+            <artifactId>oauth2-test-utils</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
 </project>
 

Added: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/JSONHttpServletRequestWrapper.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/JSONHttpServletRequestWrapper.java?rev=1133842&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/JSONHttpServletRequestWrapper.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/JSONHttpServletRequestWrapper.java Thu Jun  9 12:55:48 2011
@@ -0,0 +1,122 @@
+/**
+ *       Copyright 2011 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.amber.oauth2.ext.dynamicreg.server.request;
+
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.exception.OAuthRuntimeException;
+import org.apache.amber.oauth2.common.utils.OAuthUtils;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Lukasz Moren
+ */
+public class JSONHttpServletRequestWrapper extends HttpServletRequestWrapper {
+    private Logger log = LoggerFactory.getLogger(JSONHttpServletRequestWrapper.class);
+    private JSONObject body;
+    private boolean bodyRead = false;
+
+    public JSONHttpServletRequestWrapper(HttpServletRequest request) {
+        super(request);
+    }
+
+    public String getParameter(String name) {
+        final String[] values = getParameterMap().get(name);
+        if (values == null || values.length == 0) {
+            return null;
+        }
+        return values[0];
+    }
+
+    public Map<String, String[]> getParameterMap() {
+        try {
+            readJsonBody();
+            Map<String, String[]> parameters = new HashMap<String, String[]>();
+
+            if (body != null) {
+                final JSONArray attributeNames = body.names();
+                for (int i = 0; i < attributeNames.length(); i++) {
+                    final String attributeName = attributeNames.getString(i);
+                    final String attributeValue = body.getString(attributeName);
+
+                    parameters.put(attributeName, new String[] {attributeValue});
+                }
+            }
+
+            return Collections.unmodifiableMap(parameters);
+        } catch (JSONException e) {
+            log.error("Dynamic client registration error: ", e);
+            throw new OAuthRuntimeException("OAuth server error");
+        }
+    }
+
+    public Enumeration getParameterNames() {
+        return Collections.enumeration(getParameterMap().keySet());
+    }
+
+    public String[] getParameterValues(String name) {
+        return getParameterMap().get(name);
+    }
+
+    /**
+     * Lazily read JSON from request
+     *
+     * @throws OAuthProblemException
+     */
+    private void readJsonBody() {
+        if (!bodyRead) {
+            bodyRead = true;
+            try {
+                final ServletRequest request = getRequest();
+                String contentType = request.getContentType();
+                final String expectedContentType = OAuth.ContentType.JSON;
+                if (!OAuthUtils.hasContentType(contentType, expectedContentType)) {
+                    return;
+                }
+
+                final ServletInputStream inputStream = request.getInputStream();
+                if (inputStream == null) {
+                    return;
+                }
+                final String jsonString = OAuthUtils.saveStreamAsString(inputStream);
+                body = new JSONObject(jsonString);
+            } catch (JSONException e) {
+                log.error("Cannot decode request body as a JSON: ", e);
+            } catch (Exception e) {
+                log.error("Dynamic client registration error: ", e);
+                throw new OAuthRuntimeException("OAuth server error");
+            }
+        }
+    }
+}

Modified: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequest.java?rev=1133842&r1=1133841&r2=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequest.java (original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequest.java Thu Jun  9 12:55:48 2011
@@ -24,13 +24,11 @@ package org.apache.amber.oauth2.ext.dyna
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.amber.oauth2.common.exception.OAuthSystemException;
-import org.apache.amber.oauth2.common.utils.OAuthUtils;
 import org.apache.amber.oauth2.common.validators.OAuthValidator;
 import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration;
 import org.apache.amber.oauth2.as.request.OAuthRequest;
 import org.apache.amber.oauth2.common.exception.OAuthProblemException;
-import org.apache.amber.oauth2.ext.dynamicreg.server.validator.PullValidator;
-import org.apache.amber.oauth2.ext.dynamicreg.server.validator.PushValidator;
+import org.apache.amber.oauth2.ext.dynamicreg.server.validator.PushPullValidator;
 
 
 /**
@@ -44,12 +42,12 @@ public class OAuthServerRegistrationRequ
 
     private boolean isDiscovered;
 
-    public OAuthServerRegistrationRequest(HttpServletRequest request)
+    public OAuthServerRegistrationRequest(JSONHttpServletRequestWrapper request)
         throws OAuthSystemException, OAuthProblemException {
         this(request, false);
     }
 
-    public OAuthServerRegistrationRequest(HttpServletRequest request, boolean discover)
+    public OAuthServerRegistrationRequest(JSONHttpServletRequestWrapper request, boolean discover)
         throws OAuthSystemException, OAuthProblemException {
         super(request);
         if (discover) {
@@ -59,17 +57,7 @@ public class OAuthServerRegistrationRequ
 
     @Override
     protected OAuthValidator initValidator() throws OAuthProblemException, OAuthSystemException {
-        validators.put(OAuthRegistration.Type.PULL, PullValidator.class);
-        validators.put(OAuthRegistration.Type.PUSH, PushValidator.class);
-        type = getParam(OAuthRegistration.Request.TYPE);
-        if (OAuthUtils.isEmpty(type)) {
-            throw OAuthUtils.handleOAuthProblemException("Missing type parameter value");
-        }
-        Class clazz = validators.get(type);
-        if (clazz == null) {
-            throw OAuthUtils.handleOAuthProblemException("Invalid type parameter value");
-        }
-        return (OAuthValidator)OAuthUtils.instantiateClass(clazz);
+        return new PushPullValidator();
     }
 
     public void discover() throws OAuthSystemException {
@@ -83,24 +71,24 @@ public class OAuthServerRegistrationRequ
         return getParam(OAuthRegistration.Request.TYPE);
     }
 
-    public String getName() {
-        return getParam(OAuthRegistration.Request.NAME);
+    public String getClientName() {
+        return getParam(OAuthRegistration.Request.CLIENT_NAME);
     }
 
-    public String getUrl() {
-        return getParam(OAuthRegistration.Request.URL);
+    public String getClientUrl() {
+        return getParam(OAuthRegistration.Request.CLIENT_URL);
     }
 
-    public String getDescription() {
-        return getParam(OAuthRegistration.Request.DESCRIPTION);
+    public String getClientDescription() {
+        return getParam(OAuthRegistration.Request.CLIENT_DESCRIPTION);
     }
 
-    public String getIcon() {
-        return getParam(OAuthRegistration.Request.ICON);
+    public String getClientIcon() {
+        return getParam(OAuthRegistration.Request.CLIENT_ICON);
     }
 
     public String getRedirectURI() {
-        return getParam(OAuthRegistration.Request.REDIRECT_URI);
+        return getParam(OAuthRegistration.Request.REDIRECT_URL);
     }
 
     public boolean isDiscovered() {

Copied: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PushPullValidator.java (from r1125333, incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PushValidator.java)
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PushPullValidator.java?p2=incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PushPullValidator.java&p1=incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PushValidator.java&r1=1125333&r2=1133842&rev=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PushValidator.java (original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PushPullValidator.java Thu Jun  9 12:55:48 2011
@@ -21,20 +21,64 @@
 
 package org.apache.amber.oauth2.ext.dynamicreg.server.validator;
 
-import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration;
+import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.utils.OAuthUtils;
 import org.apache.amber.oauth2.common.validators.AbstractValidator;
+import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration;
+import org.apache.amber.oauth2.ext.dynamicreg.server.request.JSONHttpServletRequestWrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
  * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
  * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
  */
-public class PushValidator extends AbstractValidator {
+public class PushPullValidator extends AbstractValidator<JSONHttpServletRequestWrapper> {
+
+    private Logger log = LoggerFactory.getLogger(PushPullValidator.class);
+
+    public PushPullValidator() {
+
+    }
+
+    public void validateContentType(JSONHttpServletRequestWrapper request) throws OAuthProblemException {
+
+        String contentType = request.getContentType();
+        final String expectedContentType = OAuth.ContentType.JSON;
+        if (!OAuthUtils.hasContentType(contentType, expectedContentType)) {
+            throw OAuthUtils.handleBadContentTypeException(expectedContentType);
+        }
+
+//        if content type is json initialize validator for pull or push method based on json content
+        initializeValidationParameter(request);
+
+    }
+
+    private void initializeValidationParameter(JSONHttpServletRequestWrapper request)
+        throws OAuthProblemException {
+        final String requestType = request.getParameter(OAuthRegistration.Request.TYPE);
+
+        if (OAuthUtils.isEmpty(requestType)) {
+            throw OAuthUtils.handleOAuthProblemException("Missing [type] parameter value");
+        }
+
+        if (OAuthRegistration.Type.PULL.equals(requestType)) {
+            requiredParams.add(OAuthRegistration.Request.TYPE);
+            requiredParams.add(OAuthRegistration.Request.CLIENT_URL);
+        } else if (OAuthRegistration.Type.PUSH.equals(requestType)) {
+            requiredParams.add(OAuthRegistration.Request.TYPE);
+            requiredParams.add(OAuthRegistration.Request.CLIENT_NAME);
+            requiredParams.add(OAuthRegistration.Request.CLIENT_URL);
+            requiredParams.add(OAuthRegistration.Request.CLIENT_DESCRIPTION);
+            requiredParams.add(OAuthRegistration.Request.REDIRECT_URL);
+        } else {
+            throw OAuthUtils.handleOAuthProblemException("Invalid [type] parameter value");
+        }
 
-    public PushValidator() {
-        requiredParams.add(OAuthRegistration.Request.TYPE);
-        requiredParams.add(OAuthRegistration.Request.NAME);
-        requiredParams.add(OAuthRegistration.Request.URL);
-        requiredParams.add(OAuthRegistration.Request.DESCRIPTION);
+        if (log.isDebugEnabled()) {
+            log.debug("OAuth dynamic client registration type is: {}", new String[] {requestType});
+        }
     }
 }

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/validator/PushPullValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequestTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequestTest.java?rev=1133842&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequestTest.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/OAuthServerRegistrationRequestTest.java Thu Jun  9 12:55:48 2011
@@ -0,0 +1,84 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.amber.oauth2.ext.dynamicreg.server.request;
+
+import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.utils.test.FileUtils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+/**
+ * @author Lukasz Moren
+ */
+public class OAuthServerRegistrationRequestTest {
+
+    @Test
+    public void testValidOAuthPushRequest() throws Exception {
+        final String validJson = FileUtils.readTextFileAsString("json/push_valid.json");
+
+        MockHttpServletRequest request = new MockHttpServletRequest("POST", "/oauth/register");
+        request.setContentType(OAuth.ContentType.JSON);
+        request.setContent(validJson.getBytes("UTF-8"));
+
+        final JSONHttpServletRequestWrapper jsonWrapper = new JSONHttpServletRequestWrapper(request);
+        OAuthServerRegistrationRequest registrationRequest = new OAuthServerRegistrationRequest(jsonWrapper);
+
+        Assert.assertEquals("Uploading and also editing capabilities!",
+            registrationRequest.getClientDescription());
+        Assert.assertEquals("http://onlinephotogallery.com/icon.png", registrationRequest.getClientIcon());
+        Assert.assertEquals("Online Photo Gallery", registrationRequest.getClientName());
+        Assert
+            .assertEquals("https://onlinephotogallery.com/client_reg", registrationRequest.getRedirectURI());
+        Assert.assertEquals("push", registrationRequest.getType());
+        Assert.assertEquals("http://onlinephotogallery.com", registrationRequest.getClientUrl());
+    }
+
+    @Test(expected = OAuthProblemException.class)
+    public void testInvalidContentTypePushRequest() throws Exception {
+        MockHttpServletRequest request = new MockHttpServletRequest("POST", "/oauth/register");
+        request.setContentType(OAuth.ContentType.URL_ENCODED);
+
+        final JSONHttpServletRequestWrapper jsonWrapper = new JSONHttpServletRequestWrapper(request);
+        OAuthServerRegistrationRequest registrationRequest = new OAuthServerRegistrationRequest(jsonWrapper);
+    }
+
+    @Test(expected = OAuthProblemException.class)
+    public void testInvalidMethodPushRequest() throws Exception {
+        MockHttpServletRequest request = new MockHttpServletRequest("GET", "/oauth/register");
+        request.setContentType(OAuth.ContentType.JSON);
+
+        final JSONHttpServletRequestWrapper jsonWrapper = new JSONHttpServletRequestWrapper(request);
+        OAuthServerRegistrationRequest registrationRequest = new OAuthServerRegistrationRequest(jsonWrapper);
+    }
+
+    @Test(expected = OAuthProblemException.class)
+    public void testInvalidBodyPushRequest() throws Exception {
+        final String inValidJson = FileUtils.readTextFileAsString("json/push_invalid.json");
+        MockHttpServletRequest request = new MockHttpServletRequest("POST", "/oauth/register");
+        request.setContentType(OAuth.ContentType.JSON);
+        request.setContent(inValidJson.getBytes("UTF-8"));
+
+        final JSONHttpServletRequestWrapper jsonWrapper = new JSONHttpServletRequestWrapper(request);
+        OAuthServerRegistrationRequest registrationRequest = new OAuthServerRegistrationRequest(jsonWrapper);
+    }
+}

Added: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/push_invalid.json
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/push_invalid.json?rev=1133842&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/push_invalid.json (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/push_invalid.json Thu Jun  9 12:55:48 2011
@@ -0,0 +1,5 @@
+{
+    "type": "push",
+    "client_icon": "http://onlinephotogallery.com/icon.png",
+    "redirect_url": "https://onlinephotogallery.com/client_reg"
+}
\ No newline at end of file

Added: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/push_valid.json
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/push_valid.json?rev=1133842&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/push_valid.json (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/json/push_valid.json Thu Jun  9 12:55:48 2011
@@ -0,0 +1,8 @@
+{
+    "type": "push",
+    "client_name": "Online Photo Gallery",
+    "client_url":  "http://onlinephotogallery.com",
+    "client_description": "Uploading and also editing capabilities!",
+    "client_icon": "http://onlinephotogallery.com/icon.png",
+    "redirect_url": "https://onlinephotogallery.com/client_reg"
+}
\ No newline at end of file

Added: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/log4j.properties?rev=1133842&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/log4j.properties (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-server/src/test/resources/log4j.properties Thu Jun  9 12:55:48 2011
@@ -0,0 +1,29 @@
+#
+#       Copyright 2010 Newcastle University
+#
+#          http://research.ncl.ac.uk/smart/
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+log4j.rootCategory=INFO, CONSOLE
+
+# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.ConversionPattern=[%d{yyyy-mm-dd hh:mm:ss.S},%6.6r]%-5p[%t]%x(%F:%L) - %m%n
+
+log4j.logger.org.apache.amber.oauth2=DEBUG
\ No newline at end of file

Modified: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationTest.java?rev=1133842&r1=1133841&r2=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationTest.java (original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationTest.java Thu Jun  9 12:55:48 2011
@@ -47,8 +47,8 @@ public class ClientRegistrationTest exte
             .setUrl(CommonExt.APP_URL)
             .setDescription(CommonExt.APP_DESCRIPTION)
             .setIcon(CommonExt.APP_ICON)
-            .setRedirectURI(CommonExt.APP_REDIRECT_URI)
-            .buildBodyMessage();
+            .setRedirectURL(CommonExt.APP_REDIRECT_URI)
+            .buildJSONMessage();
 
         OAuthRegistrationClient oauthclient = new OAuthRegistrationClient(new URLConnectionClient());
         OAuthClientRegistrationResponse response = oauthclient.clientInfo(request);
@@ -69,7 +69,7 @@ public class ClientRegistrationTest exte
             .setUrl(CommonExt.APP_URL)
             .setDescription(CommonExt.APP_DESCRIPTION)
             .setIcon(CommonExt.APP_ICON)
-            .setRedirectURI(CommonExt.APP_REDIRECT_URI)
+            .setRedirectURL(CommonExt.APP_REDIRECT_URI)
             .buildBodyMessage();
 
         OAuthRegistrationClient oauthclient = new OAuthRegistrationClient(new URLConnectionClient());

Modified: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/RegistrationEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/RegistrationEndpoint.java?rev=1133842&r1=1133841&r2=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/RegistrationEndpoint.java (original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/RegistrationEndpoint.java Thu Jun  9 12:55:48 2011
@@ -32,6 +32,7 @@ import javax.ws.rs.core.Response;
 
 import org.apache.amber.oauth2.common.exception.OAuthSystemException;
 import org.apache.amber.oauth2.common.message.OAuthResponse;
+import org.apache.amber.oauth2.ext.dynamicreg.server.request.JSONHttpServletRequestWrapper;
 import org.apache.amber.oauth2.ext.dynamicreg.server.request.OAuthServerRegistrationRequest;
 import org.apache.amber.oauth2.ext.dynamicreg.server.response.OAuthServerRegistrationResponse;
 import org.apache.amber.oauth2.common.exception.OAuthProblemException;
@@ -47,18 +48,18 @@ public class RegistrationEndpoint {
 
 
     @POST
-    @Consumes("application/x-www-form-urlencoded")
+    @Consumes("application/json")
     @Produces("application/json")
     public Response register(@Context HttpServletRequest request) throws OAuthSystemException {
 
 
         OAuthServerRegistrationRequest oauthRequest = null;
         try {
-            oauthRequest = new OAuthServerRegistrationRequest(request);
+            oauthRequest = new OAuthServerRegistrationRequest(new JSONHttpServletRequestWrapper(request));
             oauthRequest.discover();
-            oauthRequest.getName();
-            oauthRequest.getUrl();
-            oauthRequest.getDescription();
+            oauthRequest.getClientName();
+            oauthRequest.getClientUrl();
+            oauthRequest.getClientDescription();
             oauthRequest.getRedirectURI();
 
             OAuthResponse response = OAuthServerRegistrationResponse

Modified: incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/BodyOAuthValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/BodyOAuthValidatorTest.java?rev=1133842&r1=1133841&r2=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/BodyOAuthValidatorTest.java (original)
+++ incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/BodyOAuthValidatorTest.java Thu Jun  9 12:55:48 2011
@@ -90,7 +90,7 @@ public class BodyOAuthValidatorTest {
             Assert.fail("Exception not thrown.");
         } catch (OAuthProblemException e) {
             Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
-            Assert.assertEquals("Bad content type.", e.getDescription());
+            Assert.assertEquals("Bad request content type. Expecting: application/x-www-form-urlencoded", e.getDescription());
         }
         verify(request);
     }

Added: incubator/amber/trunk/oauth-2.0/oauth2-test-utils/pom.xml
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-test-utils/pom.xml?rev=1133842&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-test-utils/pom.xml (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-test-utils/pom.xml Thu Jun  9 12:55:48 2011
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+          Copyright 2010 Newcastle University
+
+             http://research.ncl.ac.uk/smart/
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You 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.
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>oauth2-test-utils</artifactId>
+    <name>Apache Amber: OAuth 2.0 Implementation - Test Utils</name>
+    <packaging>jar</packaging>
+    <version>0.2-SNAPSHOT</version>
+
+    <parent>
+        <artifactId>amber-oauth2-parent</artifactId>
+        <groupId>org.apache.amber</groupId>
+        <version>0.2-SNAPSHOT</version>
+    </parent>
+
+    <build>
+        <finalName>oauth2-test-utils</finalName>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-core</artifactId>
+            <version>${spring.version}</version>
+        </dependency>
+    </dependencies>
+</project>
+

Added: incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/main/java/org/apache/amber/oauth2/utils/test/FileUtils.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/main/java/org/apache/amber/oauth2/utils/test/FileUtils.java?rev=1133842&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/main/java/org/apache/amber/oauth2/utils/test/FileUtils.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-test-utils/src/main/java/org/apache/amber/oauth2/utils/test/FileUtils.java Thu Jun  9 12:55:48 2011
@@ -0,0 +1,46 @@
+/**
+ *       Copyright 2011 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.amber.oauth2.utils.test;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+/**
+ * @author Lukasz Moren
+ */
+public class FileUtils {
+    private FileUtils() {
+    }
+
+    public static String readTextFileAsString(String fileName) throws IOException {
+        URL inputStream = ClassLoader.getSystemResource(fileName);
+        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream.openStream()));
+
+        String line;
+        StringBuffer buffer = new StringBuffer();
+        while ((line = br.readLine()) != null) {
+            buffer.append(line);
+        }
+        return buffer.toString();
+    }
+}

Modified: incubator/amber/trunk/oauth-2.0/pom.xml
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/pom.xml?rev=1133842&r1=1133841&r2=1133842&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/pom.xml (original)
+++ incubator/amber/trunk/oauth-2.0/pom.xml Thu Jun  9 12:55:48 2011
@@ -30,7 +30,7 @@
     <version>0.2-SNAPSHOT</version>
     <modelVersion>4.0.0</modelVersion>
     <packaging>pom</packaging>
-    
+
     <parent>
         <groupId>org.apache.amber</groupId>
         <artifactId>amber-parent</artifactId>
@@ -48,6 +48,7 @@
         <module>oauth2-resourceserver</module>
         <module>oauth2-rs-filter</module>
         <module>oauth2-dynamicreg-server</module>
+        <module>oauth2-test-utils</module>
         <module>oauth2-integration-tests</module>
     </modules>