001package org.apache.archiva.redback.keys; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.List; 023 024/** 025 * KeyManager 026 * 027 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> 028 * 029 */ 030public interface KeyManager 031{ 032 033 034 /** 035 * String identifying the key manager implementation. 036 * 037 * @return the key manager implementation id. 038 */ 039 String getId(); 040 041 /** 042 * Attempt to find a specific key in the store. 043 * 044 * NOTE: Implementations of this interface should never return an expired key. 045 * 046 * @param key the key to find. 047 * @return the actual key found. 048 * @throws KeyNotFoundException when the requested, unexpired, key cannot be found. 049 * @throws KeyManagerException when there is a fundamental problem with the KeyManager implementation. 050 */ 051 AuthenticationKey findKey( String key ) 052 throws KeyNotFoundException, KeyManagerException; 053 054 /** 055 * Create a key (and save it to the store) for the specified principal. 056 * 057 * @param principal the principal to generate the key for. 058 * @param purpose the purpose of the key. (Example: "selfservice password reset", "new user validation", 059 * "remember me") This is a purely informational field . 060 * @param expirationMinutes the amount in minutes until this key expires. (-1 means no expiration) 061 * @return the key created 062 * @throws KeyManagerException if there is a fundamental problem with the KeyManager implementation. 063 */ 064 AuthenticationKey createKey( String principal, String purpose, int expirationMinutes ) 065 throws KeyManagerException; 066 067 /** 068 * Delete a key from the underlying store. 069 * 070 * @param key the key to delete. 071 */ 072 void deleteKey( AuthenticationKey key ) 073 throws KeyManagerException; 074 075 /** 076 * Delete a key from the underlying store. 077 * 078 * @param key the key to delete. 079 */ 080 void deleteKey( String key ) 081 throws KeyManagerException; 082 083 List<AuthenticationKey> getAllKeys(); 084 085 AuthenticationKey addKey( AuthenticationKey key ); 086 087 void eraseDatabase(); 088 089 /** 090 * Remove all keys that are expired. 091 */ 092 void removeExpiredKeys() 093 throws KeyManagerException; 094}