1 /*
2 * Licensed to The Apereo Foundation under one or more contributor license
3 * agreements. See the NOTICE file distributed with this work for additional
4 * information regarding copyright ownership.
5 *
6 *
7 * The Apereo Foundation licenses this file to you under the Educational
8 * Community License, Version 2.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of the License
10 * at:
11 *
12 * http://opensource.org/licenses/ecl2.txt
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 * License for the specific language governing permissions and limitations under
18 * the License.
19 *
20 */
21 package org.opencastproject.security.urlsigning.service;
22
23 import org.opencastproject.security.urlsigning.exception.UrlSigningException;
24
25 import org.joda.time.DateTime;
26
27 public interface UrlSigningService {
28
29 /**
30 * Returns true if the signing service accepts to sign the {@code baseUrl}.
31 *
32 * @param baseUrl
33 * The base URL of the resource that needs to be signed
34 * @return True, if the signing service accepts to sign the URL; false otherwise.
35 */
36 boolean accepts(String baseUrl);
37
38 /**
39 * Create a secure signature for a resource by adding the validUntilDuration to the current time and optionally adding
40 * the validFromDuration to the current time to create the available and expiry dates for the signature.
41 *
42 * @param baseUrl
43 * The required url that refers to the resource.
44 * @param validUntilDuration
45 * The required number of seconds from now that the resource will expire.
46 * @param validFromDuration
47 * The number of seconds after now that the resource will become available; may be {@code null} (optional).
48 * @param ipAddr
49 * The IP address of the client that is allowed to view the resource; may be {@code null} (optional).
50 * @return A query string signature for this resource.
51 * @throws UrlSigningException
52 * Thrown if unable to sign the resource.
53 */
54 String sign(String baseUrl, Long validUntilDuration, Long validFromDuration, String ipAddr)
55 throws UrlSigningException;
56
57 /**
58 * Create a secure signature for a resource using DateTime objects.
59 *
60 * @param baseUrl
61 * The required url that refers to the resource.
62 * @param validUntil
63 * The required date and time this signature will expire.
64 * @param validFrom
65 * The date and time the resource will become available; may be {@code null} (optional).
66 * @param ipAddr
67 * The IP address of the client that is allowed to view the resource; may be {@code null} (optional).
68 * @return A query string signature for this resource.
69 * @throws UrlSigningException
70 * Thrown if unable to sign the resource.
71 */
72 String sign(String baseUrl, DateTime validUntil, DateTime validFrom, String ipAddr) throws UrlSigningException;
73 }