You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by ro...@apache.org on 2010/07/27 16:45:43 UTC

svn commit: r979732 - in /incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers: BasicAuthSecurityHandler.java ProxyAuthSecurityHandler.java

Author: rott
Date: Tue Jul 27 14:45:43 2010
New Revision: 979732

URL: http://svn.apache.org/viewvc?rev=979732&view=rev
Log:
non-functional code cleanup to *AuthSecurityHandler code

Modified:
    incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers/BasicAuthSecurityHandler.java
    incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers/ProxyAuthSecurityHandler.java

Modified: incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers/BasicAuthSecurityHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers/BasicAuthSecurityHandler.java?rev=979732&r1=979731&r2=979732&view=diff
==============================================================================
--- incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers/BasicAuthSecurityHandler.java (original)
+++ incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers/BasicAuthSecurityHandler.java Tue Jul 27 14:45:43 2010
@@ -22,12 +22,13 @@ package org.apache.wink.client.handlers;
 import org.apache.wink.client.ClientAuthenticationException;
 import org.apache.wink.client.ClientRequest;
 import org.apache.wink.client.ClientResponse;
+import org.apache.wink.common.http.HttpStatus;
 import org.apache.wink.common.internal.i18n.Messages;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * SecurityHandler for a client to perform http basic auth and http proxy auth:
+ * SecurityHandler for a client to perform http basic auth:
  * <p/>
  * <code>
  * Usage:<br/>
@@ -48,6 +49,7 @@ public class BasicAuthSecurityHandler ex
         LoggerFactory
         .getLogger(BasicAuthSecurityHandler.class);
 
