incubator-amber-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1050665 - in /incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/amber/ src/main/java/org/apache/amber/oauth2/ src/main/java/org/...
Date Sat, 18 Dec 2010 16:41:14 GMT
Author: tommaso
Date: Sat Dec 18 16:41:14 2010
New Revision: 1050665

URL: http://svn.apache.org/viewvc?rev=1050665&view=rev
Log:
[AMBER-11] - import of Leelo OAuth 2.0 implementation - oauth2-dynamicreg-client module

Added:
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/pom.xml   (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/OAuthRegistrationClient.java
  (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/request/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java
  (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/response/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/response/OAuthClientRegistrationResponse.java
  (with props)
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/validators/
    incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/validators/RegistrationValidator.java
  (with props)

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Dec 18 16:41:14 2010
@@ -0,0 +1 @@
+target

Added: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/pom.xml
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/pom.xml?rev=1050665&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/pom.xml (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/pom.xml Sat Dec 18 16:41:14 2010
@@ -0,0 +1,63 @@
+<?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-dynamicreg-client</artifactId>
+    <name>Apache Amber: OAuth 2.0 Implementation - Dynamic Registration Client</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-dynamicreg-client</finalName>
+    </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-dynamicreg-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+    </dependencies>
+</project>

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

Added: 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=1050665&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/OAuthRegistrationClient.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/OAuthRegistrationClient.java
Sat Dec 18 16:41:14 2010
@@ -0,0 +1,57 @@
+/**
+ *       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.client;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.amber.oauth2.client.HttpClient;
+import org.apache.amber.oauth2.client.OAuthClient;
+import org.apache.amber.oauth2.client.request.OAuthClientRequest;
+import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.exception.OAuthSystemException;
+import org.apache.amber.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse;
+
+
+/**
+ * @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 OAuthRegistrationClient extends OAuthClient {
+
+    public OAuthRegistrationClient(HttpClient oauthClient) {
+        super(oauthClient);
+    }
+
+    public OAuthClientRegistrationResponse clientInfo(
+        OAuthClientRequest request)
+        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);
+
+        return httpClient.execute(request, headers, method, OAuthClientRegistrationResponse.class);
+    }
+}

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

Added: 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=1050665&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java
Sat Dec 18 16:41:14 2010
@@ -0,0 +1,79 @@
+/**
+ *       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.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;
+
+
+/**
+ * OAuth Registration Request
+ *
+ * @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 OAuthClientRegistrationRequest extends OAuthClientRequest {
+
+    protected OAuthClientRegistrationRequest(String url) {
+        super(url);
+    }
+
+    public static OAuthRegistrationRequestBuilder location(String url, String type) {
+        return new OAuthRegistrationRequestBuilder(url, type);
+    }
+
+    public static class OAuthRegistrationRequestBuilder extends OAuthRequestBuilder {
+
+        public OAuthRegistrationRequestBuilder(String url, String type) {
+            super(url);
+            this.parameters.put(OAuthRegistration.Request.TYPE, type);
+        }
+
+        public OAuthRegistrationRequestBuilder setName(String value) {
+            this.parameters.put(OAuthRegistration.Request.NAME, value);
+            return this;
+        }
+
+        public OAuthRegistrationRequestBuilder setUrl(String value) {
+            this.parameters.put(OAuthRegistration.Request.URL, value);
+            return this;
+        }
+
+        public OAuthRegistrationRequestBuilder setDescription(String value) {
+            this.parameters.put(OAuthRegistration.Request.DESCRIPTION, value);
+            return this;
+        }
+
+        public OAuthRegistrationRequestBuilder setIcon(String value) {
+            this.parameters.put(OAuthRegistration.Request.ICON, value);
+            return this;
+        }
+
+        public OAuthRegistrationRequestBuilder setRedirectURI(String uri) {
+            this.parameters.put(OAuth.OAUTH_REDIRECT_URI, uri);
+            return this;
+        }
+
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/request/OAuthClientRegistrationRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/response/OAuthClientRegistrationResponse.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/response/OAuthClientRegistrationResponse.java?rev=1050665&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/response/OAuthClientRegistrationResponse.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/response/OAuthClientRegistrationResponse.java
Sat Dec 18 16:41:14 2010
@@ -0,0 +1,88 @@
+/**
+ *       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.client.response;
+
+import org.apache.amber.oauth2.common.error.OAuthError;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.utils.JSONUtils;
+import org.apache.amber.oauth2.ext.dynamicreg.client.validators.RegistrationValidator;
+import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration;
+import org.codehaus.jettison.json.JSONException;
+import org.apache.amber.oauth2.client.response.OAuthClientResponse;
+
+
+/**
+ * @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 OAuthClientRegistrationResponse extends OAuthClientResponse {
+
+    public OAuthClientRegistrationResponse() {
+    }
+
+    @Override
+    protected void init(String body, String contentType, int responseCode) throws OAuthProblemException
{
+        validator = new RegistrationValidator();
+        super.init(body, contentType, responseCode);
+    }
+
+    @Override
+    public String getParam(String param) {
+        return parameters.get(param);
+    }
+
+    protected void setBody(String body) throws OAuthProblemException {
+        try {
+            this.body = body;
+            parameters = JSONUtils.parseJSON(body);
+        } catch (JSONException e) {
+            throw OAuthProblemException.error(OAuthError.CodeResponse.UNSUPPORTED_RESPONSE_TYPE,
+                "Invalid response! Response body is not application/json encoded");
+        }
+    }
+
+    protected void setResponseCode(int responseCode) {
+        this.responseCode = responseCode;
+    }
+
+    protected void setContentType(String contentType) {
+        this.contentType = contentType;
+    }
+
+    public String getClientId() {
+        return parameters.get(OAuthRegistration.Response.CLIENT_ID);
+    }
+
+    public String getClientSecret() {
+        return parameters.get(OAuthRegistration.Response.CLIENT_SECRET);
+    }
+
+    public String getIssuedAt() {
+        return parameters.get(OAuthRegistration.Response.ISSUED_AT);
+    }
+
+    public String getExpiresIn() {
+        return parameters.get(OAuthRegistration.Response.EXPIRES_IN);
+    }
+
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/response/OAuthClientRegistrationResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/validators/RegistrationValidator.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/validators/RegistrationValidator.java?rev=1050665&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/validators/RegistrationValidator.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/validators/RegistrationValidator.java
Sat Dec 18 16:41:14 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.ext.dynamicreg.client.validators;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.amber.oauth2.client.response.OAuthClientResponse;
+import org.apache.amber.oauth2.client.validator.OAuthClientValidator;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.utils.OAuthUtils;
+import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration;
+
+/**
+ * @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 RegistrationValidator extends OAuthClientValidator {
+
+    protected Map<String, String[]> optionalParams = new HashMap<String, String[]>();
+
+    public RegistrationValidator() {
+        requiredParams.put(OAuthRegistration.Response.CLIENT_ID, new String[] {});
+
+        optionalParams
+            .put(OAuthRegistration.Response.ISSUED_AT, new String[] {OAuthRegistration.Response.EXPIRES_IN});
+    }
+
+
+    private void validateOptionalParams(OAuthClientResponse response) throws OAuthProblemException
{
+        Set<String> missingParameters = new HashSet<String>();
+
+        for (Map.Entry<String, String[]> requiredParam : optionalParams.entrySet())
{
+            String paramName = requiredParam.getKey();
+            String val = response.getParam(paramName);
+            if (!OAuthUtils.isEmpty(val)) {
+                String[] dependentParams = requiredParam.getValue();
+                if (!OAuthUtils.hasEmptyValues(dependentParams)) {
+                    for (String dependentParam : dependentParams) {
+                        val = response.getParam(dependentParam);
+                        if (OAuthUtils.isEmpty(val)) {
+                            missingParameters.add(dependentParam);
+                        }
+                    }
+                }
+            }
+
+        }
+
+        if (!missingParameters.isEmpty()) {
+            throw OAuthUtils.handleMissingParameters(missingParameters);
+        }
+    }
+
+    @Override
+    public void validateParameters(OAuthClientResponse response) throws OAuthProblemException
{
+        super.validateParameters(response);
+        validateOptionalParams(response);
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-dynamicreg-client/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/client/validators/RegistrationValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message