wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r1029781 - in /incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers: AbstractAuthSecurityHandler.java BasicAuthSecurityHandler.java ProxyAuthSecurityHandler.java
Date Mon, 01 Nov 2010 18:19:52 GMT
Author: bluk
Date: Mon Nov  1 18:19:51 2010
New Revision: 1029781

URL: http://svn.apache.org/viewvc?rev=1029781&view=rev
Log:
Update security handler with constructor

Thanks to Jason Dillon for the suggestion.

Modified:
    incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers/AbstractAuthSecurityHandler.java
    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/AbstractAuthSecurityHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers/AbstractAuthSecurityHandler.java?rev=1029781&r1=1029780&r2=1029781&view=diff
==============================================================================
--- incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers/AbstractAuthSecurityHandler.java
(original)
+++ incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/handlers/AbstractAuthSecurityHandler.java
Mon Nov  1 18:19:51 2010
@@ -40,6 +40,11 @@ public class AbstractAuthSecurityHandler
         super();
     }
     
+    public AbstractAuthSecurityHandler(final String username, final String password) {
+        setUserName(username);
+        setPassword(password);
+    }
+    
     /**
      * Sets the username to use.
      * 

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=1029781&r1=1029780&r2=1029781&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
Mon Nov  1 18:19:51 2010
@@ -45,14 +45,21 @@ import org.slf4j.LoggerFactory;
  */
 public class BasicAuthSecurityHandler extends AbstractAuthSecurityHandler implements ClientHandler
{
 
-    private static Logger   logger          =
-        LoggerFactory
-        .getLogger(BasicAuthSecurityHandler.class);
+    private static Logger    logger       = LoggerFactory.getLogger(BasicAuthSecurityHandler.class);
 
     private static final int UNAUTHORIZED = HttpStatus.UNAUTHORIZED.getCode();
-    
+
+    public BasicAuthSecurityHandler() {
+        /* do nothing */
+    }
+
+    public BasicAuthSecurityHandler(final String username, final String password) {
+        super(username, password);
+    }
+
     /**
-     * Performs basic HTTP authentication and proxy authentication, if necessary.
+     * Performs basic HTTP authentication and proxy authentication, if
+     * necessary.
      * 
      * @param client request object
      * @param handler context object
@@ -63,18 +70,19 @@ public class BasicAuthSecurityHandler ex
         logger.trace("Entering BasicAuthSecurityHandler.doChain()"); //$NON-NLS-1$
         ClientResponse response = context.doChain(request);
         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$
                 // we have a user credential
-                request.getHeaders().putSingle("Authorization", getEncodedString(handlerUsername,
handlerPassword)); //$NON-NLS-1$
+                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() == UNAUTHORIZED) {
                     logger
-                    .trace("After sending request with Authorization header, still got "
+ UNAUTHORIZED + " 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$
+                        .getMessage("serviceFailedToAuthenticateUser", handlerUsername));
//$NON-NLS-1$
                 } else {
                     logger.trace("Got a non-" + UNAUTHORIZED + " response, so returning response");
//$NON-NLS-1$
                     return response;
@@ -83,14 +91,14 @@ public class BasicAuthSecurityHandler ex
                 logger.trace("user and/or password were not set so throwing exception");
//$NON-NLS-1$
                 // no user credential available
                 throw new ClientAuthenticationException(Messages
-                        .getMessage("missingClientAuthenticationCredentialForUser", handlerUsername));
//$NON-NLS-1$
+                    .getMessage("missingClientAuthenticationCredentialForUser", handlerUsername));
//$NON-NLS-1$
             }
         } else {
-            logger.trace("Status code was not " + UNAUTHORIZED + " 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=1029781&r1=1029780&r2=1029781&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
Mon Nov  1 18:19:51 2010
@@ -34,8 +34,8 @@ import org.slf4j.LoggerFactory;
  * Usage:<br/>
  * ClientConfig config = new ClientConfig();<br/>
  * ProxyAuthSecurityHandler proxyAuthSecHandler = new ProxyAuthSecurityHandler();
- * proxyAuthSecHandler.setProxyUserName("username");
- * proxyAuthSecHandler.setProxyPassword("password");
+ * proxyAuthSecHandler.setUserName("username");
+ * proxyAuthSecHandler.setPassword("password");
  * config.handlers(proxyAuthSecurityHandler);<br/>
  * // create the rest client instance<br/>
  * RestClient client = new RestClient(config);<br/>
@@ -45,14 +45,25 @@ import org.slf4j.LoggerFactory;
  */
 public class ProxyAuthSecurityHandler extends AbstractAuthSecurityHandler implements ClientHandler
{
 
-    private static Logger    logger          =
-                                                 LoggerFactory
-                                                     .getLogger(ProxyAuthSecurityHandler.class);
+    private static Logger    logger              =
+                                                     LoggerFactory
+                                                         .getLogger(ProxyAuthSecurityHandler.class);
+
+    private static final int PROXY_AUTH_REQ_CODE =
+                                                     HttpStatus.PROXY_AUTHENTICATION_REQUIRED
+                                                         .getCode();
+
+    public ProxyAuthSecurityHandler() {
+        /* do nothing */
+    }
+
+    public ProxyAuthSecurityHandler(final String username, final String password) {
+        super(username, password);
+    }
 
-    private static final int PROXY_AUTH_REQ_CODE = HttpStatus.PROXY_AUTHENTICATION_REQUIRED.getCode();
-    
     /**
-     * Performs basic HTTP authentication and proxy authentication, if necessary.
+     * Performs basic HTTP authentication and proxy authentication, if
+     * necessary.
      * 
      * @param client request object
      * @param handler context object
@@ -62,37 +73,41 @@ 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() == PROXY_AUTH_REQ_CODE) {  // 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$
                 // we have a user credential
                 request.getHeaders().putSingle("Proxy-Connection", "Keep-Alive"); //$NON-NLS-1$
$NON-NLS-2$
-                request.getHeaders().putSingle("Proxy-Authorization", getEncodedString(handlerUsername,
handlerPassword)); //$NON-NLS-1$
+                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() == PROXY_AUTH_REQ_CODE) {
                     logger
-                    .trace("After sending request with Proxy-Authorization header, still
got " + PROXY_AUTH_REQ_CODE + " 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$
+                        .getMessage("serviceFailedToAuthenticateProxyUser", handlerUsername));
//$NON-NLS-1$
                 } else {
-                    logger.trace("Got a non-" + PROXY_AUTH_REQ_CODE + " 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 {
                 logger.trace("proxy user and/or proxy password were not set so throwing exception");
//$NON-NLS-1$
                 // no proxy user credential available
-                throw new ClientAuthenticationException(Messages
-                        .getMessage("missingClientAuthenticationCredentialForProxyUser",
handlerUsername)); //$NON-NLS-1$
+                throw new ClientAuthenticationException(
+                                                        Messages
+                                                            .getMessage("missingClientAuthenticationCredentialForProxyUser",
handlerUsername)); //$NON-NLS-1$
             }
-        } else {  // did NOT get a proxy auth challenge
-            logger.trace("Status code was not " + PROXY_AUTH_REQ_CODE + " so no need to re-issue
request."); //$NON-NLS-1$
+        } else { // did NOT get a proxy auth challenge
+            logger
+                .trace("Status code was not " + PROXY_AUTH_REQ_CODE + " so no need to re-issue
request."); //$NON-NLS-1$
             return response;
         }
 
     }
 
-    
 }
-



Mime
View raw message