1 package org.apache.archiva.redback.keys;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.util.List;
23
24 /**
25 * KeyManager
26 *
27 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
28 *
29 */
30 public interface KeyManager
31 {
32
33
34 /**
35 * String identifying the key manager implementation.
36 *
37 * @return the key manager implementation id.
38 */
39 String getId();
40
41 /**
42 * Attempt to find a specific key in the store.
43 * <p/>
44 * NOTE: Implementations of this interface should never return an expired key.
45 *
46 * @param key the key to find.
47 * @return the actual key found.
48 * @throws KeyNotFoundException when the requested, unexpired, key cannot be found.
49 * @throws KeyManagerException when there is a fundamental problem with the KeyManager implementation.
50 */
51 AuthenticationKey findKey( String key )
52 throws KeyNotFoundException, KeyManagerException;
53
54 /**
55 * Create a key (and save it to the store) for the specified principal.
56 *
57 * @param principal the principal to generate the key for.
58 * @param purpose the purpose of the key. (Example: "selfservice password reset", "new user validation",
59 * "remember me") This is a purely informational field .
60 * @param expirationMinutes the amount in minutes until this key expires. (-1 means no expiration)
61 * @return the key created
62 * @throws KeyManagerException if there is a fundamental problem with the KeyManager implementation.
63 */
64 AuthenticationKey createKey( String principal, String purpose, int expirationMinutes )
65 throws KeyManagerException;
66
67 /**
68 * Delete a key from the underlying store.
69 *
70 * @param key the key to delete.
71 */
72 void deleteKey( AuthenticationKey key )
73 throws KeyManagerException;
74
75 /**
76 * Delete a key from the underlying store.
77 *
78 * @param key the key to delete.
79 */
80 void deleteKey( String key )
81 throws KeyManagerException;
82
83 List<AuthenticationKey> getAllKeys();
84
85 AuthenticationKey addKey( AuthenticationKey key );
86
87 void eraseDatabase();
88
89 /**
90 * Remove all keys that are expired.
91 */
92 void removeExpiredKeys()
93 throws KeyManagerException;
94 }