Support resetting user's master password.
This commit is contained in:
@@ -77,8 +77,18 @@ public interface MPUser<S extends MPSite<?>> extends Comparable<MPUser<?>> {
|
||||
void authenticate(MPMasterKey masterKey)
|
||||
throws MPIncorrectMasterPasswordException, MPKeyUnavailableException, MPAlgorithmException;
|
||||
|
||||
/**
|
||||
* Clear all authentication tokens and secrets from memory, effectively logging the user out.
|
||||
*/
|
||||
void invalidate();
|
||||
|
||||
/**
|
||||
* Wipe the key ID, allowing the user to {@link #authenticate(char[])} with any master password.
|
||||
*
|
||||
* Note: Authenticating with a different master password will cause all of the user's results to change.
|
||||
*/
|
||||
void reset();
|
||||
|
||||
boolean isMasterKeyAvailable();
|
||||
|
||||
@Nonnull
|
||||
|
@@ -97,12 +97,14 @@ public abstract class MPBasicUser<S extends MPBasicSite<?, ?>> extends Changeabl
|
||||
@Override
|
||||
public byte[] getKeyID() {
|
||||
try {
|
||||
return getMasterKey().getKeyID( getAlgorithm() );
|
||||
if (isMasterKeyAvailable())
|
||||
return getMasterKey().getKeyID( getAlgorithm() );
|
||||
}
|
||||
catch (final MPException e) {
|
||||
logger.wrn( e, "While deriving key ID for user: %s", this );
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -143,23 +145,29 @@ public abstract class MPBasicUser<S extends MPBasicSite<?, ?>> extends Changeabl
|
||||
public void invalidate() {
|
||||
if (masterKey == null)
|
||||
return;
|
||||
|
||||
this.masterKey = null;
|
||||
|
||||
masterKey.invalidate();
|
||||
masterKey = null;
|
||||
|
||||
for (final Listener listener : listeners)
|
||||
listener.onUserInvalidated( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMasterKeyAvailable() {
|
||||
return masterKey != null;
|
||||
return (masterKey != null) && masterKey.isValid();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MPMasterKey getMasterKey()
|
||||
throws MPKeyUnavailableException {
|
||||
if (masterKey == null)
|
||||
if ((masterKey == null) || !masterKey.isValid())
|
||||
throw new MPKeyUnavailableException( "Master key was not yet set for: " + this );
|
||||
|
||||
return masterKey;
|
||||
|
@@ -169,6 +169,13 @@ public class MPFileUser extends MPBasicUser<MPFileSite> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
keyID = null;
|
||||
|
||||
super.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPFileSite addSite(final String siteName) {
|
||||
return addSite( new MPFileSite( this, siteName ) );
|
||||
|
Reference in New Issue
Block a user