-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement ReloadingKeyStoreAccess #17
Conversation
@@ -89,23 +89,31 @@ public Boolean load(UserNameAndPassword pe) throws Exception { | |||
|
|||
} | |||
|
|||
public PasswordEntry loadKey(final String username) throws UnrecoverableEntryException, KeyStoreException, InvalidKeyException { | |||
public PasswordEntry loadKey(final String username) throws UnrecoverableEntryException, KeyStoreException, InvalidKeyException, ExecutionException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these new ExecutionExceptions that may happen in case loading of the store fails, should be part of the KeyStoreException or other available exceptions that are already in there instead of adding new ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merged ExecutionExceptions into KeyStoreException
|
||
CacheLoader<Long, IKeyStoreAccess> cacheLoader = new CacheLoader<Long, IKeyStoreAccess>() { | ||
@Override | ||
public IKeyStoreAccess load(Long key) throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this throws it is always a KeyStoreException of some sort?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does not throw, removed throws
in method declaration
} | ||
|
||
public void saveKey(final String username, final char[] password) throws ExecutionException, KeyStoreException { | ||
loadingCache.get(0L).saveKey(username, password); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should catch and throw KeyStoreException?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
caught and thrown as KeyStoreException
cksa.deleteKey(userName); | ||
cksa.saveKey(userName, userPassWord.toCharArray()); | ||
Files.deleteIfExists(Paths.get(keyStorePath)); | ||
Thread.sleep(1000); // KeyStore refreshes every second |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
increase to 1200 milliseconds so they do not race
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
increased
…s from ReloadingKeyStoreAccess' cacheLoader load() function, increase sleep in tests
import java.security.UnrecoverableEntryException; | ||
import java.security.spec.InvalidKeySpecException; | ||
|
||
public interface IKeyStoreAccess { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rename interface without I and rename the implementation class to KeyStoreAccessImpl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
in last commit git diff goes haywire but diff is essentially:
--- KeyStoreAccess.java 2024-05-28 15:59:20.175771463 +0300
+++ KeyStoreAccessImpl.java 2024-05-28 15:58:02.331335951 +0300
@@ -60,17 +60,17 @@
* and deleting entries. Keeps track of the username->alias mapping
* via the UserToAliasMapping object.
*/
-public class KeyStoreAccess implements IKeyStoreAccess {
+public class KeyStoreAccessImpl implements KeyStoreAccess {
private final String keyStorePath;
private final char[] keyStorePassword;
private final EntryAliasFactory entryAliasFactory;
private final UserToAliasMapping userToAliasMapping;
private final KeyStore keyStore;
- public KeyStoreAccess(final KeyStore keyStore, final String keyStorePath, final char[] keyStorePassword) {
+ public KeyStoreAccessImpl(final KeyStore keyStore, final String keyStorePath, final char[] keyStorePassword) {
this(keyStore, keyStorePath, keyStorePassword, new EntryAliasFactory());
}
- public KeyStoreAccess(final KeyStore keyStore, final String keyStorePath, final char[] keyStorePassword, final EntryAliasFactory entryAliasFactory) {
+ public KeyStoreAccessImpl(final KeyStore keyStore, final String keyStorePath, final char[] keyStorePassword, final EntryAliasFactory entryAliasFactory) {
this.entryAliasFactory = entryAliasFactory;
this.keyStorePassword = keyStorePassword;
this.keyStorePath = keyStorePath;
Allows reloading the KeyStore from disk after cache expiration