You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2012/07/17 13:27:56 UTC

svn commit: r1362448 - /cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AccessTokenService.java

Author: sergeyb
Date: Tue Jul 17 11:27:55 2012
New Revision: 1362448

URL: http://svn.apache.org/viewvc?rev=1362448&view=rev
Log:
[CXF-4427] Optionally reporting the custom error details

Modified:
    cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AccessTokenService.java

Modified: cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AccessTokenService.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AccessTokenService.java?rev=1362448&r1=1362447&r2=1362448&view=diff
==============================================================================
--- cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AccessTokenService.java (original)
+++ cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AccessTokenService.java Tue Jul 17 11:27:55 2012
@@ -53,11 +53,16 @@ import org.apache.cxf.rs.security.oauth2
 public class AccessTokenService extends AbstractOAuthService {
     private List<AccessTokenGrantHandler> grantHandlers = Collections.emptyList();
     private boolean writeOptionalParameters = true;
+    private boolean writeCustomErrors;
     
     public void setWriteOptionalParameters(boolean write) {
         writeOptionalParameters = write;
     }
     
+    public void setWriteCustomErrors(boolean write) {
+        writeCustomErrors = write;
+    }
+    
     /**
      * Sets the list of optional grant handlers
      * @param handlers the grant handlers
@@ -90,7 +95,11 @@ public class AccessTokenService extends 
         try {
             serverToken = handler.createAccessToken(client, params);
         } catch (OAuthServiceException ex) {
-            // the error response is to be returned next
+            OAuthError customError = ex.getError();
+            if (writeCustomErrors && customError != null) {
+                return createErrorResponseFromBean(customError);
+            }
+
         }
         if (serverToken == null) {
             return createErrorResponse(params, OAuthConstants.INVALID_GRANT);
@@ -201,7 +210,10 @@ public class AccessTokenService extends 
     
     protected Response createErrorResponse(MultivaluedMap<String, String> params,
                                            String error) {
-        OAuthError oauthError = new OAuthError(error);
-        return Response.status(400).entity(oauthError).build();
+        return createErrorResponseFromBean(new OAuthError(error));
+    }
+    
+    protected Response createErrorResponseFromBean(OAuthError errorBean) {
+        return Response.status(400).entity(errorBean).build();
     }
 }