001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2015 ForgeRock AS. 015 */ 016 017package org.forgerock.audit.providers; 018 019import java.util.HashMap; 020import java.util.Map; 021 022import org.forgerock.audit.secure.SecureStorage; 023 024/** 025 * Default implementation of {@link SecureStorageProvider}. 026 * <p> 027 * Multiple SecureStorage instances can be provided, identified by a name. 028 */ 029public class DefaultSecureStorageProvider implements SecureStorageProvider { 030 031 /** Named secure storage instances availables. */ 032 private final Map<String, SecureStorage> secureStorages; 033 034 /** Creates a initially empty provider. */ 035 public DefaultSecureStorageProvider() { 036 this.secureStorages = new HashMap<>(); 037 } 038 039 /** 040 * Creates a provider with some storages instances. 041 * 042 * @param storages 043 * The storage instances to use in the provider. 044 */ 045 public DefaultSecureStorageProvider(Map<String, SecureStorage> storages) { 046 this.secureStorages = storages; 047 } 048 049 /** 050 * Register a storage with the given name. 051 * 052 * @param name 053 * Name associated to the storage instance. 054 * @param storage 055 * The storage instance. 056 */ 057 public void registerSecureStorage(String name, SecureStorage storage) { 058 secureStorages.put(name, storage); 059 } 060 061 @Override 062 public SecureStorage getSecureStorage(String name) { 063 return secureStorages.get(name); 064 } 065 066}