incubator-amber-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1050671 [1/2] - in /incubator/amber/trunk/oauth-2.0/oauth2-integration-tests: ./ src/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/amber/ src/test/java/org/apache/amber/oauth2/ src/test/jav...
Date Sat, 18 Dec 2010 17:02:44 GMT
Author: tommaso
Date: Sat Dec 18 17:02:42 2010
New Revision: 1050671

URL: http://svn.apache.org/viewvc?rev=1050671&view=rev
Log:
[AMBER-12] - import of Leelo OAuth 2.0 implementation - integration-tests module

Added:
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/pom.xml   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenAssertion.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenPasswordCredentialsTest.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenTestAuthCodeTest.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationOAuthTest.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationTest.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientResourceOAuthTest.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientServerOAuthTest.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/Common.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/CommonExt.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/EndUserAuthorizationTest.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/JUnit4SpringContextTests.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ResourceTest.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/AuthzEndpoint.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/RegistrationEndpoint.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/ResourceBodyEndpoint.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/ResourceHeaderEndpoint.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/ResourceQueryEndpoint.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/TokenEndpoint.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/server/
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/server/AbstractJettyServerTest.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/server/ExampleServlet.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/server/ResourceServlet.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/server/ServerTest.java   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/resources/
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/resources/log4j.properties   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/resources/oauth-beans.xml   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/resources/server/
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/resources/server/WEB-INF/
    incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/resources/server/WEB-INF/web.xml   (with props)

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 18 17:02:42 2010
@@ -0,0 +1 @@
+target

