oltu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ja...@apache.org
Subject svn commit: r1732766 - in /oltu/trunk/demos/client-demo: ./ src/main/java/org/apache/oltu/oauth2/client/demo/controller/ src/main/resources/
Date Sun, 28 Feb 2016 16:43:35 GMT
Author: jasha
Date: Sun Feb 28 16:43:34 2016
New Revision: 1732766

URL: http://svn.apache.org/viewvc?rev=1732766&view=rev
Log:
OLTU-154 Fix logging config and add error logging in client-demo
Thanks for the patch Marko Asplund

Modified:
    oltu/trunk/demos/client-demo/pom.xml
    oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/AuthzController.java
    oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/MainController.java
    oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RedirectController.java
    oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RegistrationController.java
    oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/ResourceController.java
    oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/TokenController.java
    oltu/trunk/demos/client-demo/src/main/resources/log4j.properties

Modified: oltu/trunk/demos/client-demo/pom.xml
URL: http://svn.apache.org/viewvc/oltu/trunk/demos/client-demo/pom.xml?rev=1732766&r1=1732765&r2=1732766&view=diff
==============================================================================
--- oltu/trunk/demos/client-demo/pom.xml (original)
+++ oltu/trunk/demos/client-demo/pom.xml Sun Feb 28 16:43:34 2016
@@ -34,13 +34,20 @@
     <oltu.oidc.version>0.1-SNAPSHOT</oltu.oidc.version>
     <org.springframework.version>3.2.4.RELEASE</org.springframework.version>
     <servlet-api.version>2.5</servlet-api.version>
+    <slf4j.version>1.7.18</slf4j.version>
   </properties>
 
   <dependencies>
     <dependency>
       <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-jcl</artifactId>
