Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C6DFA9518 for ; Tue, 27 Sep 2011 14:48:00 +0000 (UTC) Received: (qmail 7630 invoked by uid 500); 27 Sep 2011 14:48:00 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 7577 invoked by uid 500); 27 Sep 2011 14:48:00 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 7570 invoked by uid 99); 27 Sep 2011 14:48:00 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Sep 2011 14:48:00 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Tue, 27 Sep 2011 14:47:56 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DFE9023889DA for ; Tue, 27 Sep 2011 14:47:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1176408 [1/3] - in /cxf/trunk: distribution/src/main/release/samples/oauth/ distribution/src/main/release/samples/oauth/client/ distribution/src/main/release/samples/oauth/client/src/ distribution/src/main/release/samples/oauth/client/src/... Date: Tue, 27 Sep 2011 14:47:33 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20110927144735.DFE9023889DA@eris.apache.org> Author: sergeyb Date: Tue Sep 27 14:47:30 2011 New Revision: 1176408 URL: http://svn.apache.org/viewvc?rev=1176408&view=rev Log: [CXF-2759] More refactorings plus adding a demo missed during the original commit Added: cxf/trunk/distribution/src/main/release/samples/oauth/ cxf/trunk/distribution/src/main/release/samples/oauth/README.TXT (with props) cxf/trunk/distribution/src/main/release/samples/oauth/client/ cxf/trunk/distribution/src/main/release/samples/oauth/client/pom.xml (with props) cxf/trunk/distribution/src/main/release/samples/oauth/client/src/ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/AuthorizeResourceOwnerController.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/CallbackURLController.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/GetProtectedResourceController.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/TemporaryCredentialsController.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/TokenRequestController.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/Common.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/OAuthParams.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/spring-servlet.xml (with props) cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/accessToken.jsp cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/authorizeResourceOwner.jsp cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/temporaryCredentials.jsp cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/tokenRequest.jsp cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/web.xml (with props) cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/index.jsp cxf/trunk/distribution/src/main/release/samples/oauth/server/ cxf/trunk/distribution/src/main/release/samples/oauth/server/pom.xml (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/ cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/ cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/ cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/ cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/ cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/ cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/ClientApp.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/CustomAuth.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/SampleResourceProvider.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/controllers/ cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/controllers/ApplicationController.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/controllers/MemoryOAuthDataProvider.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/controllers/OAuthClientManager.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/controllers/SampleOAuthDataProvider.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/spring/ cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/spring/AuthenticationFailureHandler.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/spring/AuthenticationSuccessfullHandler.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/spring/SpringOAuthAuthenticationFilter.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/spring/SpringSecurityExceptionMapper.java (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/webapp/ cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/webapp/WEB-INF/ cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/webapp/WEB-INF/oauth-beans.xml (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/webapp/WEB-INF/security-beans.xml (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/webapp/WEB-INF/spring-servlet.xml (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/webapp/WEB-INF/views/ cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/webapp/WEB-INF/views/authorizedClientsList.jsp cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/webapp/WEB-INF/views/clientDetails.jsp cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/webapp/WEB-INF/views/displayVerifier.jsp cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/webapp/WEB-INF/views/newClientForm.jsp cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/webapp/WEB-INF/views/registeredClientsList.jsp cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/webapp/WEB-INF/web.xml (with props) cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/webapp/index.jsp cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/webapp/oAuthLogin.jsp Modified: cxf/trunk/rt/rs/security/oauth-parent/oauth-test/src/main/java/org/apache/cxf/rs/security/oauth/test/MemoryOAuthDataProvider.java cxf/trunk/rt/rs/security/oauth-parent/oauth/src/main/java/org/apache/cxf/rs/security/oauth/data/Client.java cxf/trunk/rt/rs/security/oauth-parent/oauth/src/main/java/org/apache/cxf/rs/security/oauth/data/OAuthAuthorizationData.java cxf/trunk/rt/rs/security/oauth-parent/oauth/src/main/java/org/apache/cxf/rs/security/oauth/data/RequestTokenRegistration.java cxf/trunk/rt/rs/security/oauth-parent/oauth/src/main/java/org/apache/cxf/rs/security/oauth/data/Token.java cxf/trunk/rt/rs/security/oauth-parent/oauth/src/main/java/org/apache/cxf/rs/security/oauth/filters/AbstractAuthFilter.java cxf/trunk/rt/rs/security/oauth-parent/oauth/src/main/java/org/apache/cxf/rs/security/oauth/filters/OAuthInfo.java cxf/trunk/rt/rs/security/oauth-parent/oauth/src/main/java/org/apache/cxf/rs/security/oauth/services/AuthorizationRequestHandler.java cxf/trunk/rt/rs/security/oauth-parent/oauth/src/main/java/org/apache/cxf/rs/security/oauth/services/RequestTokenHandler.java cxf/trunk/rt/rs/security/oauth-parent/oauth/src/main/java/org/apache/cxf/rs/security/oauth/utils/OAuthConstants.java cxf/trunk/rt/rs/security/oauth-parent/oauth/src/main/java/org/apache/cxf/rs/security/oauth/utils/OAuthUtils.java Added: cxf/trunk/distribution/src/main/release/samples/oauth/README.TXT URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/README.TXT?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/README.TXT (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/README.TXT Tue Sep 27 14:47:30 2011 @@ -0,0 +1,63 @@ +OAuth 1.0a demo (client and server) +======================================== +The OAuth 1.0a demo that shows protocol's flow between OAuth parties. Demo contains two parts: + + client: + A web application capable of making OAuth-authenticated requests. It is a usual OAuth client, + not dependent on Apache CXF framework, built to test this demo server part and for OAuth + educational purposes. Implementation works with any OAuth 1.0a providers, not only inluded + in this demo. + + + server: + A web application capable of accepting OAuth-authenticated requests. It is based on Apache + CXF OAuth module. It exposes OAuth endpoints and protected resources in the form of JAX-RS + services. Server demo shows and explains how CXF OAuth module can be configured to secure + JAX-RS services and integrated with existing web applications. + +Building and running the demo using maven +--------------------------------------- + + client: + Main directory of client demo application is located in folder: "client", in base folder + of this sample. + To start demo app use maven command: + + mvn jetty:run + + It will cause in starting Jetty web server and deploying client application at host on port: 8080. + Port number is defined in pom.xml. + + server: + Main directory of server demo application is located in folder: "server", in base folder + of this sample. + To start demo app use maven command: + + mvn jetty:run + + It will cause in starting Jetty web server and deploying client application at host on port: 8081. + Port number is defined in pom.xml. + + + Both client and server modules sepends on Spring 3, so you need to use CXF spring3 profile. + You can build both client and server modules using command: + + mvn clean install + + and deploy war from 'target' folder in selected web container. + +Performing steps in the OAuth flow +----------------------------- +When you have successfully deployed client and server you can start with OAuth steps: +1. Go to OAuth server (http://localhost:8081) and login with given username and password +2. Provide details and register new application at the OAuth server. +3. You have registered client application at the OAuth server, with associated and displayed + client identifier, client shared-secret and callback url. You will need those on the client side. +4. Go to OAuth client demo (http://localhost:8080) and provide information about the registered application. +5. Perform usuall OAuth 1.0 flow steps + + + +Running OAuth 1.0a demo at Google App Engine +----------------------------- +//todo add challenges in deploying demo to GAE Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/README.TXT ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/README.TXT ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/pom.xml URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/pom.xml?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/pom.xml (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/pom.xml Tue Sep 27 14:47:30 2011 @@ -0,0 +1,101 @@ + + + 4.0.0 + org.apache.cxf.samples + oauth_demo-client + OAuth 1.0a client + http://cxf.apache.org + war + + + org.apache.cxf.samples + cxf-samples + 2.5.0-SNAPSHOT + ../../pom.xml + + + + oauth_1.0a_client + + + org.mortbay.jetty + jetty-maven-plugin + 7.4.5.v20110725 + + + / + + + + 8080 + 60000 + + + 10 + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${jdk.version} + ${jdk.version} + + + + + + + + org.springframework + spring-web + + + org.springframework + spring-webmvc + + + org.springframework + spring-core + + + org.springframework + spring-beans + + + + net.oauth.core + oauth-consumer + 20100527 + + + net.oauth.core + oauth-provider + 20100527 + + + + org.apache.geronimo.specs + geronimo-servlet_3.0_spec + 1.0 + + + + standard + taglibs + 1.1.2 + jar + runtime + + + + + + oauth + OAuth Repository + http://oauth.googlecode.com/svn/code/maven/ + + + Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/pom.xml ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/pom.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/AuthorizeResourceOwnerController.java URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/AuthorizeResourceOwnerController.java?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/AuthorizeResourceOwnerController.java (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/AuthorizeResourceOwnerController.java Tue Sep 27 14:47:30 2011 @@ -0,0 +1,51 @@ +/** + * 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 demo.oauth.client.controllers; + +import javax.servlet.http.HttpServletResponse; + +import demo.oauth.client.model.OAuthParams; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class AuthorizeResourceOwnerController { + + @RequestMapping("/authorizeResourceOwner") + public void handleRequest(@ModelAttribute(value = "oAuthParams") OAuthParams oAuthParams, + HttpServletResponse response) throws Exception { + + String oauthToken = oAuthParams.getOauthToken(); + String resourceOwnerAuthorizationEndpoint = oAuthParams.getResourceOwnerAuthorizationEndpoint(); + if (resourceOwnerAuthorizationEndpoint == null || "".equals(resourceOwnerAuthorizationEndpoint)) { + oAuthParams.setErrorMessage("Missing resource owner authorization URI"); + } + + if (oauthToken == null || "".equals(oauthToken)) { + oAuthParams.setErrorMessage("Missing oauth token"); + } + + response + .sendRedirect( + new StringBuilder().append(resourceOwnerAuthorizationEndpoint).append + ("?oauth_token=").append(oauthToken).toString()); + } +} Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/AuthorizeResourceOwnerController.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/AuthorizeResourceOwnerController.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/CallbackURLController.java URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/CallbackURLController.java?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/CallbackURLController.java (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/CallbackURLController.java Tue Sep 27 14:47:30 2011 @@ -0,0 +1,60 @@ +/** + * 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 demo.oauth.client.controllers; + +import javax.servlet.http.HttpServletRequest; + +import demo.oauth.client.model.Common; +import demo.oauth.client.model.OAuthParams; + +import net.oauth.OAuth; +import net.oauth.OAuthMessage; +import net.oauth.OAuthProblemException; +import net.oauth.server.OAuthServlet; + +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; + + +@Controller +public class CallbackURLController { + + @RequestMapping("/callback") + protected ModelAndView handleRequest(@ModelAttribute("oAuthParams") OAuthParams oAuthParams, + HttpServletRequest request) throws Exception { + + OAuthMessage message = OAuthServlet.getMessage(request, request.getRequestURL().toString()); + + try { + message.requireParameters(OAuth.OAUTH_TOKEN, OAuth.OAUTH_VERIFIER); + oAuthParams.setOauthToken(message.getToken()); + oAuthParams.setOauthVerifier(message.getParameter(OAuth.OAUTH_VERIFIER)); + + oAuthParams.setClientID(Common.findCookieValue(request, "clientID")); + oAuthParams.setClientSecret(Common.findCookieValue(request, "clientSecret")); + } catch (OAuthProblemException e) { + oAuthParams.setErrorMessage("OAuth problem: " + e.getProblem() + e.getParameters().toString()); + } + + + return new ModelAndView("tokenRequest"); + } +} Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/CallbackURLController.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/CallbackURLController.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/GetProtectedResourceController.java URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/GetProtectedResourceController.java?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/GetProtectedResourceController.java (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/GetProtectedResourceController.java Tue Sep 27 14:47:30 2011 @@ -0,0 +1,137 @@ +/** + * 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 demo.oauth.client.controllers; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import javax.servlet.http.HttpServletRequest; + +import demo.oauth.client.model.OAuthParams; + +import net.oauth.OAuth; +import net.oauth.OAuthAccessor; +import net.oauth.OAuthConsumer; +import net.oauth.OAuthMessage; +import net.oauth.OAuthServiceProvider; +import net.oauth.ParameterStyle; +import net.oauth.client.OAuthClient; +import net.oauth.client.OAuthResponseMessage; +import net.oauth.client.URLConnectionClient; + +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; + + +@Controller +public class GetProtectedResourceController { + + @RequestMapping("/getProtectedResource") + protected ModelAndView handleRequest(@ModelAttribute("oAuthParams") OAuthParams oAuthParams, + HttpServletRequest request) + throws Exception { + + OAuthServiceProvider provider = new OAuthServiceProvider( + oAuthParams.getTemporaryCredentialsEndpoint(), + oAuthParams.getResourceOwnerAuthorizationEndpoint(), null); + + OAuthConsumer consumer = new OAuthConsumer(null, oAuthParams.getClientID(), + oAuthParams.getClientSecret(), + provider); + OAuthAccessor accessor = new OAuthAccessor(consumer); + accessor.requestToken = oAuthParams.getOauthToken(); + accessor.tokenSecret = oAuthParams.getOauthTokenSecret(); + + Map parameters = new HashMap(); + parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, oAuthParams.getSignatureMethod()); + parameters.put(OAuth.OAUTH_NONCE, UUID.randomUUID().toString()); + parameters.put(OAuth.OAUTH_TIMESTAMP, String.valueOf(System.currentTimeMillis() / 1000)); + parameters.put(OAuth.OAUTH_TOKEN, oAuthParams.getOauthToken()); + parameters.put(OAuth.OAUTH_CONSUMER_KEY, oAuthParams.getClientID()); + + OAuthMessage msg = null; + String method = request.getParameter("op"); + + + if ("GET".equals(method)) { + msg = accessor + .newRequestMessage(OAuthMessage.GET, oAuthParams.getGetResourceURL(), parameters.entrySet()); + } else { + msg = accessor + .newRequestMessage(OAuthMessage.POST, oAuthParams.getPostResourceURL(), + parameters.entrySet()); + } + + + OAuthClient client = new OAuthClient(new URLConnectionClient()); + + msg = client.access(msg, ParameterStyle.QUERY_STRING); + + StringBuffer bodyBuffer = readBody(msg); + + oAuthParams.setResourceResponse(bodyBuffer.toString()); + String authHeader = msg.getHeader("WWW-Authenticate"); + String oauthHeader = msg.getHeader("OAuth"); + String header = ""; + + if (authHeader != null) { + header += "WWW-Authenticate:" + authHeader; + } + + if (oauthHeader != null) { + header += "OAuth:" + oauthHeader; + } + + oAuthParams.setHeader(header); + oAuthParams.setResponseCode(((OAuthResponseMessage)msg).getHttpResponse().getStatusCode()); + + return new ModelAndView("accessToken"); + } + + private StringBuffer readBody(OAuthMessage msg) throws IOException { + StringBuffer body = new StringBuffer(); + InputStream responseBody = null; + BufferedReader br = null; + try { + responseBody = msg.getBodyAsStream(); + if (responseBody != null) { + br = new BufferedReader(new InputStreamReader(responseBody)); + String buf; + while ((buf = br.readLine()) != null) { + body.append(buf); + } + } + } finally { + if (br != null) { + br.close(); + } + if (responseBody != null) { + responseBody.close(); + } + } + return body; + } + +} Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/GetProtectedResourceController.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/GetProtectedResourceController.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/TemporaryCredentialsController.java URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/TemporaryCredentialsController.java?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/TemporaryCredentialsController.java (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/TemporaryCredentialsController.java Tue Sep 27 14:47:30 2011 @@ -0,0 +1,123 @@ +/** + * 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 demo.oauth.client.controllers; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletResponse; + +import demo.oauth.client.model.OAuthParams; + +import net.oauth.OAuth; +import net.oauth.OAuthAccessor; +import net.oauth.OAuthConsumer; +import net.oauth.OAuthMessage; +import net.oauth.OAuthServiceProvider; +import net.oauth.ParameterStyle; +import net.oauth.client.OAuthClient; +import net.oauth.client.URLConnectionClient; + + +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; + +@Controller +public class TemporaryCredentialsController { + + @RequestMapping("/handleTemporaryCredentials") + public ModelAndView handleRequest(@ModelAttribute(value = "oAuthParams") OAuthParams oAuthParams, + HttpServletResponse response) { + + OAuthServiceProvider provider; + OAuthConsumer consumer; + OAuthAccessor accessor; + + OAuthClient client = new OAuthClient(new URLConnectionClient()); + + oAuthParams.setErrorMessage(null); + String temporaryCredentialsEndpointUrl = oAuthParams.getTemporaryCredentialsEndpoint(); + if (temporaryCredentialsEndpointUrl == null || "".equals(temporaryCredentialsEndpointUrl)) { + oAuthParams.setErrorMessage("Missing temporary credentials endpoint url"); + } + String clientId = oAuthParams.getClientID(); + if (clientId == null || "".equals(clientId)) { + oAuthParams.setErrorMessage("Missing client identifier"); + } + String secret = oAuthParams.getClientSecret(); + if (secret == null || "".equals(secret)) { + oAuthParams.setErrorMessage("Missing client shared-secret"); + } + + if (oAuthParams.getErrorMessage() == null) { + provider = new OAuthServiceProvider(temporaryCredentialsEndpointUrl, + oAuthParams.getResourceOwnerAuthorizationEndpoint(), oAuthParams.getTokenRequestEndpoint()); + consumer = new OAuthConsumer(null, clientId, + secret, + provider); + accessor = new OAuthAccessor(consumer); + + Map parameters = new HashMap(); + parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, oAuthParams.getSignatureMethod()); + parameters.put(OAuth.OAUTH_NONCE, UUID.randomUUID().toString()); + parameters.put(OAuth.OAUTH_TIMESTAMP, String.valueOf(System.currentTimeMillis() / 1000)); + parameters.put(OAuth.OAUTH_CALLBACK, oAuthParams.getCallbackURL()); + parameters.put("realm", "private"); + parameters.put("x_oauth_scope", "read_info,modify_info"); + parameters.put("x_oauth_uri", "/resources/person/*"); + + + try { + accessor.consumer + .setProperty(OAuthClient.PARAMETER_STYLE, ParameterStyle.AUTHORIZATION_HEADER); + client.getRequestToken(accessor, OAuthMessage.POST, parameters.entrySet()); + } catch (Exception e) { + oAuthParams.setErrorMessage(e.toString()); + } + + oAuthParams.setOauthToken(accessor.requestToken); + oAuthParams.setOauthTokenSecret(accessor.tokenSecret); + Cookie cId = new Cookie("clientID", oAuthParams.getClientID()); + Cookie cSec = new Cookie("clientSecret", oAuthParams.getClientSecret()); + Cookie tokenSec = new Cookie("tokenSec", accessor.tokenSecret); + response.addCookie(cId); + response.addCookie(cSec); + response.addCookie(tokenSec); + } + + ModelAndView modelAndView = new ModelAndView(); + if (oAuthParams.getErrorMessage() != null) { + modelAndView.setViewName("temporaryCredentials"); + } else { + modelAndView.setViewName("authorizeResourceOwner"); + } + + return modelAndView; + } + + @RequestMapping("/temporaryCredentials") + public ModelAndView handleInternalRequest( + @ModelAttribute(value = "oAuthParams") OAuthParams oAuthParams) { + return new ModelAndView("temporaryCredentials"); + } + +} Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/TemporaryCredentialsController.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/TemporaryCredentialsController.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/TokenRequestController.java URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/TokenRequestController.java?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/TokenRequestController.java (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/TokenRequestController.java Tue Sep 27 14:47:30 2011 @@ -0,0 +1,112 @@ +/** + * 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 demo.oauth.client.controllers; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import javax.servlet.http.HttpServletRequest; + +import demo.oauth.client.model.Common; +import demo.oauth.client.model.OAuthParams; + + +import net.oauth.OAuth; +import net.oauth.OAuthAccessor; +import net.oauth.OAuthConsumer; +import net.oauth.OAuthMessage; +import net.oauth.OAuthServiceProvider; +import net.oauth.client.OAuthClient; +import net.oauth.client.URLConnectionClient; + + +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; + +@Controller +public class TokenRequestController { + + @RequestMapping("/tokenRequest") + protected ModelAndView handleRequest(@ModelAttribute("oAuthParams") OAuthParams oAuthParams, + HttpServletRequest request) + throws Exception { + + String oauthToken = oAuthParams.getOauthToken(); + + String tokenRequestEndpoint = oAuthParams.getTokenRequestEndpoint(); + String clientID = oAuthParams.getClientID(); + + if (tokenRequestEndpoint == null || "".equals(tokenRequestEndpoint)) { + oAuthParams.setErrorMessage("Missing token request URI"); + } + + if (clientID == null || "".equals(clientID)) { + oAuthParams.setErrorMessage("Missing consumer key"); + } + + if (oauthToken == null || "".equals(oauthToken)) { + oAuthParams.setErrorMessage("Missing oauth token"); + } + + String verifier = oAuthParams.getOauthVerifier(); + if (verifier == null || "".equals(verifier)) { + oAuthParams.setErrorMessage("Missing oauth verifier"); + } + + if (oAuthParams.getErrorMessage() == null) { + OAuthClient client = new OAuthClient(new URLConnectionClient()); + OAuthServiceProvider provider = new OAuthServiceProvider( + oAuthParams.getTemporaryCredentialsEndpoint(), + oAuthParams.getResourceOwnerAuthorizationEndpoint(), tokenRequestEndpoint); + + OAuthConsumer consumer = new OAuthConsumer(null, clientID, + oAuthParams.getClientSecret(), + provider); + OAuthAccessor accessor = new OAuthAccessor(consumer); + accessor.requestToken = oauthToken; + accessor.tokenSecret = Common.findCookieValue(request, "tokenSec"); + + Map parameters = new HashMap(); + parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, oAuthParams.getSignatureMethod()); + parameters.put(OAuth.OAUTH_NONCE, UUID.randomUUID().toString()); + parameters.put(OAuth.OAUTH_TIMESTAMP, String.valueOf(System.currentTimeMillis() / 1000)); + parameters.put(OAuth.OAUTH_TOKEN, oauthToken); + parameters.put(OAuth.OAUTH_VERIFIER, oAuthParams.getOauthVerifier()); + + + try { + client.getAccessToken(accessor, OAuthMessage.GET, parameters.entrySet()); + oAuthParams.setOauthToken(accessor.accessToken); + } catch (Exception e) { + oAuthParams.setErrorMessage(e.toString()); + oAuthParams.setOauthToken(oauthToken); + return new ModelAndView("tokenRequest"); + } + oAuthParams.setOauthTokenSecret(accessor.tokenSecret); + } + + oAuthParams.setClientID(Common.findCookieValue(request, "clientID")); + oAuthParams.setClientSecret(Common.findCookieValue(request, "clientSecret")); + + return new ModelAndView("accessToken"); + } + +} Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/TokenRequestController.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/controllers/TokenRequestController.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/Common.java URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/Common.java?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/Common.java (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/Common.java Tue Sep 27 14:47:30 2011 @@ -0,0 +1,38 @@ +/** + * 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 demo.oauth.client.model; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; + +public final class Common { + private Common() { + } + + public static String findCookieValue(HttpServletRequest request, String key) { + Cookie[] cookies = request.getCookies(); + + for (Cookie cooky : cookies) { + if (cooky.getName().equals(key)) { + return cooky.getValue(); + } + } + return ""; + } +} Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/Common.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/Common.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/OAuthParams.java URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/OAuthParams.java?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/OAuthParams.java (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/OAuthParams.java Tue Sep 27 14:47:30 2011 @@ -0,0 +1,210 @@ +/** + * 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 demo.oauth.client.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class OAuthParams implements Serializable { + private String temporaryCredentialsEndpoint = "http://localhost:8081/auth/oauth/initiate"; + private String resourceOwnerAuthorizationEndpoint = "http://localhost:8081/auth/oauth/authorize"; + private String tokenRequestEndpoint = "http://localhost:8081/auth/oauth/token"; + private String getResourceURL = "http://localhost:8081/auth/resources/person/get/john"; + private String postResourceURL = "http://localhost:8081/auth/resources/person/modify/john"; + + private String callbackURL = "http://localhost:8080/app/callback"; + + private String clientID = "12345678"; + private String clientSecret = "secret"; + private String signatureMethod; + + private String oauthToken; + private String oauthTokenSecret; + private String oauthVerifier; + + private String errorMessage; + private String resourceResponse; + private String header; + private Integer responseCode; + + private List methods = new ArrayList(); + + public OAuthParams() { + methods.add(new SignatureMethod("HMAC-SHA1")); + } + + public OAuthParams(String clientSecret, String clientID) { + super(); + this.clientSecret = clientSecret; + this.clientID = clientID; + } + + public String getClientSecret() { + return clientSecret; + } + + public void setClientSecret(String clientSecret) { + this.clientSecret = clientSecret; + } + + public String getClientID() { + return clientID; + } + + public void setClientID(String clientID) { + this.clientID = clientID; + } + + public String getSignatureMethod() { + return signatureMethod; + } + + public void setSignatureMethod(String signatureMethod) { + this.signatureMethod = signatureMethod; + } + + public String getTemporaryCredentialsEndpoint() { + return temporaryCredentialsEndpoint; + } + + public void setTemporaryCredentialsEndpoint(String temporaryCredentialsEndpoint) { + this.temporaryCredentialsEndpoint = temporaryCredentialsEndpoint; + } + + public String getOauthToken() { + return oauthToken; + } + + public void setOauthToken(String oauthToken) { + this.oauthToken = oauthToken; + } + + public String getOauthTokenSecret() { + return oauthTokenSecret; + } + + public void setOauthTokenSecret(String oauthTokenSecret) { + this.oauthTokenSecret = oauthTokenSecret; + } + + public String getResourceOwnerAuthorizationEndpoint() { + return resourceOwnerAuthorizationEndpoint; + } + + public void setResourceOwnerAuthorizationEndpoint(String resourceOwnerAuthorizationEndpoint) { + this.resourceOwnerAuthorizationEndpoint = resourceOwnerAuthorizationEndpoint; + } + + public String getTokenRequestEndpoint() { + return tokenRequestEndpoint; + } + + public void setTokenRequestEndpoint(String tokenRequestEndpoint) { + this.tokenRequestEndpoint = tokenRequestEndpoint; + } + + public String getOauthVerifier() { + return oauthVerifier; + } + + public void setOauthVerifier(String oauthVerifier) { + this.oauthVerifier = oauthVerifier; + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public String getGetResourceURL() { + return getResourceURL; + } + + public void setGetResourceURL(String getResourceURL) { + this.getResourceURL = getResourceURL; + } + + public String getCallbackURL() { + return callbackURL; + } + + public void setCallbackURL(String callbackURL) { + this.callbackURL = callbackURL; + } + + public String getResourceResponse() { + return resourceResponse; + } + + public void setResourceResponse(String resourceResponse) { + this.resourceResponse = resourceResponse; + } + + public String getHeader() { + return header; + } + + public void setHeader(String header) { + this.header = header; + } + + public List getMethods() { + return methods; + } + + public void setMethods(List methods) { + this.methods = methods; + } + + public String getPostResourceURL() { + return postResourceURL; + } + + public void setPostResourceURL(String postResourceURL) { + this.postResourceURL = postResourceURL; + } + + public Integer getResponseCode() { + return responseCode; + } + + public void setResponseCode(Integer responseCode) { + this.responseCode = responseCode; + } + + static class SignatureMethod { + private String methodName; + + SignatureMethod(String methodName) { + this.methodName = methodName; + } + + public String getMethodName() { + return methodName; + } + + public void setMethodName(String methodName) { + this.methodName = methodName; + } + } +} Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/OAuthParams.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/java/demo/oauth/client/model/OAuthParams.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/spring-servlet.xml URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/spring-servlet.xml?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/spring-servlet.xml (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/spring-servlet.xml Tue Sep 27 14:47:30 2011 @@ -0,0 +1,36 @@ + + + + + + + + + + + + + Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/spring-servlet.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/spring-servlet.xml ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/spring-servlet.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/accessToken.jsp URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/accessToken.jsp?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/accessToken.jsp (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/accessToken.jsp Tue Sep 27 14:47:30 2011 @@ -0,0 +1,93 @@ + +<%--@elvariable id="oAuthParams" type="org.apache.cxf.auth.oauth.demo.client.model.OAuthParams"--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ page isELIgnored="false" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> + + + + OAuth Client + + + + + + +

