Return-Path: Delivered-To: apmail-incubator-amber-commits-archive@minotaur.apache.org Received: (qmail 87612 invoked from network); 18 Dec 2010 16:35:15 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 18 Dec 2010 16:35:15 -0000 Received: (qmail 86433 invoked by uid 500); 18 Dec 2010 16:35:15 -0000 Delivered-To: apmail-incubator-amber-commits-archive@incubator.apache.org Received: (qmail 86412 invoked by uid 500); 18 Dec 2010 16:35:15 -0000 Mailing-List: contact amber-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: amber-dev@incubator.apache.org Delivered-To: mailing list amber-commits@incubator.apache.org Received: (qmail 86400 invoked by uid 99); 18 Dec 2010 16:35:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Dec 2010 16:35:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Dec 2010 16:35:05 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6CD7D23889B2; Sat, 18 Dec 2010 16:34:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1050662 [1/2] - in /incubator/amber/trunk/oauth-2.0/oauth2-client-demo: ./ 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:34:43 -0000 To: amber-commits@incubator.apache.org From: tommaso@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101218163443.6CD7D23889B2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tommaso Date: Sat Dec 18 16:34:41 2010 New Revision: 1050662 URL: http://svn.apache.org/viewvc?rev=1050662&view=rev Log: [AMBER-11] - import of Leelo OAuth 2.0 implementation - oauth2-client-demo module Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/ (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/pom.xml (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/Utils.java (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/AuthzController.java (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/MainController.java (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RedirectController.java (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RegistrationController.java (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ResourceController.java (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/TokenController.java (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/exception/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/exception/ApplicationException.java (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthParams.java (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthRegParams.java (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/jdoconfig.xml (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/persistence.xml (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/log4j.properties (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/app-config.xml (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/mvc-config.xml (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/urlrewrite.xml (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_authz.jsp (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/index.jsp (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/register.jsp (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/request_token.jsp (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/resource.jsp (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/web.xml (with props) incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/test/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/test/resources/ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/test/resources/log4j.properties (with props) Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Sat Dec 18 16:34:41 2010 @@ -0,0 +1,2 @@ +target +oauth2-client-demo.iml Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/pom.xml URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/pom.xml?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/pom.xml (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/pom.xml Sat Dec 18 16:34:41 2010 @@ -0,0 +1,155 @@ + + + + + + + amber-oauth2-parent + org.apache.amber + 0.2-SNAPSHOT + + + 4.0.0 + oauth2-client-demo + Apache Amber: OAuth 2.0 Implementation - Demo Application + war + + + + + 3.0.3.RELEASE + + + + + oauth2-demo + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.24 + + + / + + + + 8080 + 60000 + + + 10 + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.6 + 1.6 + + + + + + + + + commons-logging + commons-logging + 1.1 + + + org.slf4j + slf4j-jcl + 1.6.0 + + + + + + oauth2-common + org.apache.amber + ${project.version} + + + + + + oauth2-dynamicreg-common + org.apache.amber + ${project.version} + + + + oauth2-dynamicreg-client + org.apache.amber + ${project.version} + + + + + + org.springframework + spring-context + ${org.springframework.version} + + + + commons-logging + commons-logging + + + + + org.springframework + spring-webmvc + ${org.springframework.version} + + + + + + + org.tuckey + urlrewritefilter + 3.1.0 + runtime + + + + + standard + taglibs + 1.1.2 + jar + runtime + + + + + Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/Utils.java URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/Utils.java?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/Utils.java (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/Utils.java Sat Dec 18 16:34:41 2010 @@ -0,0 +1,200 @@ +/** + * 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.client.demo; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; + +import org.apache.amber.oauth2.client.demo.exception.ApplicationException; +import org.apache.amber.oauth2.client.demo.model.OAuthParams; +import org.apache.amber.oauth2.client.demo.model.OAuthRegParams; + +/** + * @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 Utils { + private Utils() { + } + + public static final String REDIRECT_URI = "http://localhost:8080/redirect"; + public static final String DISCOVERY_URI = "http://localhost:8080"; + + public static final String REG_TYPE_PULL = "pull"; + public static final String REG_TYPE_PUSH = "push"; + + public static final String FACEBOOK = "facebook"; + public static final String FACEBOOK_AUTHZ = "https://graph.facebook.com/oauth/authorize"; + public static final String FACEBOOK_TOKEN = "https://graph.facebook.com/oauth/access_token"; + + public static final String GOWALLA = "gowalla"; + public static final String GOWALLA_AUTHZ = "https://gowalla.com/api/oauth/authorize"; + public static final String GOWALLA_TOKEN = "https://gowalla.com/api/oauth/access_token"; + + public static final String GITHUB = "github"; + public static final String GITHUB_AUTHZ = "https://github.com/login/oauth/authorize"; + public static final String GITHUB_TOKEN = "https://github.com/login/oauth/access_token"; + + public static final String SMART_GALLERY = "smart_gallery"; + public static final String SMART_GALLERY_AUTHZ = "http://localhost:8090/oauth/authorize"; + public static final String SMART_GALLERY_TOKEN = "http://localhost:8090/oauth/token"; + public static final String SMART_GALLERY_REGISTER = "http://localhost:8090/oauthreg/register"; + + public static void validateRegistrationParams(OAuthRegParams oauthParams) throws ApplicationException { + + String regType = oauthParams.getRegistrationType(); + + String name = oauthParams.getName(); + String url = oauthParams.getUrl(); + String description = oauthParams.getDescription(); + StringBuffer sb = new StringBuffer(); + + if (isEmpty(url)) { + sb.append("Application URL "); + } + + if (REG_TYPE_PUSH.equals(regType)) { + if (isEmpty(name)) { + sb.append("Application Name "); + } + + if (isEmpty(description)) { + sb.append("Application URL "); + } + } else if (!REG_TYPE_PULL.equals(regType)) { + throw new ApplicationException("Incorrect registration type: " + regType); + } + + String incorrectParams = sb.toString(); + if ("".equals(incorrectParams)) { + return; + } + throw new ApplicationException("Incorrect parameters: " + incorrectParams); + + } + + public static void validateAuthorizationParams(OAuthParams oauthParams) throws ApplicationException { + + + String authzEndpoint = oauthParams.getAuthzEndpoint(); + String tokenEndpoint = oauthParams.getTokenEndpoint(); + String clientId = oauthParams.getClientId(); + String clientSecret = oauthParams.getClientSecret(); + String redirectUri = oauthParams.getRedirectUri(); + + StringBuffer sb = new StringBuffer(); + + if (isEmpty(authzEndpoint)) { + sb.append("Authorization Endpoint "); + } + + if (isEmpty(tokenEndpoint)) { + sb.append("Token Endpoint "); + } + + if (isEmpty(clientId)) { + sb.append("Client ID "); + } + + if (isEmpty(clientSecret)) { + sb.append("Client Secret "); + } + + if (!REDIRECT_URI.equals(redirectUri)) { + sb.append("Redirect URI"); + } + + String incorrectParams = sb.toString(); + if ("".equals(incorrectParams)) { + return; + } + throw new ApplicationException("Incorrect parameters: " + incorrectParams); + + } + + public static void validateTokenParams(OAuthParams oauthParams) throws ApplicationException { + + String authzEndpoint = oauthParams.getAuthzEndpoint(); + String tokenEndpoint = oauthParams.getTokenEndpoint(); + String clientId = oauthParams.getClientId(); + String clientSecret = oauthParams.getClientSecret(); + String redirectUri = oauthParams.getRedirectUri(); + String authzCode = oauthParams.getAuthzCode(); + + StringBuffer sb = new StringBuffer(); + + if (isEmpty(authzCode)) { + sb.append("Authorization Code "); + } + + if (isEmpty(authzEndpoint)) { + sb.append("Authorization Endpoint "); + } + + if (isEmpty(tokenEndpoint)) { + sb.append("Token Endpoint "); + } + + if (isEmpty(clientId)) { + sb.append("Client ID "); + } + + if (isEmpty(clientSecret)) { + sb.append("Client Secret "); + } + + if (!REDIRECT_URI.equals(redirectUri)) { + sb.append("Redirect URI"); + } + + String incorrectParams = sb.toString(); + if ("".equals(incorrectParams)) { + return; + } + throw new ApplicationException("Incorrect parameters: " + incorrectParams); + + } + + public static boolean isEmpty(String value) { + return value == null || "".equals(value); + } + + + public static String findCookieValue(HttpServletRequest request, String key) { + Cookie[] cookies = request.getCookies(); + + for (Cookie cookie : cookies) { + if (cookie.getName().equals(key)) { + return cookie.getValue(); + } + } + return ""; + } + + public static String isIssued(String value) { + if (isEmpty(value)) { + return "(Not issued)"; + } + return value; + } +} Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/Utils.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/AuthzController.java URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/AuthzController.java?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/AuthzController.java (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/AuthzController.java Sat Dec 18 16:34:41 2010 @@ -0,0 +1,93 @@ +/** + * 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.client.demo.controller; + + +import java.io.IOException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.amber.oauth2.client.demo.exception.ApplicationException; +import org.apache.amber.oauth2.client.request.OAuthClientRequest; +import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.amber.oauth2.common.message.types.ResponseType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.amber.oauth2.client.demo.model.OAuthParams; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.view.RedirectView; + +import org.apache.amber.oauth2.client.demo.Utils; + +/** + * Handles requests for the application welcome page. + * + * @author Maciej Machulak + * @author Lukasz Moren + */ +@Controller +@RequestMapping("/") +public class AuthzController { + + + private Logger logger = LoggerFactory.getLogger(AuthzController.class); + + @RequestMapping("/authorize") + public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams, + HttpServletRequest req, + HttpServletResponse res) + throws OAuthSystemException, IOException { + + try { + + Utils.validateAuthorizationParams(oauthParams); + + res.addCookie(new Cookie("clientId", oauthParams.getClientId())); + res.addCookie(new Cookie("clientSecret", oauthParams.getClientSecret())); + res.addCookie(new Cookie("authzEndpoint", oauthParams.getAuthzEndpoint())); + res.addCookie(new Cookie("tokenEndpoint", oauthParams.getTokenEndpoint())); + res.addCookie(new Cookie("redirectUri", oauthParams.getRedirectUri())); + res.addCookie(new Cookie("scope", oauthParams.getScope())); + res.addCookie(new Cookie("app", oauthParams.getApplication())); + + OAuthClientRequest request = OAuthClientRequest + .authorizationLocation(oauthParams.getAuthzEndpoint()) + .setClientId(oauthParams.getClientId()) + .setRedirectURI(oauthParams.getRedirectUri()) + .setResponseType(ResponseType.CODE.toString()) + .setScope(oauthParams.getScope()) + .buildQueryMessage(); + + return new ModelAndView(new RedirectView(request.getLocationUri())); + + } catch (ApplicationException e) { + oauthParams.setErrorMessage(e.getMessage()); + return new ModelAndView("get_authz"); + } + } + + +} Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/AuthzController.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/MainController.java URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/MainController.java?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/MainController.java (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/MainController.java Sat Dec 18 16:34:41 2010 @@ -0,0 +1,95 @@ +/** + * 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.client.demo.controller; + +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +import org.apache.amber.oauth2.client.demo.Utils; +import org.apache.amber.oauth2.client.demo.model.OAuthRegParams; +import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.amber.oauth2.client.demo.model.OAuthParams; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + + +/** + * @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) + */ +@Controller +@RequestMapping("/") +public class MainController { + + private Logger logger = LoggerFactory.getLogger(MainController.class); + + @RequestMapping("/index") + public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams) + throws OAuthSystemException, IOException { + return new ModelAndView("index"); + } + + @RequestMapping("/main/{app}") + public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams, + @ModelAttribute("oauthRegParams") OAuthRegParams oauthRegParams, + @PathVariable("app") String app, + HttpServletResponse res) + throws OAuthSystemException, IOException { + + boolean selected = false; + if (Utils.GITHUB.equals(app)) { + selected = true; + oauthParams.setAuthzEndpoint(Utils.GITHUB_AUTHZ); + oauthParams.setTokenEndpoint(Utils.GITHUB_TOKEN); + + } else if (Utils.FACEBOOK.equals(app)) { + selected = true; + oauthParams.setAuthzEndpoint(Utils.FACEBOOK_AUTHZ); + oauthParams.setTokenEndpoint(Utils.FACEBOOK_TOKEN); + } else if (Utils.GOWALLA.equals(app)) { + selected = true; + oauthParams.setAuthzEndpoint(Utils.GOWALLA_AUTHZ); + oauthParams.setTokenEndpoint(Utils.GOWALLA_TOKEN); + } else if (Utils.SMART_GALLERY.equals(app)) { + selected = true; + oauthRegParams.setAuthzEndpoint(Utils.SMART_GALLERY_AUTHZ); + oauthRegParams.setTokenEndpoint(Utils.SMART_GALLERY_TOKEN); + oauthRegParams.setRegistrationEndpoint(Utils.SMART_GALLERY_REGISTER); + oauthRegParams.setApplication(app); + oauthRegParams.setRedirectUri(Utils.REDIRECT_URI); + return new ModelAndView("register"); + } + if (selected) { + oauthParams.setApplication(app); + oauthParams.setRedirectUri(Utils.REDIRECT_URI); + return new ModelAndView("get_authz"); + } + + return new ModelAndView("index"); + } +} Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/MainController.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RedirectController.java URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RedirectController.java?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RedirectController.java (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RedirectController.java Sat Dec 18 16:34:41 2010 @@ -0,0 +1,98 @@ +/** + * 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.client.demo.controller; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.amber.oauth2.client.demo.Utils; +import org.apache.amber.oauth2.client.demo.model.OAuthParams; +import org.apache.amber.oauth2.client.response.OAuthAuthzResponse; +import org.apache.amber.oauth2.common.exception.OAuthProblemException; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +/** + * @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) + */ +@Controller +@RequestMapping("/redirect") +public class RedirectController { + + @RequestMapping(method = RequestMethod.GET) + public ModelAndView handleRedirect(@ModelAttribute("oauthParams") OAuthParams oauthParams, + HttpServletRequest request, + HttpServletResponse response) { + + + try { + + // Create the response wrapper + OAuthAuthzResponse oar = null; + oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request); + + + // Get Authorization Code + String code = oar.getCode(); + + // Get OAuth Info + String clientId = Utils.findCookieValue(request, "clientId"); + String clientSecret = Utils.findCookieValue(request, "clientSecret"); + String authzEndpoint = Utils.findCookieValue(request, "authzEndpoint"); + String tokenEndpoint = Utils.findCookieValue(request, "tokenEndpoint"); + String redirectUri = Utils.findCookieValue(request, "redirectUri"); + String scope = Utils.findCookieValue(request, "scope"); + + String app = Utils.findCookieValue(request, "app"); + response.addCookie(new Cookie("app", app)); + + oauthParams.setAuthzCode(code); + oauthParams.setClientId(clientId); + oauthParams.setClientSecret(clientSecret); + oauthParams.setAuthzEndpoint(authzEndpoint); + oauthParams.setTokenEndpoint(tokenEndpoint); + oauthParams.setRedirectUri(redirectUri); + oauthParams.setScope(Utils.isIssued(scope)); + oauthParams.setApplication(app); + + + } catch (OAuthProblemException e) { + StringBuffer sb = new StringBuffer(); + sb.append("
"); + sb.append("Error code: ").append(e.getError()).append("
"); + sb.append("Error description: ").append(e.getDescription()).append("
"); + sb.append("Error uri: ").append(e.getUri()).append("
"); + sb.append("State: ").append(e.getState()).append("
"); + oauthParams.setErrorMessage(sb.toString()); + return new ModelAndView("main"); + } + + return new ModelAndView("request_token"); + + } +} Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RedirectController.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RegistrationController.java URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RegistrationController.java?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RegistrationController.java (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RegistrationController.java Sat Dec 18 16:34:41 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.client.demo.controller; + +import java.io.IOException; +import javax.servlet.http.HttpServletRequest; + +import org.apache.amber.oauth2.client.URLConnectionClient; +import org.apache.amber.oauth2.client.demo.Utils; +import org.apache.amber.oauth2.client.demo.model.OAuthParams; +import org.apache.amber.oauth2.client.demo.model.OAuthRegParams; +import org.apache.amber.oauth2.client.request.OAuthClientRequest; +import org.apache.amber.oauth2.common.exception.OAuthProblemException; +import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.amber.oauth2.ext.dynamicreg.client.OAuthRegistrationClient; +import org.apache.amber.oauth2.ext.dynamicreg.client.request.OAuthClientRegistrationRequest; +import org.apache.amber.oauth2.ext.dynamicreg.common.OAuthRegistration; +import org.apache.amber.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import org.apache.amber.oauth2.client.demo.exception.ApplicationException; + +/** + * @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) + */ +@Controller +@RequestMapping("/") +public class RegistrationController { + + @RequestMapping(value = "/register") + public ModelAndView authorize(@ModelAttribute("oauthRegParams") OAuthRegParams oauthRegParams, + @ModelAttribute("oauthParams") OAuthParams oauthParams, + HttpServletRequest req) throws OAuthSystemException, IOException { + + + try { + + Utils.validateRegistrationParams(oauthRegParams); + + OAuthClientRequest request = null; + if (Utils.REG_TYPE_PULL.equals(oauthRegParams.getRegistrationType())) { + request = OAuthClientRegistrationRequest + .location(oauthRegParams.getRegistrationEndpoint(), OAuthRegistration.Type.PULL) + .setUrl(oauthRegParams.getUrl()) + .buildBodyMessage(); + } else { + request = OAuthClientRegistrationRequest + .location(oauthRegParams.getRegistrationEndpoint(), OAuthRegistration.Type.PUSH) + .setName(oauthRegParams.getName()) + .setUrl(oauthRegParams.getUrl()) + .setDescription(oauthRegParams.getDescription()) + .setRedirectURI(oauthRegParams.getRedirectUri()) + .setIcon(oauthRegParams.getIcon()) + .buildBodyMessage(); + } + + + OAuthRegistrationClient client = new OAuthRegistrationClient(new URLConnectionClient()); + OAuthClientRegistrationResponse response = client.clientInfo(request); + + oauthParams.setClientId(response.getClientId()); + oauthParams.setClientSecret(response.getClientSecret()); + oauthParams.setAuthzEndpoint(oauthRegParams.getAuthzEndpoint()); + oauthParams.setTokenEndpoint(oauthRegParams.getTokenEndpoint()); + oauthParams.setApplication(oauthRegParams.getApplication()); + oauthParams.setRedirectUri(oauthRegParams.getRedirectUri()); + + return new ModelAndView("get_authz"); + + + } catch (ApplicationException e) { + oauthRegParams.setErrorMessage(e.getMessage()); + return new ModelAndView("register"); + } catch (OAuthProblemException e) { + oauthRegParams.setErrorMessage(e.getMessage()); + return new ModelAndView("register"); + } + } + +} Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/RegistrationController.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ResourceController.java URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ResourceController.java?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ResourceController.java (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ResourceController.java Sat Dec 18 16:34:41 2010 @@ -0,0 +1,73 @@ +/** + * 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.client.demo.controller; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import javax.servlet.http.HttpServletRequest; + +import org.apache.amber.oauth2.client.demo.Utils; +import org.apache.amber.oauth2.client.demo.model.OAuthParams; +import org.apache.amber.oauth2.common.utils.OAuthUtils; +import org.apache.amber.oauth2.common.OAuth; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +/** + * @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) + */ +@Controller +@RequestMapping("/get_resource") +public class ResourceController { + + @RequestMapping + public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams, + HttpServletRequest req) { + + try { + String tokenName = OAuth.OAUTH_TOKEN_DRAFT_0; + if (Utils.SMART_GALLERY.equals(oauthParams.getApplication())) { + tokenName = OAuth.OAUTH_TOKEN; + } + URL url = new URL( + oauthParams.getResourceUrl() + "?" + tokenName + "=" + oauthParams.getAccessToken()); + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + if (conn.getResponseCode() == 200) { + oauthParams.setResource(OAuthUtils.saveStreamAsString(conn.getInputStream())); + } else { + oauthParams.setErrorMessage( + "Could not access resource: " + conn.getResponseCode() + " " + conn.getResponseMessage()); + } + } catch (IOException e) { + oauthParams.setErrorMessage(e.getMessage()); + } + + return new ModelAndView("resource"); + + + } +} Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ResourceController.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/TokenController.java URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/TokenController.java?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/TokenController.java (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/TokenController.java Sat Dec 18 16:34:41 2010 @@ -0,0 +1,106 @@ +/** + * 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.client.demo.controller; + +import java.io.IOException; +import javax.servlet.http.HttpServletRequest; + +import org.apache.amber.oauth2.client.OAuthClient; +import org.apache.amber.oauth2.client.URLConnectionClient; +import org.apache.amber.oauth2.client.demo.Utils; +import org.apache.amber.oauth2.client.demo.exception.ApplicationException; +import org.apache.amber.oauth2.client.demo.model.OAuthParams; +import org.apache.amber.oauth2.client.request.OAuthClientRequest; +import org.apache.amber.oauth2.client.response.OAuthAccessTokenResponse; +import org.apache.amber.oauth2.common.exception.OAuthProblemException; +import org.apache.amber.oauth2.common.exception.OAuthSystemException; +import org.apache.amber.oauth2.common.message.types.GrantType; +import org.apache.amber.oauth2.client.response.GitHubTokenResponse; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import org.apache.amber.oauth2.client.response.OAuthJSONAccessTokenResponse; + + +/** + * @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) + */ +@Controller +@RequestMapping("/get_token") +public class TokenController { + + @RequestMapping + public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams, + HttpServletRequest req) throws OAuthSystemException, IOException { + + try { + + Utils.validateTokenParams(oauthParams); + + OAuthClientRequest request = OAuthClientRequest + .tokenLocation(oauthParams.getTokenEndpoint()) + .setClientId(oauthParams.getClientId()) + .setClientSecret(oauthParams.getClientSecret()) + .setRedirectURI(oauthParams.getRedirectUri()) + .setCode(oauthParams.getAuthzCode()) + .setGrantType(GrantType.AUTHORIZATION_CODE) + .buildQueryMessage(); + + OAuthClient client = new OAuthClient(new URLConnectionClient()); + String app = Utils.findCookieValue(req, "app"); + + OAuthAccessTokenResponse oauthResponse = null; + Class cl = OAuthJSONAccessTokenResponse.class; + + if (Utils.FACEBOOK.equals(app)) { + cl = GitHubTokenResponse.class; + } else if (Utils.GITHUB.equals(app)) { + cl = GitHubTokenResponse.class; + } + + oauthResponse = client.accessToken(request, cl); + + oauthParams.setAccessToken(oauthResponse.getAccessToken()); + oauthParams.setExpiresIn(Utils.isIssued(oauthResponse.getExpiresIn())); + oauthParams.setRefreshToken(Utils.isIssued(oauthResponse.getRefreshToken())); + + return new ModelAndView("get_resource"); + + } catch (ApplicationException e) { + oauthParams.setErrorMessage(e.getMessage()); + return new ModelAndView("request_token"); + } catch (OAuthProblemException e) { + StringBuffer sb = new StringBuffer(); + sb.append("
"); + sb.append("Error code: ").append(e.getError()).append("
"); + sb.append("Error description: ").append(e.getDescription()).append("
"); + sb.append("Error uri: ").append(e.getUri()).append("
"); + sb.append("State: ").append(e.getState()).append("
"); + oauthParams.setErrorMessage(sb.toString()); + return new ModelAndView("get_authz"); + } + } +} Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/TokenController.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/exception/ApplicationException.java URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/exception/ApplicationException.java?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/exception/ApplicationException.java (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/exception/ApplicationException.java Sat Dec 18 16:34:41 2010 @@ -0,0 +1,46 @@ +/** + * 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.client.demo.exception; + +/** + * @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 ApplicationException extends Exception { + + public ApplicationException() { + super(); //To change body of overridden methods use File | Settings | File Templates. + } + + public ApplicationException(String s) { + super(s); //To change body of overridden methods use File | Settings | File Templates. + } + + public ApplicationException(String s, Throwable throwable) { + super(s, throwable); //To change body of overridden methods use File | Settings | File Templates. + } + + public ApplicationException(Throwable throwable) { + super(throwable); //To change body of overridden methods use File | Settings | File Templates. + } +} Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/exception/ApplicationException.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthParams.java URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthParams.java?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthParams.java (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthParams.java Sat Dec 18 16:34:41 2010 @@ -0,0 +1,159 @@ +/** + * 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.client.demo.model; + + +/** + * @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 OAuthParams { + + private String clientId; + private String clientSecret; + private String redirectUri; + private String authzEndpoint; + private String tokenEndpoint; + private String authzCode; + private String accessToken; + private String expiresIn; + private String refreshToken; + private String scope; + private String resourceUrl; + private String resource; + private String application; + + private String errorMessage; + + public String getClientId() { + return clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getClientSecret() { + return clientSecret; + } + + public void setClientSecret(String clientSecret) { + this.clientSecret = clientSecret; + } + + public String getRedirectUri() { + return redirectUri; + } + + public void setRedirectUri(String redirectUri) { + this.redirectUri = redirectUri; + } + + public String getAuthzEndpoint() { + return authzEndpoint; + } + + public void setAuthzEndpoint(String authzEndpoint) { + this.authzEndpoint = authzEndpoint; + } + + public String getTokenEndpoint() { + return tokenEndpoint; + } + + public void setTokenEndpoint(String tokenEndpoint) { + this.tokenEndpoint = tokenEndpoint; + } + + public String getAuthzCode() { + return authzCode; + } + + public void setAuthzCode(String authzCode) { + this.authzCode = authzCode; + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public String getAccessToken() { + return accessToken; + } + + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + public String getExpiresIn() { + return expiresIn; + } + + public void setExpiresIn(String expiresIn) { + this.expiresIn = expiresIn; + } + + public String getRefreshToken() { + return refreshToken; + } + + public void setRefreshToken(String refreshToken) { + this.refreshToken = refreshToken; + } + + public String getResourceUrl() { + return resourceUrl; + } + + public void setResourceUrl(String resourceUrl) { + this.resourceUrl = resourceUrl; + } + + public String getResource() { + return resource; + } + + public void setResource(String resource) { + this.resource = resource; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getApplication() { + return application; + } + + public void setApplication(String application) { + this.application = application; + } +} Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthParams.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthRegParams.java URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthRegParams.java?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthRegParams.java (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthRegParams.java Sat Dec 18 16:34:41 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.client.demo.model; + +/** + * @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 OAuthRegParams extends OAuthParams { + + private String registrationType; + private String name = "OAuth V2.0 Demo Application"; + private String url = "http://localhost:8080"; + private String description = "Demo Application of the OAuth V2.0 Protocol"; + private String icon = "http://localhost:8080/demo.png"; + private String registrationEndpoint; + + public String getRegistrationType() { + return registrationType; + } + + public void setRegistrationType(String registrationType) { + this.registrationType = registrationType; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public String getRegistrationEndpoint() { + return registrationEndpoint; + } + + public void setRegistrationEndpoint(String registrationEndpoint) { + this.registrationEndpoint = registrationEndpoint; + } +} Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthRegParams.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/jdoconfig.xml URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/jdoconfig.xml?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/jdoconfig.xml (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/jdoconfig.xml Sat Dec 18 16:34:41 2010 @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/jdoconfig.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/persistence.xml URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/persistence.xml?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/persistence.xml (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/persistence.xml Sat Dec 18 16:34:41 2010 @@ -0,0 +1,38 @@ + + + + + + org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider + + + + + + + + \ No newline at end of file Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/META-INF/persistence.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/log4j.properties URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/log4j.properties?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/log4j.properties (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/log4j.properties Sat Dec 18 16:34:41 2010 @@ -0,0 +1,29 @@ +# +# Copyright 2010 Newcastle University +# +# http://research.ncl.ac.uk/smart/ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +log4j.rootCategory=INFO, CONSOLE + +# CONSOLE is set to be a ConsoleAppender using a PatternLayout. +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=[%d{yyyy-mm-dd hh:mm:ss.S},%6.6r]%-5p[%t]%x(%F:%L) - %m%n + +#log4j.logger.org.hibernate.search=TRACE \ No newline at end of file Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/resources/log4j.properties ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/app-config.xml URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/app-config.xml?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/app-config.xml (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/app-config.xml Sat Dec 18 16:34:41 2010 @@ -0,0 +1,35 @@ + + + + + + + + + Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/app-config.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/mvc-config.xml URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/mvc-config.xml?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/mvc-config.xml (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/mvc-config.xml Sat Dec 18 16:34:41 2010 @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/spring/mvc-config.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/urlrewrite.xml URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/urlrewrite.xml?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/urlrewrite.xml (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/urlrewrite.xml Sat Dec 18 16:34:41 2010 @@ -0,0 +1,40 @@ + + + + + + + / + /app/index + + + /** + /app/$1 + + + /app/** + /$1 + + Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/urlrewrite.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_authz.jsp URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_authz.jsp?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_authz.jsp (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_authz.jsp Sat Dec 18 16:34:41 2010 @@ -0,0 +1,84 @@ +<%-- + + Copyright 2010 Newcastle University + + http://research.ncl.ac.uk/smart/ + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--%> + +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ page session="false" %> +<%--@elvariable id="oauthParams" type="org.apache.amber.oauth2.client.demo.model.OAuthParams"--%> + + + + OAuth V2.0 Client Application + + + +