-      <version>1.7.7</version>
+      <artifactId>jcl-over-slf4j</artifactId>
+      <version>${slf4j.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>${slf4j.version}</version>
     </dependency>
 
     <!-- OAuth Dependency -->
@@ -143,7 +150,6 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-war-plugin</artifactId>
-        <version>2.2</version>
         <configuration>
           <webResources>
             <resource>

Modified: oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/AuthzController.java
URL: http://svn.apache.org/viewvc/oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/AuthzController.java?rev=1732766&r1=1732765&r2=1732766&view=diff
==============================================================================
--- oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/AuthzController.java
(original)
+++ oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/AuthzController.java
Sun Feb 28 16:43:34 2016
@@ -20,11 +20,12 @@
  */
 package org.apache.oltu.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.oltu.oauth2.client.demo.Utils;
+import org.apache.oltu.oauth2.client.demo.exception.ApplicationException;
+import org.apache.oltu.oauth2.client.demo.model.OAuthParams;
+import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
+import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
+import org.apache.oltu.oauth2.common.message.types.ResponseType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Controller;
@@ -33,18 +34,15 @@ import org.springframework.web.bind.anno
 import org.springframework.web.servlet.ModelAndView;
 import org.springframework.web.servlet.view.RedirectView;
 
-import org.apache.oltu.oauth2.client.demo.Utils;
-import org.apache.oltu.oauth2.client.demo.exception.ApplicationException;
-import org.apache.oltu.oauth2.client.demo.model.OAuthParams;
-import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
-import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
-import org.apache.oltu.oauth2.common.message.types.ResponseType;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 
 /**
  * Handles requests for the application welcome page.
  */
 @Controller
-@RequestMapping("/")
 public class AuthzController {
 
     private Logger logger = LoggerFactory.getLogger(AuthzController.class);
@@ -55,6 +53,8 @@ public class AuthzController {
                                   HttpServletResponse res)
         throws OAuthSystemException, IOException {
 
+        logger.debug("start processing /authorize request");
+
         try {
             Utils.validateAuthorizationParams(oauthParams);
 
@@ -78,6 +78,7 @@ public class AuthzController {
 
             return new ModelAndView(new RedirectView(request.getLocationUri()));
         } catch (ApplicationException e) {
+            logger.error("failed to validate OAuth authorization request parameters", e);
             oauthParams.setErrorMessage(e.getMessage());
             return new ModelAndView("get_authz");
         }

Modified: oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/MainController.java
URL: http://svn.apache.org/viewvc/oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/MainController.java?rev=1732766&r1=1732765&r2=1732766&view=diff
==============================================================================
--- oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/MainController.java
(original)
+++ oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/MainController.java
Sun Feb 28 16:43:34 2016
@@ -20,10 +20,6 @@
  */
 package org.apache.oltu.oauth2.client.demo.controller;
 
-import java.io.IOException;
-
-import javax.servlet.http.HttpServletResponse;
-
 import org.apache.oltu.oauth2.client.demo.Utils;
 import org.apache.oltu.oauth2.client.demo.model.OAuthParams;
 import org.apache.oltu.oauth2.client.demo.model.OAuthRegParams;
@@ -32,7 +28,6 @@ import org.apache.oltu.oauth2.jwt.JWT;
 import org.apache.oltu.oauth2.jwt.io.JWTClaimsSetWriter;
 import org.apache.oltu.oauth2.jwt.io.JWTHeaderWriter;
 import org.apache.oltu.oauth2.jwt.io.JWTReader;
-import org.apache.oltu.oauth2.jwt.io.JWTWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Controller;
@@ -41,18 +36,18 @@ import org.springframework.web.bind.anno
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.servlet.ModelAndView;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
 /**
  */
 @Controller
-@RequestMapping("/")
 public class MainController {
 
     private Logger logger = LoggerFactory.getLogger(MainController.class);
 
     private final JWTReader jwtReader = new JWTReader();
 
-    private final JWTWriter jwtWriter = new JWTWriter();
-
     @RequestMapping("/index")
     public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams)
         throws OAuthSystemException, IOException {
@@ -73,15 +68,14 @@ public class MainController {
             selected = true;
             oauthParams.setAuthzEndpoint(Utils.GITHUB_AUTHZ);
             oauthParams.setTokenEndpoint(Utils.GITHUB_TOKEN);
-
         } else if (Utils.FACEBOOK.equalsIgnoreCase(app)) {
             selected = true;
             oauthParams.setAuthzEndpoint(Utils.FACEBOOK_AUTHZ);
             oauthParams.setTokenEndpoint(Utils.FACEBOOK_TOKEN);
         } else if (Utils.GOOGLE.equalsIgnoreCase(app)) {
-                selected = true;
-                oauthParams.setAuthzEndpoint(Utils.GOOGLE_AUTHZ);
-                oauthParams.setTokenEndpoint(Utils.GOOGLE_TOKEN);
+            selected = true;
+            oauthParams.setAuthzEndpoint(Utils.GOOGLE_AUTHZ);
+            oauthParams.setTokenEndpoint(Utils.GOOGLE_TOKEN);
         } else if (Utils.LINKEDIN.equalsIgnoreCase(app)) {
             selected = true;
             oauthParams.setAuthzEndpoint(Utils.LINKEDIN_AUTHZ);
@@ -112,8 +106,8 @@ public class MainController {
             oauthParams.setHeader(new JWTHeaderWriter().write(jwt.getHeader()));
             oauthParams.setClaimsSet(new JWTClaimsSetWriter().write(jwt.getClaimsSet()));
         } catch (Exception e){
-            oauthParams.setErrorMessage(
-                    "Error while decoding the token: " + e);
+            logger.error("Error while decoding the token", e);
+            oauthParams.setErrorMessage("Error while decoding the token: " + e);
         }
 
         return new ModelAndView("index");

Modified: oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RedirectController.java
URL: http://svn.apache.org/viewvc/oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RedirectController.java?rev=1732766&r1=1732765&r2=1732766&view=diff
==============================================================================
--- oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RedirectController.java
(original)
+++ oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RedirectController.java
Sun Feb 28 16:43:34 2016
@@ -21,37 +21,34 @@
 
 package org.apache.oltu.oauth2.client.demo.controller;
 
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
 import org.apache.oltu.oauth2.client.demo.Utils;
 import org.apache.oltu.oauth2.client.demo.model.OAuthParams;
 import org.apache.oltu.oauth2.client.response.OAuthAuthzResponse;
 import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 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;
 
-/**
- *
- *
- *
- */
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 @Controller
-@RequestMapping("/redirect")
 public class RedirectController {
+    private Logger logger = LoggerFactory.getLogger(RedirectController.class);
 
-    @RequestMapping(method = RequestMethod.GET)
+    @RequestMapping(value = "/redirect", method = RequestMethod.GET)
     public ModelAndView handleRedirect(@ModelAttribute("oauthParams") OAuthParams oauthParams,
                                        HttpServletRequest request,
                                        HttpServletResponse response) {
 
+        logger.debug("creating OAuth authorization response wrapper (/redirect)");
 
         try {
-        	
             // Get OAuth Info
             String clientId = Utils.findCookieValue(request, "clientId");
             String clientSecret = Utils.findCookieValue(request, "clientSecret");
@@ -83,12 +80,13 @@ public class RedirectController {
             oauthParams.setApplication(app);
 
         } catch (OAuthProblemException e) {
+            logger.error("failed to create OAuth authorization response wrapper", e);
             StringBuffer sb = new StringBuffer();
-            sb.append("</br>");
-            sb.append("Error code: ").append(e.getError()).append("</br>");
-            sb.append("Error description: ").append(e.getDescription()).append("</br>");
-            sb.append("Error uri: ").append(e.getUri()).append("</br>");
-            sb.append("State: ").append(e.getState()).append("</br>");
+            sb.append("<br />");
+            sb.append("Error code: ").append(e.getError()).append("<br />");
+            sb.append("Error description: ").append(e.getDescription()).append("<br />");
+            sb.append("Error uri: ").append(e.getUri()).append("<br />");
+            sb.append("State: ").append(e.getState()).append("<br />");
             oauthParams.setErrorMessage(sb.toString());
             return new ModelAndView("get_authz");
         }

Modified: oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RegistrationController.java
URL: http://svn.apache.org/viewvc/oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RegistrationController.java?rev=1732766&r1=1732765&r2=1732766&view=diff
==============================================================================
--- oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RegistrationController.java
(original)
+++ oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/RegistrationController.java
Sun Feb 28 16:43:34 2016
@@ -21,14 +21,6 @@
 
 package org.apache.oltu.oauth2.client.demo.controller;
 
-import java.io.IOException;
-import javax.servlet.http.HttpServletRequest;
-
-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.oltu.oauth2.client.URLConnectionClient;
 import org.apache.oltu.oauth2.client.demo.Utils;
 import org.apache.oltu.oauth2.client.demo.exception.ApplicationException;
@@ -41,24 +33,29 @@ import org.apache.oltu.oauth2.ext.dynami
 import org.apache.oltu.oauth2.ext.dynamicreg.client.request.OAuthClientRegistrationRequest;
 import org.apache.oltu.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse;
 import org.apache.oltu.oauth2.ext.dynamicreg.common.OAuthRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+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 javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
 
-/**
- *
- *
- *
- */
 @Controller
-@RequestMapping("/")
 public class RegistrationController {
 
+    private Logger logger = LoggerFactory.getLogger(RegistrationController.class);
+
     @RequestMapping(value = "/register")
     public ModelAndView authorize(@ModelAttribute("oauthRegParams") OAuthRegParams oauthRegParams,
                                   @ModelAttribute("oauthParams") OAuthParams oauthParams,
                                   HttpServletRequest req) throws OAuthSystemException, IOException
{
 
+        logger.debug("start processing /register request");
 
         try {
-
             Utils.validateRegistrationParams(oauthRegParams);
 
             OAuthClientRequest request = null;
@@ -91,11 +88,12 @@ public class RegistrationController {
 
             return new ModelAndView("get_authz");
 
-
         } catch (ApplicationException e) {
+            logger.error("failed to validate OAuth authorization request parameters", e);
             oauthRegParams.setErrorMessage(e.getMessage());
             return new ModelAndView("register");
         } catch (OAuthProblemException e) {
+            logger.error("failed to acquire OAuth client registration info", e);
             oauthRegParams.setErrorMessage(e.getMessage());
             return new ModelAndView("register");
         }

Modified: oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/ResourceController.java
URL: http://svn.apache.org/viewvc/oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/ResourceController.java?rev=1732766&r1=1732765&r2=1732766&view=diff
==============================================================================
--- oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/ResourceController.java
(original)
+++ oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/ResourceController.java
Sun Feb 28 16:43:34 2016
@@ -1,17 +1,17 @@
 /**
- *       Copyright 2010 Newcastle University
- *
- *          http://research.ncl.ac.uk/smart/
- *
+ * Copyright 2010 Newcastle University
+ * <p>
+ * http://research.ncl.ac.uk/smart/
+ * <p>
  * 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
  * 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.
@@ -20,8 +20,7 @@
  */
 
 package org.apache.oltu.oauth2.client.demo.controller;
- 
-import javax.servlet.http.HttpServletRequest;
+
 import org.apache.oltu.oauth2.client.OAuthClient;
 import org.apache.oltu.oauth2.client.URLConnectionClient;
 import org.apache.oltu.oauth2.client.demo.Utils;
@@ -31,52 +30,63 @@ import org.apache.oltu.oauth2.client.req
 import org.apache.oltu.oauth2.client.response.OAuthResourceResponse;
 import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
 import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 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 javax.servlet.http.HttpServletRequest;
+
 @Controller
-@RequestMapping("/get_resource")
 public class ResourceController {
 
-    @RequestMapping
+    private Logger logger = LoggerFactory.getLogger(ResourceController.class);
+
+    @RequestMapping("/get_resource")
     public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams,
                                   HttpServletRequest req) {
 
+        logger.debug("start processing /get_resource request");
+
         try {
-			OAuthClientRequest request=null; 
-			
-			if (Utils.REQUEST_TYPE_QUERY.equals(oauthParams.getRequestType())){
-				request= new OAuthBearerClientRequest(oauthParams.getResourceUrl()).setAccessToken(oauthParams.getAccessToken()).buildQueryMessage();
-			}else if (Utils.REQUEST_TYPE_HEADER.equals(oauthParams.getRequestType())){
-				request= new OAuthBearerClientRequest(oauthParams.getResourceUrl()).setAccessToken(oauthParams.getAccessToken()).buildHeaderMessage();
-			}else if (Utils.REQUEST_TYPE_BODY.equals(oauthParams.getRequestType())){
-				request= new OAuthBearerClientRequest(oauthParams.getResourceUrl()).setAccessToken(oauthParams.getAccessToken()).buildBodyMessage();
-			}			
-			
-			OAuthClient client = new OAuthClient(new URLConnectionClient());
-			OAuthResourceResponse resourceResponse= client.resource(request, oauthParams.getRequestMethod(),
OAuthResourceResponse.class);
-			
-			if (resourceResponse.getResponseCode()==200){			
-				oauthParams.setResource(resourceResponse.getBody());
-			}else{
-				oauthParams.setErrorMessage(
-	                    "Could not access resource: " + resourceResponse.getResponseCode() +
" " + resourceResponse.getBody());
-			}
-		} catch (OAuthSystemException e) {
-			 oauthParams.setErrorMessage(e.getMessage());
-		} catch (OAuthProblemException e) {
-			 oauthParams.setErrorMessage(e.getMessage());
-		}
-  
+            OAuthClientRequest request = getoAuthClientRequest(oauthParams);
+
+            OAuthClient client = new OAuthClient(new URLConnectionClient());
+            OAuthResourceResponse resourceResponse = client.resource(request, oauthParams.getRequestMethod(),
OAuthResourceResponse.class);
+
+            if (resourceResponse.getResponseCode() == 200) {
+                oauthParams.setResource(resourceResponse.getBody());
+            } else {
+                oauthParams.setErrorMessage(
+                        "Could not access resource: " + resourceResponse.getResponseCode()
+ " " + resourceResponse.getBody());
+            }
+        } catch (OAuthSystemException e) {
+            logger.error("Failed to process get_resource request", e);
+            oauthParams.setErrorMessage(e.getMessage());
+        } catch (OAuthProblemException e) {
+            logger.error("Invalid get_resource request", e);
+            oauthParams.setErrorMessage(e.getMessage());
+        }
+
         return new ModelAndView("resource");
+    }
 
+    private OAuthClientRequest getoAuthClientRequest(OAuthParams oauthParams) throws OAuthSystemException
{
+        OAuthClientRequest request = null;
 
+        OAuthBearerClientRequest oAuthBearerClientRequest =
+                new OAuthBearerClientRequest(oauthParams.getResourceUrl())
+                        .setAccessToken(oauthParams.getAccessToken());
+        String requestType = oauthParams.getRequestType();
+        if (Utils.REQUEST_TYPE_QUERY.equals(requestType)) {
+            request = oAuthBearerClientRequest.buildQueryMessage();
+        } else if (Utils.REQUEST_TYPE_HEADER.equals(requestType)) {
+            request = oAuthBearerClientRequest.buildHeaderMessage();
+        } else if (Utils.REQUEST_TYPE_BODY.equals(requestType)) {
+            request = oAuthBearerClientRequest.buildBodyMessage();
+        }
+        return request;
     }
 }

Modified: oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/TokenController.java
URL: http://svn.apache.org/viewvc/oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/TokenController.java?rev=1732766&r1=1732765&r2=1732766&view=diff
==============================================================================
--- oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/TokenController.java
(original)
+++ oltu/trunk/demos/client-demo/src/main/java/org/apache/oltu/oauth2/client/demo/controller/TokenController.java
Sun Feb 28 16:43:34 2016
@@ -21,11 +21,6 @@
 
 package org.apache.oltu.oauth2.client.demo.controller;
 
-import java.io.IOException;
-import java.net.URL;
-
-import javax.servlet.http.HttpServletRequest;
-
 import org.apache.oltu.oauth2.client.OAuthClient;
 import org.apache.oltu.oauth2.client.URLConnectionClient;
 import org.apache.oltu.oauth2.client.demo.Utils;
@@ -41,31 +36,28 @@ import org.apache.oltu.oauth2.common.mes
 import org.apache.oltu.oauth2.jwt.JWT;
 import org.apache.oltu.oauth2.jwt.io.JWTClaimsSetWriter;
 import org.apache.oltu.oauth2.jwt.io.JWTHeaderWriter;
-import org.apache.oltu.oauth2.jwt.io.JWTWriter;
 import org.apache.oltu.openidconnect.client.response.OpenIdConnectResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 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 javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.net.URI;
 
-/**
- *
- *
- *
- */
 @Controller
-@RequestMapping("/get_token")
 public class TokenController {
+    private Logger logger = LoggerFactory.getLogger(TokenController.class);
 
-    private final JWTWriter jwtWriter = new JWTWriter();
-
-    @RequestMapping
+    @RequestMapping("/get_token")
     public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams,
                                   HttpServletRequest req) throws OAuthSystemException, IOException
{
+        logger.debug("authorizing");
 
         try {
-
             Utils.validateTokenParams(oauthParams);
 
             OAuthClientRequest request = OAuthClientRequest
@@ -80,50 +72,48 @@ public class TokenController {
             OAuthClient client = new OAuthClient(new URLConnectionClient());
             String app = Utils.findCookieValue(req, "app");
 
-            OAuthAccessTokenResponse oauthResponse = null;
             Class<? extends OAuthAccessTokenResponse> cl = OAuthJSONAccessTokenResponse.class;
 
             if (Utils.FACEBOOK.equalsIgnoreCase(app)) {
                 cl = GitHubTokenResponse.class;
             } else if (Utils.GITHUB.equalsIgnoreCase(app)) {
                 cl = GitHubTokenResponse.class;
-            }else if (Utils.GOOGLE.equalsIgnoreCase(app)){
-            	cl = OpenIdConnectResponse.class;
+            } else if (Utils.GOOGLE.equalsIgnoreCase(app)){
+                cl = OpenIdConnectResponse.class;
             }
 
-            oauthResponse = client.accessToken(request, cl);
+            OAuthAccessTokenResponse oauthResponse = client.accessToken(request, cl);
 
             oauthParams.setAccessToken(oauthResponse.getAccessToken());
             oauthParams.setExpiresIn(oauthResponse.getExpiresIn());
             oauthParams.setRefreshToken(Utils.isIssued(oauthResponse.getRefreshToken()));
 
             if (Utils.GOOGLE.equalsIgnoreCase(app)){
+                OpenIdConnectResponse openIdConnectResponse = ((OpenIdConnectResponse)oauthResponse);
+                JWT idToken = openIdConnectResponse.getIdToken();
+                oauthParams.setIdToken(idToken.getRawString());
 
-            	OpenIdConnectResponse openIdConnectResponse = ((OpenIdConnectResponse)oauthResponse);
-            	JWT idToken = openIdConnectResponse.getIdToken();
-            	oauthParams.setIdToken(idToken.getRawString());
-
-            	oauthParams.setHeader(new JWTHeaderWriter().write(idToken.getHeader()));
+                oauthParams.setHeader(new JWTHeaderWriter().write(idToken.getHeader()));
                 oauthParams.setClaimsSet(new JWTClaimsSetWriter().write(idToken.getClaimsSet()));
 
-            	URL url = new URL(oauthParams.getTokenEndpoint());
-
-            	oauthParams.setIdTokenValid(openIdConnectResponse.checkId(url.getHost(), oauthParams.getClientId()));
-
+                URI uri = URI.create(oauthParams.getTokenEndpoint());
+                oauthParams.setIdTokenValid(openIdConnectResponse.checkId(uri.getHost(),
oauthParams.getClientId()));
             }
 
             return new ModelAndView("get_resource");
 
         } catch (ApplicationException e) {
+            logger.error("failed to validate OAuth token request parameters", e);
             oauthParams.setErrorMessage(e.getMessage());
             return new ModelAndView("request_token");
         } catch (OAuthProblemException e) {
+            logger.error("failed to acquire OAuth access token", e);
             StringBuffer sb = new StringBuffer();
-            sb.append("</br>");
-            sb.append("Error code: ").append(e.getError()).append("</br>");
-            sb.append("Error description: ").append(e.getDescription()).append("</br>");
-            sb.append("Error uri: ").append(e.getUri()).append("</br>");
-            sb.append("State: ").append(e.getState()).append("</br>");
+            sb.append("<br />");
+            sb.append("Error code: ").append(e.getError()).append("<br />");
+            sb.append("Error description: ").append(e.getDescription()).append("<br />");
+            sb.append("Error uri: ").append(e.getUri()).append("<br />");
+            sb.append("State: ").append(e.getState()).append("<br />");
             oauthParams.setErrorMessage(sb.toString());
             return new ModelAndView("get_authz");
         }

Modified: oltu/trunk/demos/client-demo/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/oltu/trunk/demos/client-demo/src/main/resources/log4j.properties?rev=1732766&r1=1732765&r2=1732766&view=diff
==============================================================================
--- oltu/trunk/demos/client-demo/src/main/resources/log4j.properties (original)
+++ oltu/trunk/demos/client-demo/src/main/resources/log4j.properties Sun Feb 28 16:43:34 2016
@@ -26,4 +26,6 @@ log4j.appender.CONSOLE=org.apache.log4j.
 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
+#log4j.logger.org.hibernate.search=TRACE
+
+log4j.logger.org.apache.oltu.oauth2.client.demo=DEBUG



Mime
View raw message