Sample OAuth 1.0a client implementation

+

Step 4. Get Protected Resource

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OAuth Token:
OAuth Secret:
Client Identifier:
Client Shared-Secret:
GET Protected Resource, need scope: 'read_info'
POST Protected Resource, need scope: 'modify_info'
Signature Method: + +
+ +
+ +
+
+ + +

Response: ${oAuthParams.resourceResponse}

+
+ +

Header:${oAuthParams.header}

+
+ +

Response Status:${oAuthParams.responseCode}

+
+ + \ No newline at end of file Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/authorizeResourceOwner.jsp URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/authorizeResourceOwner.jsp?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/authorizeResourceOwner.jsp (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/authorizeResourceOwner.jsp Tue Sep 27 14:47:30 2011 @@ -0,0 +1,73 @@ + +<%--@elvariable id="text" type="java.lang.String"--%> +<%--@elvariable id="oAuthParams" type="org.apache.cxf.auth.oauth.demo.client.model.OAuthParams"--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ page isELIgnored="false" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> + + + + OAuth 1.0a client + + + + + + +

Sample OAuth 1.0a client implementation

+

Step 2. Authorize Resource Owner

+ + + +

Error: ${oAuthParams.errorMessage}

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Response:
OAuth Token:
OAuth Token Secret:
  
Required OAuth parameters:
Resource Owner Authorization Endpoint URI:
+ +
+
+ + \ No newline at end of file Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/temporaryCredentials.jsp URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/temporaryCredentials.jsp?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/temporaryCredentials.jsp (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/temporaryCredentials.jsp Tue Sep 27 14:47:30 2011 @@ -0,0 +1,83 @@ + +<%--@elvariable id="text" type="java.lang.String"--%> +<%--@elvariable id="oAuthParams" type="org.apache.cxf.auth.oauth.demo.client.model.OAuthParams"--%> +<%--@elvariable id="methods" type="java.util.List"--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ page isELIgnored="false" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> + + + + OAuth 1.0a client + + + + + + +

Sample OAuth 1.0a client implementation

+ +

+ +

Step 1. Get OAuth temporary credentials

+ + + +

Error: ${oAuthParams.errorMessage}

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Required OAuth parameters:
Temporary Credentials Endoint URI:
Client Identifier:
Client Shared-Secret:
Callback URL:
Signature Method: + + + +
+ +
+
+ + \ No newline at end of file Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/tokenRequest.jsp URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/tokenRequest.jsp?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/tokenRequest.jsp (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/views/tokenRequest.jsp Tue Sep 27 14:47:30 2011 @@ -0,0 +1,92 @@ + +<%--@elvariable id="text" type="java.lang.String"--%> +<%--@elvariable id="oAuthParams" type="org.apache.cxf.auth.oauth.demo.client.model.OAuthParams"--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ page isELIgnored="false" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> + + + + OAuth 1.0a Client + + + + + + +

Sample OAuth 1.0a client implementation

+

Step 3. Request Access Token

+ + + +

Error: ${oAuthParams.errorMessage}

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Response:
OAuth Token:
OAuth Verifier:
  
Required OAuth parameters:
Token Request URI:
Client Identifier:
Client Shared-Secret:
Signature Method: + + + +
+ +
+
+ + \ No newline at end of file Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/web.xml?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/web.xml (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/web.xml Tue Sep 27 14:47:30 2011 @@ -0,0 +1,49 @@ + + + + + contextConfigLocation + /WEB-INF/spring-servlet.xml + + + + org.springframework.web.context.ContextLoaderListener + + + + spring + org.springframework.web.servlet.DispatcherServlet + 1 + + + + spring + /app/* + + + + + index.jsp + + Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/web.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/web.xml ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/WEB-INF/web.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/index.jsp URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/index.jsp?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/index.jsp (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/client/src/main/webapp/index.jsp Tue Sep 27 14:47:30 2011 @@ -0,0 +1,20 @@ + +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%response.sendRedirect("/app/temporaryCredentials"); %> Added: cxf/trunk/distribution/src/main/release/samples/oauth/server/pom.xml URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/server/pom.xml?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/server/pom.xml (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/server/pom.xml Tue Sep 27 14:47:30 2011 @@ -0,0 +1,138 @@ + + + 4.0.0 + org.apache.cxf.samples + oauth_demo-server + OAuth 1.0a server + war + + + org.apache.cxf.samples + cxf-samples + 2.5.0-SNAPSHOT + ../../pom.xml + + + + oauth_1.0a_server + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.24 + + + / + + + + 8081 + 60000 + + + 10 + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${jdk.version} + ${jdk.version} + + + + + + + + org.apache.cxf + cxf-rt-rs-security-oauth + ${project.version} + + + + org.apache.cxf + cxf-rt-transports-http-jetty + ${project.version} + + + org.apache.cxf + cxf-rt-frontend-jaxrs + ${project.version} + + + org.springframework + spring-web + 3.0.3.RELEASE + + + org.springframework + spring-webmvc + 3.0.3.RELEASE + + + + org.springframework + spring-core + 3.0.3.RELEASE + + + org.springframework + spring-beans + 3.0.3.RELEASE + + + org.springframework + spring-context + 3.0.3.RELEASE + + + org.springframework.security + spring-security-core + 3.0.3.RELEASE + + + org.springframework.security + spring-security-web + 3.0.3.RELEASE + + + org.springframework.security + spring-security-config + 3.0.3.RELEASE + + + org.springframework.security + spring-security-acl + 3.0.3.RELEASE + + + javax.annotation + jsr250-api + 1.0 + + + cglib + cglib + 2.1 + + + asm + asm + 1.5.3 + + + + + standard + taglibs + 1.1.2 + jar + runtime + + + + Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/server/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/server/pom.xml ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/server/pom.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/ClientApp.java URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/ClientApp.java?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/ClientApp.java (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/ClientApp.java Tue Sep 27 14:47:30 2011 @@ -0,0 +1,60 @@ +/** + * 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 demo.oauth.server; + +import java.io.Serializable; + +public class ClientApp implements Serializable { + private String clientName = "OAuth 1.0a client"; + private String callbackURL = "http://localhost:8080/app/callback"; + private String consumerKey; + private String error; + + public String getClientName() { + return clientName; + } + + public void setClientName(String clientName) { + this.clientName = clientName; + } + + public String getCallbackURL() { + return callbackURL; + } + + public void setCallbackURL(String callbackURL) { + this.callbackURL = callbackURL; + } + + public String getError() { + return error; + } + + public void setError(String error) { + this.error = error; + } + + public String getConsumerKey() { + return consumerKey; + } + + public void setConsumerKey(String consumerKey) { + this.consumerKey = consumerKey; + } +} Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/ClientApp.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/ClientApp.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/CustomAuth.java URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/CustomAuth.java?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/CustomAuth.java (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/CustomAuth.java Tue Sep 27 14:47:30 2011 @@ -0,0 +1,18 @@ +package demo.oauth.server; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint; + + +public class CustomAuth extends LoginUrlAuthenticationEntryPoint { + @Override + public void commence(HttpServletRequest request, HttpServletResponse response, + AuthenticationException authException) throws IOException, ServletException { + super.commence(request, response, authException); + } +} Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/CustomAuth.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/CustomAuth.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/SampleResourceProvider.java URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/SampleResourceProvider.java?rev=1176408&view=auto ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/SampleResourceProvider.java (added) +++ cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/SampleResourceProvider.java Tue Sep 27 14:47:30 2011 @@ -0,0 +1,54 @@ +/** + * 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 demo.oauth.server; + +import javax.annotation.security.RolesAllowed; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; + +import org.springframework.security.access.annotation.Secured; + +/** + * Sample JAX-RS resource service + */ +@Path("/") +public class SampleResourceProvider { + + @GET + @Produces("text/html") + @Path("/person/get/{name}") + @Secured ({"ROLE_USER"}) + public Response getInfo(@PathParam("name") String name, @Context HttpServletRequest request) { + return Response.ok("Successfully accessed OAuth protected person: " + name).build(); + } + + @POST + @Produces("text/html") + @Path("/person/modify/{name}") + @Secured( {"ROLE_ADMIN"}) + public Response modifyInfo(@PathParam("name") String name, @Context HttpServletRequest request) { + return Response.ok("Successfully modified OAuth protected person: " + name).build(); + } +} Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/SampleResourceProvider.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/distribution/src/main/release/samples/oauth/server/src/main/java/demo/oauth/server/SampleResourceProvider.java ------------------------------------------------------------------------------ svn:keywords = Rev Date