Java Client: Add new user preference for default login type
This commit is contained in:
parent
6f2dd84a31
commit
2794ea08e4
@ -604,6 +604,11 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener,
|
||||
user.getPreferences().getDefaultType(), user.getPreferences()::setDefaultType ),
|
||||
Components.strut() );
|
||||
|
||||
components.add( Components.label( "Default Login Type:" ),
|
||||
Components.comboBox( MPResultType.values(), MPResultType::getLongName,
|
||||
user.getPreferences().getDefaultLoginType(), user.getPreferences()::setDefaultLoginType),
|
||||
Components.strut() );
|
||||
|
||||
components.add( Components.checkBox( "Hide Passwords",
|
||||
user.getPreferences().isHidePasswords(), user.getPreferences()::setHidePasswords ) );
|
||||
|
||||
@ -639,7 +644,7 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener,
|
||||
|
||||
components.add( Components.label( "Login Type:" ),
|
||||
Components.comboBox( MPResultType.values(), type ->
|
||||
getTypeDescription( type, user.getAlgorithm().mpw_default_login_type() ),
|
||||
getTypeDescription( type, user.getPreferences().getDefaultLoginType() ),
|
||||
site.getLoginType(), site::setLoginType ),
|
||||
Components.strut() );
|
||||
|
||||
|
@ -13,6 +13,10 @@ public interface MPUserPreferences {
|
||||
|
||||
void setDefaultType(@Nullable MPResultType defaultType);
|
||||
|
||||
MPResultType getDefaultLoginType();
|
||||
|
||||
void setDefaultLoginType(@Nullable MPResultType defaultLoginType);
|
||||
|
||||
boolean isHidePasswords();
|
||||
|
||||
void setHidePasswords(boolean hidePasswords);
|
||||
|
@ -56,7 +56,7 @@ public abstract class MPBasicSite<U extends MPUser<?>, Q extends MPQuestion> ext
|
||||
this.algorithm = (algorithm != null)? algorithm: this.user.getAlgorithm();
|
||||
this.counter = (counter != null)? counter: this.algorithm.mpw_default_counter();
|
||||
this.resultType = (resultType != null)? resultType: this.user.getPreferences().getDefaultType();
|
||||
this.loginType = (loginType != null)? loginType: this.algorithm.mpw_default_login_type();
|
||||
this.loginType = (loginType != null)? loginType: this.user.getPreferences().getDefaultLoginType();
|
||||
}
|
||||
|
||||
// - Meta
|
||||
@ -125,7 +125,7 @@ public abstract class MPBasicSite<U extends MPUser<?>, Q extends MPQuestion> ext
|
||||
if (this.loginType == loginType)
|
||||
return;
|
||||
|
||||
this.loginType = ifNotNullElse( loginType, getAlgorithm().mpw_default_login_type() );
|
||||
this.loginType = ifNotNullElse( loginType, this.user.getPreferences().getDefaultLoginType() );
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,8 @@ public class MPBasicUserPreferences<U extends MPBasicUser<?>> implements MPUserP
|
||||
|
||||
@Nullable
|
||||
private MPResultType defaultType;
|
||||
@Nullable
|
||||
private MPResultType defaultLoginType;
|
||||
private boolean hidePasswords;
|
||||
|
||||
public MPBasicUserPreferences(final U user) {
|
||||
@ -34,6 +36,16 @@ public class MPBasicUserPreferences<U extends MPBasicUser<?>> implements MPUserP
|
||||
this.defaultType = defaultType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPResultType getDefaultLoginType() {
|
||||
return (defaultLoginType != null) ? defaultLoginType : user.getAlgorithm().mpw_default_login_type();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultLoginType(@Nullable final MPResultType defaultLoginType) {
|
||||
this.defaultLoginType = defaultLoginType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHidePasswords() {
|
||||
return hidePasswords;
|
||||
|
@ -62,18 +62,19 @@ public class MPFileUser extends MPBasicUser<MPFileSite> {
|
||||
}
|
||||
|
||||
public MPFileUser(final String fullName, @Nullable final byte[] keyID, final MPAlgorithm algorithm, final File location) {
|
||||
this( fullName, keyID, algorithm, 0, null, new Instant(), false,
|
||||
this( fullName, keyID, algorithm, 0, null, null, new Instant(), false,
|
||||
MPMarshaller.ContentMode.PROTECTED, MPMarshalFormat.DEFAULT, location );
|
||||
}
|
||||
|
||||
public MPFileUser(final String fullName, @Nullable final byte[] keyID, final MPAlgorithm algorithm, final int avatar,
|
||||
@Nullable final MPResultType defaultType, final ReadableInstant lastUsed, final boolean hidePasswords,
|
||||
final MPMarshaller.ContentMode contentMode, final MPMarshalFormat format, final File location) {
|
||||
@Nullable final MPResultType defaultType, @Nullable final MPResultType defaultLoginType,
|
||||
final ReadableInstant lastUsed, final boolean hidePasswords, final MPMarshaller.ContentMode contentMode,
|
||||
final MPMarshalFormat format, final File location) {
|
||||
super( avatar, fullName, algorithm );
|
||||
|
||||
this.keyID = (keyID != null)? keyID.clone(): null;
|
||||
this.lastUsed = lastUsed;
|
||||
this.preferences = new MPFileUserPreferences( this, defaultType, hidePasswords );
|
||||
this.preferences = new MPFileUserPreferences( this, defaultType, defaultLoginType, hidePasswords);
|
||||
this.format = format;
|
||||
this.contentMode = contentMode;
|
||||
|
||||
|
@ -10,10 +10,11 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public class MPFileUserPreferences extends MPBasicUserPreferences<MPFileUser> {
|
||||
|
||||
public MPFileUserPreferences(final MPFileUser user, @Nullable final MPResultType defaultType, final boolean hidePasswords) {
|
||||
public MPFileUserPreferences(final MPFileUser user, @Nullable final MPResultType defaultType, @Nullable final MPResultType defaultLoginType, final boolean hidePasswords) {
|
||||
super( user );
|
||||
|
||||
setDefaultType( defaultType );
|
||||
setDefaultLoginType(defaultLoginType);
|
||||
setHidePasswords( hidePasswords );
|
||||
}
|
||||
|
||||
@ -26,6 +27,15 @@ public class MPFileUserPreferences extends MPBasicUserPreferences<MPFileUser> {
|
||||
getUser().setChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultLoginType(@Nullable final MPResultType defaultLoginType) {
|
||||
if (getDefaultLoginType() == defaultLoginType)
|
||||
return;
|
||||
|
||||
super.setDefaultLoginType(defaultLoginType);
|
||||
getUser().setChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHidePasswords(final boolean hidePasswords) {
|
||||
if (Objects.equals( isHidePasswords(), hidePasswords ))
|
||||
|
@ -57,6 +57,7 @@ public class MPFlatMarshaller implements MPMarshaller {
|
||||
content.append( "# Key ID: " ).append( user.exportKeyID() ).append( '\n' );
|
||||
content.append( "# Algorithm: " ).append( user.getAlgorithm().version().toInt() ).append( '\n' );
|
||||
content.append( "# Default Type: " ).append( user.getPreferences().getDefaultType().getType() ).append( '\n' );
|
||||
content.append( "# Default Login Type: " ).append( user.getPreferences().getDefaultLoginType().getType() ).append( '\n' );
|
||||
content.append( "# Passwords: " ).append( user.getContentMode().name() ).append( '\n' );
|
||||
content.append( "##\n" );
|
||||
content.append( "#\n" );
|
||||
|
@ -56,11 +56,12 @@ public class MPFlatUnmarshaller implements MPUnmarshaller {
|
||||
int mpVersion = 0, avatar = 0;
|
||||
boolean clearContent = false, headerStarted = false;
|
||||
MPResultType defaultType = null;
|
||||
MPResultType defaultLoginType = null;
|
||||
Instant date = null;
|
||||
|
||||
//noinspection HardcodedLineSeparator
|
||||
for (final String line : CharStreams.readLines( reader ))
|
||||
// Header delimitor.
|
||||
// Header delimiter.
|
||||
if (line.startsWith( "##" )) {
|
||||
if (!headerStarted)
|
||||
// Starts the header.
|
||||
@ -68,7 +69,7 @@ public class MPFlatUnmarshaller implements MPUnmarshaller {
|
||||
else if ((fullName != null) && (keyID != null))
|
||||
// Ends the header.
|
||||
return new MPFileUser(
|
||||
fullName, keyID, MPAlgorithm.Version.fromInt( mpVersion ).getAlgorithm(), avatar, defaultType,
|
||||
fullName, keyID, MPAlgorithm.Version.fromInt( mpVersion ).getAlgorithm(), avatar, defaultType, defaultLoginType,
|
||||
date, false, clearContent? MPMarshaller.ContentMode.VISIBLE: MPMarshaller.ContentMode.PROTECTED,
|
||||
MPMarshalFormat.Flat, file
|
||||
);
|
||||
@ -93,6 +94,8 @@ public class MPFlatUnmarshaller implements MPUnmarshaller {
|
||||
clearContent = "visible".equalsIgnoreCase( value );
|
||||
else if ("Default Type".equalsIgnoreCase( name ))
|
||||
defaultType = MPResultType.forType( ConversionUtils.toIntegerNN( value ) );
|
||||
else if ("Default Login Type".equalsIgnoreCase( name ))
|
||||
defaultLoginType = MPResultType.forType( ConversionUtils.toIntegerNN( value ) );
|
||||
else if ("Date".equalsIgnoreCase( name ))
|
||||
date = MPModelConstants.dateTimeFormatter.parseDateTime( value ).toInstant();
|
||||
}
|
||||
|
@ -20,11 +20,6 @@ package com.lyndir.masterpassword.model.impl;
|
||||
|
||||
import static com.lyndir.lhunath.opal.system.util.ObjectUtils.*;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
|
||||
import com.fasterxml.jackson.core.util.Separators;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.primitives.UnsignedInteger;
|
||||
import com.lyndir.lhunath.opal.system.CodeUtils;
|
||||
import com.lyndir.masterpassword.*;
|
||||
@ -66,6 +61,7 @@ public class MPJSONFile extends MPJSONAnyObject {
|
||||
user._ext_mpw = new User.Ext() {
|
||||
{
|
||||
default_type = modelUser.getPreferences().getDefaultType();
|
||||
default_login_type = modelUser.getPreferences().getDefaultLoginType();
|
||||
hide_passwords = modelUser.getPreferences().isHidePasswords();
|
||||
}
|
||||
};
|
||||
@ -133,6 +129,7 @@ public class MPJSONFile extends MPJSONAnyObject {
|
||||
return new MPFileUser(
|
||||
user.full_name, CodeUtils.decodeHex( user.key_id ), algorithm, user.avatar,
|
||||
(user._ext_mpw != null)? user._ext_mpw.default_type: null,
|
||||
(user._ext_mpw != null)? user._ext_mpw.default_login_type : null,
|
||||
(user.last_used != null)? MPModelConstants.dateTimeFormatter.parseDateTime( user.last_used ): new Instant(),
|
||||
(user._ext_mpw != null) && user._ext_mpw.hide_passwords,
|
||||
export.redacted? MPMarshaller.ContentMode.PROTECTED: MPMarshaller.ContentMode.VISIBLE,
|
||||
@ -211,6 +208,8 @@ public class MPJSONFile extends MPJSONAnyObject {
|
||||
|
||||
@Nullable
|
||||
MPResultType default_type;
|
||||
@Nullable
|
||||
MPResultType default_login_type;
|
||||
boolean hide_passwords;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user