Added: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/pom.xml
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/pom.xml?rev=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/pom.xml (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/pom.xml Sat Dec 18 17:02:42 2010
@@ -0,0 +1,137 @@
+<?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">
+    <parent>
+        <artifactId>amber-oauth2-parent</artifactId>
+        <groupId>org.apache.amber</groupId>
+       <version>0.2-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <name>Apache Amber: OAuth 2.0 Implementation - Integration Tests</name>
+    <artifactId>oauth2-integration-tests</artifactId>
+   <version>0.2-SNAPSHOT</version>
+
+    <build>
+        <finalName>oauth2-integration-tests</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.5</version>
+                <configuration>
+                    <excludes>
+                        <exclude>**/utils/*</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.amber</groupId>
+            <artifactId>oauth2-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.amber</groupId>
+            <artifactId>oauth2-client</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.amber</groupId>
+            <artifactId>oauth2-authzserver</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.amber</groupId>
+            <artifactId>oauth2-httpclient4</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.amber</groupId>
+            <artifactId>oauth2-resourceserver</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.amber</groupId>
+            <artifactId>oauth2-dynamicreg-client</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.amber</groupId>
+            <artifactId>oauth2-dynamicreg-server</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+            <version>${cxf.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-webapp</artifactId>
+            <version>${jetty.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-transports-http</artifactId>
+            <version>${cxf.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-transports-http-jetty</artifactId>
+            <version>${cxf.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+            <version>${spring.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-core</artifactId>
+            <version>${spring.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-beans</artifactId>
+            <version>${spring.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenAssertion.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenAssertion.java?rev=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenAssertion.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenAssertion.java Sat Dec 18 17:02:42 2010
@@ -0,0 +1,104 @@
+/**
+ *       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.integration;
+
+import org.apache.amber.oauth2.client.OAuthClient;
+import org.apache.amber.oauth2.client.URLConnectionClient;
+import org.apache.amber.oauth2.client.request.OAuthClientRequest;
+import org.apache.amber.oauth2.client.response.OAuthAccessTokenResponse;
+import org.apache.amber.oauth2.client.response.OAuthClientResponse;
+import org.apache.amber.oauth2.common.error.OAuthError;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.junit.Test;
+import org.apache.amber.oauth2.common.message.types.GrantType;
+import org.apache.amber.oauth2.httpclient4.HttpClient4;
+
+/**
+ * @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 AccessTokenAssertion extends ClientServerOAuthTest {
+
+    @Test
+    public void testSuccessfullAccesToken() throws Exception {
+
+        OAuthClientRequest request = OAuthClientRequest
+            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
+            .setGrantType(GrantType.ASSERTION)
+            .setAssertion(Common.ASSERTION)
+            .setAssertionType(Common.ASSERTION_TYPE)
+            .buildBodyMessage();
+
+        OAuthClient oAuthClient = new OAuthClient(new HttpClient4());
+        OAuthAccessTokenResponse response = null;
+        try {
+            response = oAuthClient.accessToken(request);
+        } catch (OAuthProblemException e) {
+            fail("exception not expected");
+        }
+        assertNotNull(response.getAccessToken());
+        assertNotNull(response.getExpiresIn());
+
+    }
+
+    @Test
+    public void testInvalidRequest() throws Exception {
+
+        OAuthClientRequest request = OAuthClientRequest
+            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
+            .setGrantType(GrantType.ASSERTION)
+            .setAssertionType(Common.ASSERTION_TYPE)
+            .buildBodyMessage();
+
+        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
+
+        OAuthAccessTokenResponse response = null;
+        try {
+            oAuthClient.accessToken(request);
+            fail("exception expected");
+        } catch (OAuthProblemException e) {
+            assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+
+    }
+
+    @Test
+    public void testInvalidRequest2() throws Exception {
+
+        OAuthClientRequest request = OAuthClientRequest
+            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
+            .setGrantType(GrantType.ASSERTION)
+            .buildBodyMessage();
+
+        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
+        OAuthClientResponse response = null;
+        try {
+            oAuthClient.accessToken(request);
+            fail("exception expected");
+        } catch (OAuthProblemException e) {
+            assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+    }
+}
\ No newline at end of file

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenAssertion.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenPasswordCredentialsTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenPasswordCredentialsTest.java?rev=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenPasswordCredentialsTest.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenPasswordCredentialsTest.java Sat Dec 18 17:02:42 2010
@@ -0,0 +1,111 @@
+/**
+ *       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.integration;
+
+import org.apache.amber.oauth2.client.OAuthClient;
+import org.apache.amber.oauth2.client.URLConnectionClient;
+import org.apache.amber.oauth2.client.request.OAuthClientRequest;
+import org.apache.amber.oauth2.client.response.OAuthClientResponse;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.message.types.GrantType;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.amber.oauth2.client.response.OAuthJSONAccessTokenResponse;
+import org.apache.amber.oauth2.common.error.OAuthError;
+
+
+/**
+ * @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 AccessTokenPasswordCredentialsTest extends ClientServerOAuthTest {
+    private static Logger logger = LoggerFactory.getLogger(AccessTokenPasswordCredentialsTest.class);
+
+    static {
+        logger.info("Test class: " + AccessTokenPasswordCredentialsTest.class);
+    }
+
+    @Test
+    public void testSuccessfullAccesToken() throws Exception {
+
+        OAuthClientRequest request = OAuthClientRequest
+            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
+            .setGrantType(GrantType.PASSWORD)
+            .setClientId(Common.CLIENT_ID)
+            .setClientSecret(Common.CLIENT_SECRET)
+            .setUsername(Common.USERNAME)
+            .setPassword(Common.PASSWORD)
+            .buildBodyMessage();
+
+        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
+
+        OAuthJSONAccessTokenResponse response = oAuthClient.accessToken(request);
+
+        assertNotNull(response.getAccessToken());
+    }
+
+    @Test
+    public void testInvalidRequest() throws Exception {
+
+        OAuthClientRequest request = OAuthClientRequest
+            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
+            .setGrantType(GrantType.PASSWORD)
+            .setClientId(Common.CLIENT_ID)
+            .buildBodyMessage();
+
+        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
+        OAuthClientResponse response = null;
+
+        try {
+            oAuthClient.accessToken(request);
+            fail("exception expected");
+        } catch (OAuthProblemException e) {
+            assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+    }
+
+    @Test
+    public void testInvalidClient() throws Exception {
+        OAuthClientRequest request = OAuthClientRequest
+            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
+            .setGrantType(GrantType.PASSWORD)
+            .setClientId("wrong_client_id")
+            .setClientSecret(Common.CLIENT_SECRET)
+            .setUsername(Common.USERNAME)
+            .setPassword(Common.PASSWORD)
+            .buildBodyMessage();
+
+        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
+        OAuthClientResponse response = null;
+
+        try {
+            oAuthClient.accessToken(request);
+            fail("exception expected");
+        } catch (OAuthProblemException e) {
+            assertEquals(OAuthError.TokenResponse.INVALID_CLIENT, e.getError());
+        }
+
+    }
+}
\ No newline at end of file

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenPasswordCredentialsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenTestAuthCodeTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenTestAuthCodeTest.java?rev=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenTestAuthCodeTest.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenTestAuthCodeTest.java Sat Dec 18 17:02:42 2010
@@ -0,0 +1,163 @@
+/**
+ *       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.integration;
+
+import org.apache.amber.oauth2.client.OAuthClient;
+import org.apache.amber.oauth2.client.URLConnectionClient;
+import org.apache.amber.oauth2.client.request.OAuthClientRequest;
+import org.apache.amber.oauth2.client.response.OAuthAccessTokenResponse;
+import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.error.OAuthError;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.junit.Test;
+
+import org.apache.amber.oauth2.common.message.types.GrantType;
+
+/**
+ * @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 AccessTokenTestAuthCodeTest extends ClientServerOAuthTest {
+
+
+    @Test
+    public void testSuccessfullAccesToken() throws Exception {
+
+        OAuthClientRequest request = OAuthClientRequest
+            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
+            .setGrantType(GrantType.AUTHORIZATION_CODE)
+            .setCode(Common.AUTHORIZATION_CODE)
+            .setRedirectURI(Common.REDIRECT_URL)
+            .setClientId(Common.CLIENT_ID)
+            .setClientSecret(Common.CLIENT_SECRET)
+            .buildBodyMessage();
+
+        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
+        OAuthAccessTokenResponse response = oAuthClient.accessToken(request);
+        assertNotNull(response.getAccessToken());
+        assertNotNull(response.getExpiresIn());
+
+
+    }
+
+    @Test
+    public void testNoneGrantType() throws Exception {
+        OAuthClientRequest request = OAuthClientRequest
+            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
+            .setGrantType(GrantType.NONE)
+            .setClientId(Common.CLIENT_ID)
+            .buildBodyMessage();
+
+        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
+
+
+        try {
+            oAuthClient.accessToken(request);
+            fail("exception expected");
+        } catch (OAuthProblemException e) {
+            assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+    }
+
+    @Test
+    public void testInvalidRequest() throws Exception {
+        OAuthClientRequest request = OAuthClientRequest
+            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
+            .setClientId(Common.CLIENT_ID)
+            .buildBodyMessage();
+
+        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
+
+
+        try {
+            oAuthClient.accessToken(request);
+            fail("exception expected");
+        } catch (OAuthProblemException e) {
+            assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+    }
+
+    @Test
+    public void testInvalidClient() throws Exception {
+        OAuthClientRequest request = OAuthClientRequest
+            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
+            .setGrantType(GrantType.AUTHORIZATION_CODE)
+            .setCode(Common.AUTHORIZATION_CODE)
+            .setClientId("unknownid")
+            .setRedirectURI(Common.REDIRECT_URL)
+            .buildBodyMessage();
+
+        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
+
+
+        try {
+            oAuthClient.accessToken(request);
+            fail("exception expected");
+        } catch (OAuthProblemException e) {
+            assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+    }
+
+    @Test
+    public void testInvalidGrantType() throws Exception {
+        OAuthClientRequest request = OAuthClientRequest
+            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
+            .setParameter(OAuth.OAUTH_GRANT_TYPE, "unknown_grant_type")
+            .setCode(Common.AUTHORIZATION_CODE)
+            .setRedirectURI(Common.REDIRECT_URL)
+            .setClientId(Common.CLIENT_ID)
+            .buildBodyMessage();
+
+        OAuthClient oAuthclient = new OAuthClient(new URLConnectionClient());
+
+
+        try {
+            oAuthclient.accessToken(request);
+            fail("exception expected");
+        } catch (OAuthProblemException e) {
+            assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+    }
+
+    @Test
+    public void testInvalidCode() throws Exception {
+        OAuthClientRequest request = OAuthClientRequest
+            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
+            .setGrantType(GrantType.AUTHORIZATION_CODE)
+            .setRedirectURI(Common.REDIRECT_URL)
+            .setCode("unknown_code")
+            .setClientId(Common.CLIENT_ID)
+            .buildBodyMessage();
+
+        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
+
+        try {
+            oAuthClient.accessToken(request);
+            fail("exception expected");
+        } catch (OAuthProblemException e) {
+            assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+    }
+}
\ No newline at end of file

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/AccessTokenTestAuthCodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationOAuthTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationOAuthTest.java?rev=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationOAuthTest.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationOAuthTest.java Sat Dec 18 17:02:42 2010
@@ -0,0 +1,54 @@
+/**
+ *       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.integration;
+
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * @author Maciej P. Machulak
+ */
+public abstract class ClientRegistrationOAuthTest extends ClientServerOAuthTest {
+
+    protected static Server s3;
+
+    @BeforeClass
+    public static void initService() throws Exception {
+
+        ClientServerOAuthTest.initService();
+        JAXRSServerFactoryBean sf3 = (JAXRSServerFactoryBean)ctx.getBean("oauthServerExt");
+        s3 = sf3.create();
+
+    }
+
+    @AfterClass
+    public static void stopService() throws Exception {
+        if (s3 != null) {
+            s3.stop();
+        }
+        ClientServerOAuthTest.stopService();
+    }
+
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationOAuthTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationTest.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationTest.java Sat Dec 18 17:02:42 2010
@@ -0,0 +1,85 @@
+/**
+ *       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.integration;
+
+import org.apache.amber.oauth2.client.URLConnectionClient;
+import org.apache.amber.oauth2.client.request.OAuthClientRequest;
+import org.apache.amber.oauth2.ext.dynamicreg.client.OAuthRegistrationClient;
+import org.apache.amber.oauth2.ext.dynamicreg.client.request.OAuthClientRegistrationRequest;
+import org.junit.Test;
+import org.apache.amber.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse;
+import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration;
+
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+
+/**
+ * @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 ClientRegistrationTest extends ClientServerOAuthTest {
+
+    @Test
+    public void testPushMetadataRegistration() throws Exception {
+
+        OAuthClientRequest request = OAuthClientRegistrationRequest
+            .location(CommonExt.REGISTRATION_ENDPOINT, OAuthRegistration.Type.PUSH)
+            .setName(CommonExt.APP_NAME)
+            .setUrl(CommonExt.APP_URL)
+            .setDescription(CommonExt.APP_DESCRIPTION)
+            .setIcon(CommonExt.APP_ICON)
+            .setRedirectURI(CommonExt.APP_REDIRECT_URI)
+            .buildBodyMessage();
+
+        OAuthRegistrationClient oauthclient = new OAuthRegistrationClient(new URLConnectionClient());
+        OAuthClientRegistrationResponse response = oauthclient.clientInfo(request);
+
+        assertEquals(CommonExt.CLIENT_ID, response.getClientId());
+        assertEquals(CommonExt.CLIENT_SECRET, response.getClientSecret());
+        assertEquals(CommonExt.EXPIRES_IN, response.getExpiresIn());
+        assertEquals(CommonExt.ISSUED_AT, response.getIssuedAt());
+
+    }
+
+    @Test
+    public void testInvalidType() throws Exception {
+
+        OAuthClientRequest request = OAuthClientRegistrationRequest
+            .location(CommonExt.REGISTRATION_ENDPOINT, "unknown_type")
+            .setName(CommonExt.APP_NAME)
+            .setUrl(CommonExt.APP_URL)
+            .setDescription(CommonExt.APP_DESCRIPTION)
+            .setIcon(CommonExt.APP_ICON)
+            .setRedirectURI(CommonExt.APP_REDIRECT_URI)
+            .buildBodyMessage();
+
+        OAuthRegistrationClient oauthclient = new OAuthRegistrationClient(new URLConnectionClient());
+        try {
+            OAuthClientRegistrationResponse response = oauthclient.clientInfo(request);
+            fail("exception expected");
+        } catch (OAuthProblemException e) {
+            assertNotNull(e.getError());
+        }
+
+    }
+
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientRegistrationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientResourceOAuthTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientResourceOAuthTest.java?rev=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientResourceOAuthTest.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientResourceOAuthTest.java Sat Dec 18 17:02:42 2010
@@ -0,0 +1,55 @@
+/**
+ *       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.integration;
+
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * @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 abstract class ClientResourceOAuthTest extends ClientServerOAuthTest {
+
+    protected static Server s3;
+
+    @BeforeClass
+    public static void initService() throws Exception {
+
+        ClientServerOAuthTest.initService();
+        JAXRSServerFactoryBean sf3 = (JAXRSServerFactoryBean)ctx.getBean("resourceServer");
+        s3 = sf3.create();
+
+    }
+
+    @AfterClass
+    public static void stopService() throws Exception {
+        if (s3 != null) {
+            s3.stop();
+        }
+        ClientServerOAuthTest.stopService();
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientResourceOAuthTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientServerOAuthTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientServerOAuthTest.java?rev=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientServerOAuthTest.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientServerOAuthTest.java Sat Dec 18 17:02:42 2010
@@ -0,0 +1,62 @@
+/**
+ *       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.integration;
+
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * @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 abstract class ClientServerOAuthTest extends JUnit4SpringContextTests {
+    protected static Server s2;
+    protected static Server s;
+
+    @BeforeClass
+    public static void initService() throws Exception {
+
+        JAXRSServerFactoryBean sf = (JAXRSServerFactoryBean)ctx.getBean("oauthServer");
+        s = sf.create();
+
+        JAXRSServerFactoryBean sf2 = (JAXRSServerFactoryBean)ctx.getBean("oauthClient");
+        s2 = sf2.create();
+
+
+    }
+
+    @AfterClass
+    public static void stopService() throws Exception {
+        if (s != null) {
+            s.stop();
+        }
+        if (s2 != null) {
+            s2.stop();
+        }
+    }
+
+
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ClientServerOAuthTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/Common.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/Common.java?rev=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/Common.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/Common.java Sat Dec 18 17:02:42 2010
@@ -0,0 +1,119 @@
+/**
+ *       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.integration;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.apache.amber.oauth2.client.request.OAuthClientRequest;
+
+/**
+ * @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 final class Common {
+    private Common() {
+    }
+
+    public static final String RESOURCE_SERVER_NAME = "Example OAuth Resource Server";
+    public static final String ACCESS_TOKEN_VALID = "access_token_valid";
+    public static final String ACCESS_TOKEN_EXPIRED = "access_token_expired";
+    public static final String ACCESS_TOKEN_INSUFFICIENT = "access_token_insufficient";
+
+    public static final String OAUTH_VERSION_1
+        = "oauth_token=\"some_oauth1_token\",realm=\"Something\",oauth_signature_method=\"HMAC-SHA1\"";
+    public static final String OAUTH_VERSION_2 = ACCESS_TOKEN_VALID;
+    public static final String OAUTH_VERSION_2_EXPIRED = ACCESS_TOKEN_EXPIRED;
+    public static final String OAUTH_VERSION_2_INSUFFICIENT = ACCESS_TOKEN_INSUFFICIENT;
+
+    public static final String OAUTH_URL_ENCODED_VERSION_1 = OAUTH_VERSION_1;
+    public static final String OAUTH_URL_ENCODED_VERSION_2 = "oauth_token=" + OAUTH_VERSION_2;
+    public static final String OAUTH_URL_ENCODED_VERSION_2_EXPIRED = "oauth_token=" + OAUTH_VERSION_2_EXPIRED;
+    public static final String OAUTH_URL_ENCODED_VERSION_2_INSUFFICIENT = "oauth_token="
+        + OAUTH_VERSION_2_INSUFFICIENT;
+
+    public static final String AUTHORIZATION_HEADER_OAUTH1 = "OAuth " + OAUTH_VERSION_1;
+    public static final String AUTHORIZATION_HEADER_OAUTH2 = "OAuth " + OAUTH_VERSION_2;
+    public static final String AUTHORIZATION_HEADER_OAUTH2_EXPIRED = "OAuth " + OAUTH_VERSION_2_EXPIRED;
+    public static final String AUTHORIZATION_HEADER_OAUTH2_INSUFFICIENT = "OAuth "
+        + OAUTH_VERSION_2_INSUFFICIENT;
+
+    public static final String BODY_OAUTH1 = OAUTH_URL_ENCODED_VERSION_1;
+    public static final String BODY_OAUTH2 = OAUTH_URL_ENCODED_VERSION_2;
+    public static final String BODY_OAUTH2_EXPIRED = OAUTH_URL_ENCODED_VERSION_2_EXPIRED;
+    public static final String BODY_OAUTH2_INSUFFICIENT = OAUTH_URL_ENCODED_VERSION_2_INSUFFICIENT;
+
+    public static final String QUERY_OAUTH1 = OAUTH_URL_ENCODED_VERSION_1;
+    public static final String QUERY_OAUTH2 = OAUTH_URL_ENCODED_VERSION_2;
+    public static final String QUERY_OAUTH2_EXPIRED = OAUTH_URL_ENCODED_VERSION_2_EXPIRED;
+    public static final String QUERY_OAUTH2_INSUFFICIENT = OAUTH_URL_ENCODED_VERSION_2_INSUFFICIENT;
+
+    public static final String CLIENT_ID = "test_id";
+    public static final String CLIENT_SECRET = "test_secret";
+    public static final String USERNAME = "test_username";
+    public static final String PASSWORD = "test_password";
+
+    public static final String HEADER_WWW_AUTHENTICATE = "WWW-Authenticate";
+    public static final String HEADER_AUTHORIZATION = "Authorization";
+
+    public static final String AUTHORIZATION_CODE = "known_authz_code";
+
+
+    public static final String ASSERTION = "<samlp:AuthnRequest\n"
+        + "   xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\"\n"
+        + "   xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\"\n"
+        + "   ID=\"aaf23196-1773-2113-474a-fe114412ab72\"\n"
+        + "   Version=\"2.0\"\n"
+        + "   IssueInstant=\"2004-12-05T09:21:59Z\"\n"
+        + "   AssertionConsumerServiceIndex=\"0\"\n"
+        + "   AttributeConsumingServiceIndex=\"0\">\n"
+        + "   <saml:Issuer>https://sp.example.com/SAML2</saml:Issuer>\n"
+        + "   <samlp:NameIDPolicy\n"
+        + "     AllowCreate=\"true\"\n"
+        + "     Format=\"urn:oasis:names:tc:SAML:2.0:nameid-format:transient\"/>\n"
+        + " </samlp:AuthnRequest>";
+    public static final String ASSERTION_TYPE = "http://xml.coverpages.org/saml.html";
+
+    public static final String ACCESS_TOKEN_ENDPOINT = "http://localhost:9001/auth/oauth2/token";
+    public static final String AUTHORIZATION_ENPOINT = "http://localhost:9001/auth/oauth2/authz";
+    public static final String REDIRECT_URL = "http://localhost:9002/auth/oauth2/redirect";
+    public static final String RESOURCE_SERVER = "http://localhost:9003/resource_server";
+    public static final String PROTECTED_RESOURCE_HEADER = "/resource_header";
+    public static final String PROTECTED_RESOURCE_BODY = "/resource_body";
+    public static final String PROTECTED_RESOURCE_QUERY = "/resource_query";
+
+    public static final String TEST_WEBAPP_PATH = "/server";
+
+    public static HttpURLConnection doRequest(OAuthClientRequest req) throws IOException {
+        URL url = new URL(req.getLocationUri());
+        HttpURLConnection c = (HttpURLConnection)url.openConnection();
+        c.setInstanceFollowRedirects(true);
+        c.connect();
+        c.getResponseCode();
+
+        return c;
+    }
+
+
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/Common.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/CommonExt.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/CommonExt.java?rev=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/CommonExt.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/CommonExt.java Sat Dec 18 17:02:42 2010
@@ -0,0 +1,45 @@
+/**
+ *       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.integration;
+
+/**
+ * @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 final class CommonExt {
+    private CommonExt() {
+    }
+
+    public static final String REGISTRATION_ENDPOINT = "http://localhost:9000/auth/oauth2ext/register";
+    public static final String APP_NAME = "Sample Application";
+    public static final String APP_URL = "http://www.example.com";
+    public static final String APP_ICON = "http://www.example.com/app.ico";
+    public static final String APP_DESCRIPTION = "Description of a Sample App";
+    public static final String APP_REDIRECT_URI = "http://www.example.com/redirect";
+
+    public static final String CLIENT_ID = "someclientid";
+    public static final String CLIENT_SECRET = "someclientsecret";
+    public static final String ISSUED_AT = "0123456789";
+    public static final String EXPIRES_IN = "987654321";
+
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/CommonExt.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/EndUserAuthorizationTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/EndUserAuthorizationTest.java?rev=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/EndUserAuthorizationTest.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/EndUserAuthorizationTest.java Sat Dec 18 17:02:42 2010
@@ -0,0 +1,135 @@
+/**
+ *       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.integration;
+
+import java.net.HttpURLConnection;
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+
+import org.apache.amber.oauth2.client.request.OAuthClientRequest;
+import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.message.types.ResponseType;
+import org.junit.Test;
+import org.apache.amber.oauth2.client.response.OAuthAuthzResponse;
+import org.apache.amber.oauth2.client.response.OAuthClientResponse;
+import org.apache.amber.oauth2.common.error.OAuthError;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.utils.OAuthUtils;
+
+/**
+ * @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)
+ */
+@Path("/")
+public class EndUserAuthorizationTest extends ClientServerOAuthTest {
+
+    @Test
+    public void testWrongParametersEndUserAuthorization() throws Exception {
+
+
+        OAuthClientRequest request = OAuthClientRequest
+            .authorizationLocation(Common.AUTHORIZATION_ENPOINT)
+            .setClientId(Common.CLIENT_ID)
+            .setRedirectURI(Common.REDIRECT_URL)
+            .buildQueryMessage();
+
+        Common.doRequest(request);
+
+    }
+
+    @Test
+    public void testCorrectParametersEndUserAuthorization() throws Exception {
+
+        OAuthClientRequest request = OAuthClientRequest
+            .authorizationLocation(Common.AUTHORIZATION_ENPOINT)
+            .setClientId(Common.CLIENT_ID)
+            .setRedirectURI(Common.REDIRECT_URL + "1")
+            .setResponseType(ResponseType.CODE.toString())
+            .buildQueryMessage();
+
+        Common.doRequest(request);
+
+    }
+
+    @Test
+    public void testTokenResponse() throws Exception {
+        OAuthClientRequest request = OAuthClientRequest
+            .authorizationLocation(Common.AUTHORIZATION_ENPOINT)
+            .setClientId(Common.CLIENT_ID)
+            .setRedirectURI(Common.REDIRECT_URL + "2")
+            .setResponseType(ResponseType.TOKEN.toString())
+            .buildQueryMessage();
+
+        HttpURLConnection c = Common.doRequest(request);
+        String fragment = c.getURL().toURI().getFragment();
+        Map<String, String> map = OAuthUtils.decodeForm(fragment);
+
+        assertNotNull(map.get(OAuth.OAUTH_EXPIRES_IN));
+        assertNotNull(map.get(OAuth.OAUTH_ACCESS_TOKEN));
+
+    }
+
+    @GET
+    @Path("/redirect")
+    public Response callback(@Context HttpServletRequest request) throws Exception {
+
+        OAuthClientResponse resp = null;
+        try {
+            OAuthAuthzResponse.oauthCodeAuthzResponse(request);
+            fail("exception expected");
+        } catch (OAuthProblemException e) {
+            assertEquals(OAuthError.CodeResponse.INVALID_REQUEST, e.getError());
+        }
+
+
+        return Response.ok().build();
+    }
+
+    @GET
+    @Path("/redirect1")
+    public Response callback1(@Context HttpServletRequest request) throws Exception {
+
+        OAuthClientResponse resp = null;
+        try {
+            OAuthAuthzResponse.oauthCodeAuthzResponse(request);
+        } catch (OAuthProblemException e) {
+            fail("exception not expected");
+        }
+
+
+        return Response.ok().build();
+    }
+
+    @GET
+    @Path("/redirect2")
+    public Response callback2(@Context HttpServletRequest request, @Context HttpServletResponse r)
+        throws Exception {
+        return Response.ok().build();
+    }
+
+}
\ No newline at end of file

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/EndUserAuthorizationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/JUnit4SpringContextTests.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/JUnit4SpringContextTests.java?rev=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/JUnit4SpringContextTests.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/JUnit4SpringContextTests.java Sat Dec 18 17:02:42 2010
@@ -0,0 +1,41 @@
+/**
+ *       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.integration;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @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 JUnit4SpringContextTests extends Assert {
+
+    protected static ClassPathXmlApplicationContext ctx;
+
+    @BeforeClass
+    public static void initialize() {
+        ctx = new ClassPathXmlApplicationContext(new String[] {"classpath:oauth-beans.xml"});
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/JUnit4SpringContextTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ResourceTest.java?rev=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ResourceTest.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ResourceTest.java Sat Dec 18 17:02:42 2010
@@ -0,0 +1,366 @@
+/**
+ *       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.integration;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Map;
+
+import org.apache.amber.oauth2.common.error.OAuthError;
+import org.apache.amber.oauth2.common.utils.OAuthUtils;
+import org.junit.Test;
+
+
+/**
+ * This tests against Section 5 of the OAuth 2.0 Draft 10 implementation
+ *
+ * @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 ResourceTest extends ClientResourceOAuthTest {
+
+    @Test
+    public void testResourceAccessBodyValidToken() throws Exception {
+
+        URL url = new URL(Common.RESOURCE_SERVER + Common.PROTECTED_RESOURCE_BODY);
+        URLConnection c = url.openConnection();
+
+        if (c instanceof HttpURLConnection) {
+            HttpURLConnection httpURLConnection = (HttpURLConnection)c;
+            httpURLConnection.setRequestMethod("POST");
+            httpURLConnection.setDoOutput(true);
+            httpURLConnection.setAllowUserInteraction(false);
+            httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+            httpURLConnection
+                .setRequestProperty("Content-Length", Integer.toString(Common.BODY_OAUTH2.length()));
+            OutputStream ost = httpURLConnection.getOutputStream();
+            PrintWriter pw = new PrintWriter(ost);
+            pw.print(Common.BODY_OAUTH2);
+            pw.flush();
+            pw.close();
+
+            testValidTokenResponse(httpURLConnection);
+        }
+    }
+
+    @Test
+    public void testResourceAccessBodyInvalidToken() throws Exception {
+
+        URL url = new URL(Common.RESOURCE_SERVER + Common.PROTECTED_RESOURCE_BODY);
+        URLConnection c = url.openConnection();
+
+        if (c instanceof HttpURLConnection) {
+            HttpURLConnection httpURLConnection = (HttpURLConnection)c;
+            httpURLConnection.setRequestMethod("POST");
+            httpURLConnection.setDoOutput(true);
+            httpURLConnection.setAllowUserInteraction(false);
+            httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+            httpURLConnection.setRequestProperty("Content-Length",
+                Integer.toString("oauth_token=randominvalidtoken".length()));
+            OutputStream ost = httpURLConnection.getOutputStream();
+            PrintWriter pw = new PrintWriter(ost);
+            pw.print("oauth_token=randominvalidtoken");
+            pw.flush();
+            pw.close();
+
+            testInvalidTokenResponse(httpURLConnection);
+
+        }
+    }
+
+
+    @Test
+    public void testResourceAccessBodyNoToken() throws Exception {
+
+        URL url = new URL(Common.RESOURCE_SERVER + Common.PROTECTED_RESOURCE_BODY);
+        URLConnection c = url.openConnection();
+
+        if (c instanceof HttpURLConnection) {
+            HttpURLConnection httpURLConnection = (HttpURLConnection)c;
+            httpURLConnection.setRequestMethod("POST");
+            httpURLConnection.setAllowUserInteraction(false);
+            httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+
+            testNoTokenResponse(httpURLConnection);
+        }
+    }
+
+
+    @Test
+    public void testResourceAccessBodyOAuthWrongVersionToken() throws Exception {
+
+        URL url = new URL(Common.RESOURCE_SERVER + Common.PROTECTED_RESOURCE_BODY);
+        URLConnection c = url.openConnection();
+
+        if (c instanceof HttpURLConnection) {
+            HttpURLConnection httpURLConnection = (HttpURLConnection)c;
+            httpURLConnection.setRequestMethod("POST");
+            httpURLConnection.setDoOutput(true);
+            httpURLConnection.setAllowUserInteraction(false);
+            httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+            httpURLConnection.setRequestProperty("Content-Length",
+                Integer.toString("oauth_token=randominvalidtoken&oauth_signature_method=HMAC-SHA1".length()));
+            OutputStream ost = httpURLConnection.getOutputStream();
+            PrintWriter pw = new PrintWriter(ost);
+            pw.print("oauth_token=randominvalidtoken&oauth_signature_method=HMAC-SHA1");
+            pw.flush();
+            pw.close();
+
+            testWrongOAuthVersionResponse(httpURLConnection);
+        }
+    }
+
+    @Test
+    public void testResourceAccessBodyExpiredToken() throws Exception {
+
+        URL url = new URL(Common.RESOURCE_SERVER + Common.PROTECTED_RESOURCE_BODY);
+        URLConnection c = url.openConnection();
+
+        if (c instanceof HttpURLConnection) {
+            HttpURLConnection httpURLConnection = (HttpURLConnection)c;
+            httpURLConnection.setRequestMethod("POST");
+            httpURLConnection.setDoOutput(true);
+            httpURLConnection.setAllowUserInteraction(false);
+            httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+            httpURLConnection
+                .setRequestProperty("Content-Length", Integer.toString(Common.BODY_OAUTH2_EXPIRED.length()));
+            OutputStream ost = httpURLConnection.getOutputStream();
+            PrintWriter pw = new PrintWriter(ost);
+            pw.print(Common.BODY_OAUTH2_EXPIRED);
+            pw.flush();
+            pw.close();
+
+            testExpiredTokenResponse(httpURLConnection);
+
+        }
+    }
+
+
+    @Test
+    public void testResourceAccessBodyInsufficientToken() throws Exception {
+
+        URL url = new URL(Common.RESOURCE_SERVER + Common.PROTECTED_RESOURCE_BODY);
+        URLConnection c = url.openConnection();
+
+        if (c instanceof HttpURLConnection) {
+            HttpURLConnection httpURLConnection = (HttpURLConnection)c;
+            httpURLConnection.setRequestMethod("POST");
+            httpURLConnection.setDoOutput(true);
+            httpURLConnection.setAllowUserInteraction(false);
+            httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+            httpURLConnection.setRequestProperty("Content-Length",
+                Integer.toString(Common.BODY_OAUTH2_INSUFFICIENT.length()));
+            OutputStream ost = httpURLConnection.getOutputStream();
+            PrintWriter pw = new PrintWriter(ost);
+            pw.print(Common.BODY_OAUTH2_INSUFFICIENT);
+            pw.flush();
+            pw.close();
+
+            testInsufficientScopeResponse(httpURLConnection);
+
+
+        }
+    }
+
+
+    @Test
+    public void testResourceAccessQueryValidToken() throws Exception {
+
+        URL url = new URL(
+            Common.RESOURCE_SERVER + Common.PROTECTED_RESOURCE_QUERY + "?" + Common.QUERY_OAUTH2);
+        URLConnection c = url.openConnection();
+
+        if (c instanceof HttpURLConnection) {
+            HttpURLConnection httpURLConnection = (HttpURLConnection)c;
+            httpURLConnection.setRequestMethod("GET");
+
+            InputStream inputStream = null;
+            if (httpURLConnection.getResponseCode() == 400) {
+                inputStream = httpURLConnection.getErrorStream();
+            } else {
+                inputStream = httpURLConnection.getInputStream();
+            }
+
+            String responseBody = OAuthUtils.saveStreamAsString(inputStream);
+            assertEquals(Common.ACCESS_TOKEN_VALID, responseBody);
+        }
+
+    }
+
+    @Test
+    public void testResourceAccessQueryInvalidToken() throws Exception {
+
+        URL url = new URL(Common.RESOURCE_SERVER + Common.PROTECTED_RESOURCE_QUERY + "?"
+            + "oauth_token=randominvalidtoken");
+        URLConnection c = url.openConnection();
+
+        if (c instanceof HttpURLConnection) {
+            HttpURLConnection httpURLConnection = (HttpURLConnection)c;
+            httpURLConnection.setRequestMethod("GET");
+
+            testInvalidTokenResponse(httpURLConnection);
+        }
+
+    }
+
+    @Test
+    public void testResourceAccessQueryNoToken() throws Exception {
+
+        URL url = new URL(Common.RESOURCE_SERVER + Common.PROTECTED_RESOURCE_QUERY);
+        URLConnection c = url.openConnection();
+
+        if (c instanceof HttpURLConnection) {
+            HttpURLConnection httpURLConnection = (HttpURLConnection)c;
+            httpURLConnection.setRequestMethod("GET");
+
+            testNoTokenResponse(httpURLConnection);
+        }
+
+    }
+
+    @Test
+    public void testResourceAccessHeaderValidToken() throws Exception {
+
+        URL url = new URL(Common.RESOURCE_SERVER + Common.PROTECTED_RESOURCE_HEADER);
+        URLConnection c = url.openConnection();
+        c.addRequestProperty(Common.HEADER_AUTHORIZATION, Common.AUTHORIZATION_HEADER_OAUTH2);
+
+        if (c instanceof HttpURLConnection) {
+            HttpURLConnection httpURLConnection = (HttpURLConnection)c;
+            httpURLConnection.setRequestMethod("GET");
+
+            testValidTokenResponse(httpURLConnection);
+        }
+
+    }
+
+    @Test
+    public void testResourceAccessHeaderNoToken() throws Exception {
+
+        URL url = new URL(Common.RESOURCE_SERVER + Common.PROTECTED_RESOURCE_HEADER);
+        URLConnection c = url.openConnection();
+
+        if (c instanceof HttpURLConnection) {
+            HttpURLConnection httpURLConnection = (HttpURLConnection)c;
+            httpURLConnection.setRequestMethod("GET");
+
+            testNoTokenResponse(httpURLConnection);
+        }
+
+    }
+
+    void testInvalidTokenResponse(HttpURLConnection httpURLConnection) throws Exception {
+        // For the invalid token the response should be
+        // - 401
+        // - WWW-Authenticate header should be there
+        // - realm included
+        // - error=invalid_token
+        assertEquals(401, httpURLConnection.getResponseCode());
+        String wwwAuthHeader = httpURLConnection.getHeaderField(Common.HEADER_WWW_AUTHENTICATE);
+        assertNotNull(wwwAuthHeader);
+        Map<String, String> headerValues = OAuthUtils.decodeOAuthHeader(wwwAuthHeader);
+        String realm = headerValues.get("realm");
+        assertNotNull(realm);
+        String error = headerValues.get("error");
+        assertEquals(OAuthError.ResourceResponse.INVALID_TOKEN, error);
+    }
+
+
+    void testValidTokenResponse(HttpURLConnection httpURLConnection) throws Exception {
+
+        InputStream inputStream = null;
+        if (httpURLConnection.getResponseCode() == 400) {
+            inputStream = httpURLConnection.getErrorStream();
+        } else {
+            inputStream = httpURLConnection.getInputStream();
+        }
+        String responseBody = OAuthUtils.saveStreamAsString(inputStream);
+        assertEquals(Common.ACCESS_TOKEN_VALID, responseBody);
+    }
+
+    private void testNoTokenResponse(HttpURLConnection httpURLConnection) throws Exception {
+        // For the request with no token the response should be
+        // - 401
+        // - WWW-Authenticate header should be there
+        // - only realm should be included
+        assertEquals(401, httpURLConnection.getResponseCode());
+        String wwwAuthHeader = httpURLConnection.getHeaderField(Common.HEADER_WWW_AUTHENTICATE);
+        assertNotNull(wwwAuthHeader);
+        Map<String, String> headerValues = OAuthUtils.decodeOAuthHeader(wwwAuthHeader);
+        assertEquals(1, headerValues.size());
+        String realm = headerValues.get("realm");
+        assertNotNull(realm);
+    }
+
+
+    private void testExpiredTokenResponse(HttpURLConnection httpURLConnection) throws Exception {
+        // For the invalid token the response should be
+        // - 401
+        // - WWW-Authenticate header should be there
+        // - realm included
+        // - error=expired_token
+        assertEquals(401, httpURLConnection.getResponseCode());
+        String wwwAuthHeader = httpURLConnection.getHeaderField(Common.HEADER_WWW_AUTHENTICATE);
+        assertNotNull(wwwAuthHeader);
+        Map<String, String> headerValues = OAuthUtils.decodeOAuthHeader(wwwAuthHeader);
+        String realm = headerValues.get("realm");
+        assertNotNull(realm);
+        String error = headerValues.get("error");
+        assertEquals(OAuthError.ResourceResponse.EXPIRED_TOKEN, error);
+    }
+
+    private void testInsufficientScopeResponse(HttpURLConnection httpURLConnection) throws Exception {
+        // For the invalid token the response should be
+        // - 403
+        // - WWW-Authenticate header should be there
+        // - realm included
+        // - error=insufficient_scope
+        assertEquals(403, httpURLConnection.getResponseCode());
+        String wwwAuthHeader = httpURLConnection.getHeaderField(Common.HEADER_WWW_AUTHENTICATE);
+        assertNotNull(wwwAuthHeader);
+        Map<String, String> headerValues = OAuthUtils.decodeOAuthHeader(wwwAuthHeader);
+        String realm = headerValues.get("realm");
+        assertNotNull(realm);
+        String error = headerValues.get("error");
+        assertEquals(OAuthError.ResourceResponse.INSUFFICIENT_SCOPE, error);
+    }
+
+    private void testWrongOAuthVersionResponse(HttpURLConnection httpURLConnection) throws Exception {
+        // For the wrong OAuth version response
+        // - 400
+        // - WWW-Authenticate header should be there
+        // - error=invalid_request
+        assertEquals(400, httpURLConnection.getResponseCode());
+        String wwwAuthHeader = httpURLConnection.getHeaderField(Common.HEADER_WWW_AUTHENTICATE);
+        assertNotNull(wwwAuthHeader);
+        Map<String, String> headerValues = OAuthUtils.decodeOAuthHeader(wwwAuthHeader);
+        String realm = headerValues.get("realm");
+        assertNotNull(realm);
+        String error = headerValues.get("error");
+        assertEquals(OAuthError.CodeResponse.INVALID_REQUEST, error);
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/ResourceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/AuthzEndpoint.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/AuthzEndpoint.java?rev=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/AuthzEndpoint.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/AuthzEndpoint.java Sat Dec 18 17:02:42 2010
@@ -0,0 +1,105 @@
+/**
+ *       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.integration.endpoints;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+
+import org.apache.amber.oauth2.as.issuer.MD5Generator;
+import org.apache.amber.oauth2.as.request.OAuthAuthzRequest;
+import org.apache.amber.oauth2.as.response.OAuthASResponse;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.message.types.ResponseType;
+import org.apache.amber.oauth2.common.exception.OAuthSystemException;
+import org.apache.amber.oauth2.common.utils.OAuthUtils;
+import org.apache.amber.oauth2.as.issuer.OAuthIssuerImpl;
+import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.message.OAuthResponse;
+
+/**
+ * @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)
+ */
+@Path("/authz")
+public class AuthzEndpoint {
+
+    @GET
+    public Response authorize(@Context HttpServletRequest request)
+        throws URISyntaxException, OAuthSystemException {
+
+        OAuthAuthzRequest oauthRequest = null;
+
+        OAuthIssuerImpl oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator());
+
+        try {
+            oauthRequest = new OAuthAuthzRequest(request);
+
+            //build response according to response_type
+            String responseType = oauthRequest.getParam(OAuth.OAUTH_RESPONSE_TYPE);
+
+            OAuthASResponse.OAuthAuthorizationResponseBuilder builder = OAuthASResponse
+                .authorizationResponse(HttpServletResponse.SC_FOUND);
+
+            if (responseType.equals(ResponseType.CODE.toString()) || responseType
+                .equals(ResponseType.CODE_AND_TOKEN.toString())) {
+                builder.setCode(oauthIssuerImpl.authorizationCode());
+            }
+            if (responseType.equals(ResponseType.TOKEN.toString()) || responseType
+                .equals(ResponseType.CODE_AND_TOKEN.toString())) {
+                builder.setAccessToken(oauthIssuerImpl.accessToken());
+                builder.setExpiresIn(String.valueOf(3600));
+            }
+
+            String redirectURI = oauthRequest.getParam(OAuth.OAUTH_REDIRECT_URI);
+
+            final OAuthResponse response = builder.location(redirectURI).buildQueryMessage();
+            URI url = new URI(response.getLocationUri());
+
+            return Response.status(response.getResponseStatus()).location(url).build();
+
+        } catch (OAuthProblemException e) {
+
+            final Response.ResponseBuilder responseBuilder = Response.status(HttpServletResponse.SC_FOUND);
+
+            String redirectUri = e.getRedirectUri();
+
+            if (OAuthUtils.isEmpty(redirectUri)) {
+                throw new WebApplicationException(
+                    responseBuilder.entity("OAuth callback url needs to be provided by client!!!").build());
+            }
+            final OAuthResponse response = OAuthASResponse.errorResponse(HttpServletResponse.SC_FOUND)
+                .error(e)
+                .location(redirectUri).buildQueryMessage();
+            final URI location = new URI(response.getLocationUri());
+            return responseBuilder.location(location).build();
+        }
+    }
+
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/AuthzEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=1050671&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/RegistrationEndpoint.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/RegistrationEndpoint.java Sat Dec 18 17:02:42 2010
@@ -0,0 +1,82 @@
+/**
+ *       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.integration.endpoints;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+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.OAuthServerRegistrationRequest;
+import org.apache.amber.oauth2.ext.dynamicreg.server.response.OAuthServerRegistrationResponse;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.integration.CommonExt;
+
+/**
+ * @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)
+ */
+@Path("/register")
+public class RegistrationEndpoint {
+
+
+    @POST
+    @Consumes("application/x-www-form-urlencoded")
+    @Produces("application/json")
+    public Response register(@Context HttpServletRequest request) throws OAuthSystemException {
+
+
+        OAuthServerRegistrationRequest oauthRequest = null;
+        try {
+            oauthRequest = new OAuthServerRegistrationRequest(request);
+            oauthRequest.discover();
+            oauthRequest.getName();
+            oauthRequest.getUrl();
+            oauthRequest.getDescription();
+            oauthRequest.getRedirectURI();
+
+            OAuthResponse response = OAuthServerRegistrationResponse
+                .status(HttpServletResponse.SC_OK)
+                .setClientId(CommonExt.CLIENT_ID)
+                .setClientSecret(CommonExt.CLIENT_SECRET)
+                .setIssuedAt(CommonExt.ISSUED_AT)
+                .setExpiresIn(CommonExt.EXPIRES_IN)
+                .buildJSONMessage();
+            return Response.status(response.getResponseStatus()).entity(response.getBody()).build();
+
+        } catch (OAuthProblemException e) {
+            OAuthResponse response = OAuthServerRegistrationResponse
+                .errorResponse(HttpServletResponse.SC_BAD_REQUEST)
+                .error(e)
+                .buildJSONMessage();
+            return Response.status(response.getResponseStatus()).entity(response.getBody()).build();
+        }
+
+    }
+}
\ No newline at end of file

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-integration-tests/src/test/java/org/apache/amber/oauth2/integration/endpoints/RegistrationEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message