01: /*
02: * Copyright 2005-2007 Noelios Consulting.
03: *
04: * The contents of this file are subject to the terms of the Common Development
05: * and Distribution License (the "License"). You may not use this file except in
06: * compliance with the License.
07: *
08: * You can obtain a copy of the license at
09: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
10: * language governing permissions and limitations under the License.
11: *
12: * When distributing Covered Code, include this CDDL HEADER in each file and
13: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
14: * applicable, add the following below this CDDL HEADER, with the fields
15: * enclosed by brackets "[]" replaced with your own identifying information:
16: * Portions Copyright [yyyy] [name of copyright owner]
17: */
18:
19: package org.restlet.example.book.rest.ch3;
20:
21: import org.restlet.Client;
22: import org.restlet.data.ChallengeResponse;
23: import org.restlet.data.ChallengeScheme;
24: import org.restlet.data.Method;
25: import org.restlet.data.Protocol;
26: import org.restlet.data.Request;
27: import org.restlet.data.Response;
28: import org.restlet.resource.Representation;
29:
30: /**
31: * Amazon S3 client. Support class handling authorized requests.
32: *
33: * @author Jerome Louvel (contact@noelios.com)
34: */
35: public class S3Authorized {
36: public final static String PUBLIC_KEY = "0F9DBXKB5274JKTJ8DG2";
37:
38: public final static String PRIVATE_KEY = "GuUHQ086WawbwvVl3JPl9JIk4VOtLcllkvIb0b7w";
39:
40: public final static String HOST = "https://s3.amazonaws.com/";
41:
42: private static Response handleAuthorized(Method method, String uri,
43: Representation entity) {
44: // Send an authenticated request
45: Request request = new Request(method, uri, entity);
46: request.setChallengeResponse(new ChallengeResponse(
47: ChallengeScheme.HTTP_AWS, PUBLIC_KEY, PRIVATE_KEY));
48: return new Client(Protocol.HTTPS).handle(request);
49: }
50:
51: public static Response authorizedHead(String uri) {
52: return handleAuthorized(Method.HEAD, uri, null);
53: }
54:
55: public static Response authorizedGet(String uri) {
56: return handleAuthorized(Method.GET, uri, null);
57: }
58:
59: public static Response authorizedPut(String uri,
60: Representation entity) {
61: return handleAuthorized(Method.PUT, uri, entity);
62: }
63:
64: public static Response authorizedDelete(String uri) {
65: return handleAuthorized(Method.DELETE, uri, null);
66: }
67: }
|