View Javadoc

1   // ========================================================================
2   // Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.client.security;
15  
16  
17  import java.io.IOException;
18  
19  import org.eclipse.jetty.client.HttpExchange;
20  import org.eclipse.jetty.http.HttpHeaders;
21  import org.eclipse.jetty.io.Buffer;
22  import org.eclipse.jetty.io.ByteArrayBuffer;
23  import org.eclipse.jetty.util.B64Code;
24  import org.eclipse.jetty.util.StringUtil;
25  
26  /**
27   * Sets proxy authentication headers for BASIC authentication challenges
28   * 
29   * 
30   */
31  public class ProxyAuthorization implements Authentication
32  {
33      private Buffer _authorization;
34      
35      public ProxyAuthorization(String username,String password) throws IOException
36      {
37          String authenticationString = "Basic " + B64Code.encode( username + ":" + password, StringUtil.__ISO_8859_1);
38          _authorization= new ByteArrayBuffer(authenticationString);
39      }
40      
41      /**
42       * BASIC proxy authentication is of the form
43       * 
44       * encoded credentials are of the form: username:password
45       * 
46       * 
47       */
48      public void setCredentials( HttpExchange exchange ) throws IOException
49      {
50          exchange.setRequestHeader( HttpHeaders.PROXY_AUTHORIZATION_BUFFER, _authorization);
51      }
52  }