Sample OAuth V2.0 Client Application

+ +

Web Server Flow

+ +

Step 1. Get User's Authorization

+ + +

Error: ${oauthParams.errorMessage}

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Required OAuth parameters:
Requested Access Scope
End-User Authorization URL:
Token Endpoint:
Client ID:
Client Secret:
Redirect URI:
+ + +
+
+ + + Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_authz.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp Sat Dec 18 16:34:41 2010 @@ -0,0 +1,99 @@ +<%-- + + 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. + +--%> + +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ page session="false" %> +<%--@elvariable id="oauthParams" type="org.apache.amber.oauth2.client.demo.model.OAuthParams"--%> + + + + OAuth V2.0 Client Application + + + +

Sample OAuth V2.0 Client Application

+ +

Web Server Flow

+ +

Step 3. Get Resource

+ + +

${oauthParams.errorMessage}

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Required OAuth parameters:
Resource URL:
Access Token:
Expires In:
Refresh Token:
Requested Access Scope
End-User Authorization URL:
Token Endpoint:
Client ID:
Client Secret:
Redirect URI:
+ + +
+
+ + Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/index.jsp URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/index.jsp?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/index.jsp (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/index.jsp Sat Dec 18 16:34:41 2010 @@ -0,0 +1,47 @@ +<%-- + + 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. + +--%> + +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ page session="false" %> +<%--@elvariable id="oauthParams" type="org.apache.amber.oauth2.client.demo.model.OAuthParams"--%> + + + + OAuth V2.0 Client Application + + + +

Sample OAuth V2.0 Client Application

+ +

Web Server Flow

+ +

Choose Application

+ +Smart Gallery +Facebook +Github +Gowalla + + + Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/index.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/register.jsp URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/register.jsp?rev=1050662&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/register.jsp (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/register.jsp Sat Dec 18 16:34:41 2010 @@ -0,0 +1,93 @@ +<%-- + + 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. + +--%> + +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ page session="false" %> +<%--@elvariable id="oauthRegParams" type="org.apache.amber.oauth2.client.demo.model.OAuthRegParams"--%> + + + + OAuth V2.0 Client Application + + + +

Sample OAuth V2.0 Client Application

+ +

Dynamic Registration

+ +

Step 0. Dynamically Register Application

+ + +

${oauthRegParams.errorMessage}

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Required OAuth Dynamic Registration parameters:
Registration Type: + + +
Application Name:
Application URL:
Application Description:
Application Redirect URI:
Application Icon URL:
OAuth Registration Endpoint:
+ + + + +
+
+ + + Propchange: incubator/amber/trunk/oauth-2.0/oauth2-client-demo/src/main/webapp/WEB-INF/views/register.jsp ------------------------------------------------------------------------------ svn:eol-style = native