+    private static final int UNAUTHORIZED = HttpStatus.UNAUTHORIZED.getCode();
     
     /**
      * Performs basic HTTP authentication and proxy authentication, if necessary.
@@ -60,7 +62,7 @@ public class BasicAuthSecurityHandler ex
     public ClientResponse handle(ClientRequest request, HandlerContext context) throws Exception {
         logger.trace("Entering BasicAuthSecurityHandler.doChain()"); //$NON-NLS-1$
         ClientResponse response = context.doChain(request);
-        if (response.getStatusCode() == 401) {
+        if (response.getStatusCode() == UNAUTHORIZED) {
             
             if (!(handlerUsername == null || handlerUsername.equals("") || handlerPassword == null || handlerPassword.equals(""))) { //$NON-NLS-1$ //$NON-NLS-2$
                 logger.trace("userid and password set so setting Authorization header"); //$NON-NLS-1$
@@ -68,13 +70,13 @@ public class BasicAuthSecurityHandler ex
                 request.getHeaders().putSingle("Authorization", getEncodedString(handlerUsername, handlerPassword)); //$NON-NLS-1$
                 logger.trace("Issuing request again with Authorization header"); //$NON-NLS-1$
                 response = context.doChain(request);
-                if (response.getStatusCode() == 401) {
+                if (response.getStatusCode() == UNAUTHORIZED) {
                     logger
-                    .trace("After sending request with Authorization header, still got 401 response"); //$NON-NLS-1$
+                    .trace("After sending request with Authorization header, still got " + UNAUTHORIZED + " response"); //$NON-NLS-1$
                     throw new ClientAuthenticationException(Messages
                             .getMessage("serviceFailedToAuthenticateUser", handlerUsername)); //$NON-NLS-1$
                 } else {
-                    logger.trace("Got a non-401 response, so returning response"); //$NON-NLS-1$
+                    logger.trace("Got a non-" + UNAUTHORIZED + " response, so returning response"); //$NON-NLS-1$
                     return response;
                 }
             } else {
@@ -84,7 +86,7 @@ public class BasicAuthSecurityHandler ex
                         .getMessage("missingClientAuthenticationCredentialForUser", handlerUsername)); //$NON-NLS-1$
             }
         } else {
-            logger.trace("Status code was not 401 so no need to re-issue request."); //$NON-NLS-1$
+            logger.trace("Status code was not " + UNAUTHORIZED + " so no need to re-issue request."); //$NON-NLS-1$
             return response;
         }
 

Modified: incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers/ProxyAuthSecurityHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers/ProxyAuthSecurityHandler.java?rev=979732&r1=979731&r2=979732&view=diff
==============================================================================
--- incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers/ProxyAuthSecurityHandler.java (original)
+++ incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers/ProxyAuthSecurityHandler.java Tue Jul 27 14:45:43 2010
@@ -22,6 +22,7 @@ package org.apache.wink.client.handlers;
 import org.apache.wink.client.ClientAuthenticationException;
 import org.apache.wink.client.ClientRequest;
 import org.apache.wink.client.ClientResponse;
+import org.apache.wink.common.http.HttpStatus;
 import org.apache.wink.common.internal.i18n.Messages;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -48,6 +49,7 @@ public class ProxyAuthSecurityHandler ex
                                                  LoggerFactory
                                                      .getLogger(ProxyAuthSecurityHandler.class);
 
+    private static final int PROXY_AUTH_REQ_CODE = HttpStatus.PROXY_AUTHENTICATION_REQUIRED.getCode();
     
     /**
      * Performs basic HTTP authentication and proxy authentication, if necessary.
@@ -60,7 +62,7 @@ public class ProxyAuthSecurityHandler ex
     public ClientResponse handle(ClientRequest request, HandlerContext context) throws Exception {
         logger.trace("Entering ProxyAuthSecurityHandler.doChain()"); //$NON-NLS-1$
         ClientResponse response = context.doChain(request);
-        if (response.getStatusCode() == 407) {  // got a proxy auth challenge
+        if (response.getStatusCode() == PROXY_AUTH_REQ_CODE) {  // got a proxy auth challenge
             
             if (!(handlerUsername == null || handlerUsername.equals("") || handlerPassword == null || handlerPassword.equals(""))) { //$NON-NLS-1$ //$NON-NLS-2$
                 logger.trace("userid and password set so setting Proxy-Authorization header"); //$NON-NLS-1$
@@ -69,13 +71,13 @@ public class ProxyAuthSecurityHandler ex
                 request.getHeaders().putSingle("Proxy-Authorization", getEncodedString(handlerUsername, handlerPassword)); //$NON-NLS-1$
                 logger.trace("Issuing request again with Proxy-Authorization header"); //$NON-NLS-1$
                 response = context.doChain(request);
-                if (response.getStatusCode() == 407) {
+                if (response.getStatusCode() == PROXY_AUTH_REQ_CODE) {
                     logger
-                    .trace("After sending request with Proxy-Authorization header, still got 407 response"); //$NON-NLS-1$
+                    .trace("After sending request with Proxy-Authorization header, still got " + PROXY_AUTH_REQ_CODE + " response"); //$NON-NLS-1$
                     throw new ClientAuthenticationException(Messages
                             .getMessage("serviceFailedToAuthenticateProxyUser", handlerUsername)); //$NON-NLS-1$
                 } else {
-                    logger.trace("Got a non-407 response, so returning response"); //$NON-NLS-1$
+                    logger.trace("Got a non-" + PROXY_AUTH_REQ_CODE + " response, so returning response"); //$NON-NLS-1$
                     return response;
                 }
             } else {
@@ -85,7 +87,7 @@ public class ProxyAuthSecurityHandler ex
                         .getMessage("missingClientAuthenticationCredentialForProxyUser", handlerUsername)); //$NON-NLS-1$
             }
         } else {  // did NOT get a proxy auth challenge
-            logger.trace("Status code was not 407 so no need to re-issue request."); //$NON-NLS-1$
+            logger.trace("Status code was not " + PROXY_AUTH_REQ_CODE + " so no need to re-issue request."); //$NON-NLS-1$
             return response;
         }