| | |
| | | */ |
| | | package com.gitblit.transport.ssh; |
| | | |
| | | import java.security.PublicKey; |
| | | import java.text.MessageFormat; |
| | | import java.util.List; |
| | | import java.util.concurrent.ExecutionException; |
| | |
| | | import com.google.common.cache.LoadingCache; |
| | | |
| | | /** |
| | | * Parent class for public key managers. |
| | | * Parent class for ssh public key managers. |
| | | * |
| | | * @author James Moger |
| | | * |
| | |
| | | |
| | | protected final Logger log = LoggerFactory.getLogger(getClass()); |
| | | |
| | | protected final LoadingCache<String, List<PublicKey>> keyCache = CacheBuilder |
| | | protected final LoadingCache<String, List<SshKey>> keyCache = CacheBuilder |
| | | .newBuilder(). |
| | | expireAfterAccess(15, TimeUnit.MINUTES). |
| | | maximumSize(100) |
| | | .build(new CacheLoader<String, List<PublicKey>>() { |
| | | .build(new CacheLoader<String, List<SshKey>>() { |
| | | @Override |
| | | public List<PublicKey> load(String username) { |
| | | public List<SshKey> load(String username) { |
| | | return getKeysImpl(username); |
| | | } |
| | | }); |
| | |
| | | @Override |
| | | public abstract IPublicKeyManager stop(); |
| | | |
| | | public final List<PublicKey> getKeys(String username) { |
| | | public final List<SshKey> getKeys(String username) { |
| | | try { |
| | | if (isStale(username)) { |
| | | keyCache.invalidate(username); |
| | |
| | | |
| | | protected abstract boolean isStale(String username); |
| | | |
| | | protected abstract List<PublicKey> getKeysImpl(String username); |
| | | protected abstract List<SshKey> getKeysImpl(String username); |
| | | |
| | | public abstract boolean addKey(String username, String data); |
| | | public abstract boolean addKey(String username, SshKey key); |
| | | |
| | | public abstract boolean removeKey(String username, String data); |
| | | public abstract boolean removeKey(String username, SshKey key); |
| | | |
| | | public abstract boolean removeAllKeys(String username); |
| | | } |