EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.http.filters]

COVERAGE SUMMARY FOR SOURCE FILE [BasicAuthentication.java]

nameclass, %method, %block, %line, %
BasicAuthentication.java100% (1/1)100% (2/2)100% (42/42)100% (4/4)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BasicAuthentication100% (1/1)100% (2/2)100% (42/42)100% (4/4)
BasicAuthentication (String, String, Crypto): void 100% (1/1)100% (31/31)100% (3/3)
filter (HttpRequest): HttpRequest 100% (1/1)100% (11/11)100% (1/1)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.http.filters;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
23import static org.jclouds.Constants.PROPERTY_IDENTITY;
24 
25import java.io.UnsupportedEncodingException;
26 
27import javax.inject.Inject;
28import javax.inject.Named;
29import javax.inject.Singleton;
30import javax.ws.rs.core.HttpHeaders;
31 
32import org.jclouds.crypto.Crypto;
33import org.jclouds.crypto.CryptoStreams;
34import org.jclouds.http.HttpException;
35import org.jclouds.http.HttpRequest;
36import org.jclouds.http.HttpRequestFilter;
37import org.jclouds.http.utils.ModifyRequest;
38 
39/**
40 * Uses Basic Authentication to sign the request.
41 * 
42 * @see <a href= "http://en.wikipedia.org/wiki/Basic_access_authentication" />
43 * @author Adrian Cole
44 * 
45 */
46@Singleton
47public class BasicAuthentication implements HttpRequestFilter {
48 
49   private final String header;
50 
51   @Inject
52   public BasicAuthentication(@Named(PROPERTY_IDENTITY) String user, @Named(PROPERTY_CREDENTIAL) String password,
53         Crypto crypto) throws UnsupportedEncodingException {
54      this.header = "Basic "
55            + CryptoStreams.base64(String.format("%s:%s", checkNotNull(user, "user"),
56                  checkNotNull(password, "password")).getBytes("UTF-8"));
57   }
58 
59   @Override
60   public HttpRequest filter(HttpRequest request) throws HttpException {
61      return ModifyRequest.replaceHeader(request, HttpHeaders.AUTHORIZATION, header);
62   }
63}

[all classes][org.jclouds.http.filters]
EMMA 2.0.5312 (C) Vladimir Roubtsov