EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.atmos.filters]

COVERAGE SUMMARY FOR SOURCE FILE [ShareUrl.java]

nameclass, %method, %block, %line, %
ShareUrl.java100% (1/1)25%  (1/4)20%  (28/138)40%  (10/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ShareUrl100% (1/1)25%  (1/4)20%  (28/138)40%  (10/25)
apply (String): URI 0%   (0/1)0%   (0/61)0%   (0/4)
createStringToSign (String, long): String 0%   (0/1)0%   (0/29)0%   (0/6)
signString (String): String 0%   (0/1)0%   (0/20)0%   (0/5)
ShareUrl (String, String, URI, Provider, Provider, Crypto): void 100% (1/1)100% (28/28)100% (10/10)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  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,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.atmos.filters;
20 
21import static org.jclouds.Constants.LOGGER_SIGNATURE;
22import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
23import static org.jclouds.Constants.PROPERTY_IDENTITY;
24 
25import java.net.URI;
26 
27import javax.annotation.Resource;
28import javax.inject.Inject;
29import javax.inject.Named;
30import javax.inject.Singleton;
31import javax.ws.rs.core.UriBuilder;
32 
33import org.jclouds.crypto.Crypto;
34import org.jclouds.crypto.CryptoStreams;
35import org.jclouds.date.TimeStamp;
36import org.jclouds.http.HttpException;
37import org.jclouds.io.InputSuppliers;
38import org.jclouds.location.Provider;
39import org.jclouds.logging.Logger;
40 
41import com.google.common.base.Function;
42 
43/**
44 * Signs the EMC Atmos Online Storage request.
45 * 
46 * @see <a href="https://community.emc.com/community/labs/atmos_online" />
47 * @author Adrian Cole
48 * 
49 */
50@Singleton
51public class ShareUrl implements Function<String, URI> {
52 
53   private final String uid;
54   private final byte[] key;
55   private final URI provider;
56   private final javax.inject.Provider<Long> timeStampProvider;
57   private final javax.inject.Provider<UriBuilder> uriBuilders;
58   private final Crypto crypto;
59 
60   @Resource
61   Logger logger = Logger.NULL;
62 
63   @Resource
64   @Named(LOGGER_SIGNATURE)
65   Logger signatureLog = Logger.NULL;
66 
67   @Inject
68   public ShareUrl(@Named(PROPERTY_IDENTITY) String uid, @Named(PROPERTY_CREDENTIAL) String encodedKey,
69            @Provider URI provider, @TimeStamp javax.inject.Provider<Long> timeStampProvider,
70            javax.inject.Provider<UriBuilder> uriBuilders, Crypto crypto) {
71      this.uid = uid;
72      this.key = CryptoStreams.base64(encodedKey);
73      this.provider = provider;
74      this.uriBuilders = uriBuilders;
75      this.timeStampProvider = timeStampProvider;
76      this.crypto = crypto;
77   }
78 
79   @Override
80   public URI apply(String path) throws HttpException {
81      String requestedResource = new StringBuilder().append("/rest/namespace/").append(path).toString();
82      long expires = timeStampProvider.get();
83      String signature = signString(createStringToSign(requestedResource, expires));
84      return uriBuilders.get().uri(provider).path(requestedResource).queryParam("uid", uid).queryParam("expires",
85               expires).queryParam("signature", signature).build();
86   }
87 
88   public String createStringToSign(String requestedResource, long expires) {
89      StringBuilder toSign = new StringBuilder();
90      toSign.append("GET\n");
91      toSign.append(requestedResource.toLowerCase()).append("\n");
92      toSign.append(uid).append("\n");
93      toSign.append(expires);
94      return toSign.toString();
95   }
96 
97   public String signString(String toSign) {
98      String signature;
99      try {
100         signature = CryptoStreams.base64(CryptoStreams.mac(InputSuppliers.of(toSign), crypto.hmacSHA1(key)));
101      } catch (Exception e) {
102         throw new HttpException("error signing request", e);
103      }
104      return signature;
105   }
106 
107}

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