2
0

Fix warnings and inspections.

This commit is contained in:
Maarten Billemont
2018-04-27 11:32:54 -04:00
parent 82e2d0b5ac
commit cb74b1f3fc
30 changed files with 225 additions and 142 deletions

View File

@@ -29,13 +29,13 @@ import org.joda.time.Instant;
*/
public class MPFileSite extends MPSite {
private final MPFileUser user;
private String siteName;
private final MPFileUser user;
private String siteName;
@Nullable
private String siteContent;
private UnsignedInteger siteCounter;
private MPResultType resultType;
private MPAlgorithm algorithm;
private String siteContent;
private UnsignedInteger siteCounter;
private MPResultType resultType;
private MPAlgorithm algorithm;
@Nullable
private String loginContent;
@@ -122,14 +122,15 @@ public class MPFileSite extends MPSite {
return siteContent;
}
public void setSitePassword(final MPMasterKey masterKey, @Nullable final MPResultType resultType, @Nullable final String result)
public void setSitePassword(final MPMasterKey masterKey, final MPResultType resultType, @Nullable final String result)
throws MPInvalidatedException {
this.resultType = resultType;
if (result == null)
this.siteContent = null;
else
this.siteContent = masterKey.siteState(
getSiteName(), getSiteCounter(), MPKeyPurpose.Authentication, null, getResultType(), result, algorithm );
siteName, siteCounter, MPKeyPurpose.Authentication, null, resultType, result, algorithm );
}
@Override

View File

@@ -32,6 +32,7 @@ import org.joda.time.ReadableInstant;
/**
* @author lhunath, 14-12-07
*/
@SuppressWarnings("ComparableImplementedButEqualsNotOverridden")
public class MPFileUser extends MPUser<MPFileSite> implements Comparable<MPFileUser> {
@SuppressWarnings("UnusedDeclaration")
@@ -41,9 +42,9 @@ public class MPFileUser extends MPUser<MPFileSite> implements Comparable<MPFileU
private final Collection<MPFileSite> sites = Sets.newHashSet();
@Nullable
private byte[] keyID;
private MPAlgorithm algorithm;
private MPMarshalFormat format;
private byte[] keyID;
private MPAlgorithm algorithm;
private MPMarshalFormat format;
private int avatar;
private MPResultType defaultType;

View File

@@ -36,6 +36,7 @@ import javax.annotation.Nonnull;
*
* @author lhunath, 14-12-07
*/
@SuppressWarnings("CallToSystemGetenv")
public class MPFileUserManager extends MPUserManager {
@SuppressWarnings("UnusedDeclaration")
@@ -50,21 +51,20 @@ public class MPFileUserManager extends MPUserManager {
instance = create( new File( ifNotNullElseNullable( System.getProperty( "user.home" ), System.getenv( "HOME" ) ), ".mpw.d" ) );
}
private final File userFilesDirectory;
private final File path;
public static MPFileUserManager get() {
MPUserManager.instance = instance;
return instance;
}
public static MPFileUserManager create(final File userFilesDirectory) {
return new MPFileUserManager( userFilesDirectory );
public static MPFileUserManager create(final File path) {
return new MPFileUserManager( path );
}
protected MPFileUserManager(final File userFilesDirectory) {
protected MPFileUserManager(final File path) {
super( unmarshallUsers( userFilesDirectory ) );
this.userFilesDirectory = userFilesDirectory;
super( unmarshallUsers( path ) );
this.path = path;
}
private static Iterable<MPFileUser> unmarshallUsers(final File userFilesDirectory) {
@@ -76,7 +76,7 @@ public class MPFileUserManager extends MPUserManager {
Map<String, MPFileUser> users = new HashMap<>();
for (final File userFile : listUserFiles( userFilesDirectory ))
for (final MPMarshalFormat format : MPMarshalFormat.values())
if (userFile.getName().endsWith( '.' + format.fileExtension() ))
if (userFile.getName().endsWith( format.fileSuffix() ))
try {
MPFileUser user = format.unmarshaller().unmarshall( userFile );
MPFileUser previousUser = users.put( user.getFullName(), user );
@@ -95,7 +95,7 @@ public class MPFileUserManager extends MPUserManager {
@Override
public boolean accept(final File dir, final String name) {
for (final MPMarshalFormat format : MPMarshalFormat.values())
if (name.endsWith( '.' + format.fileExtension() ))
if (name.endsWith( format.fileSuffix() ))
return true;
return false;
@@ -134,13 +134,13 @@ public class MPFileUserManager extends MPUserManager {
@Nonnull
private File getUserFile(final MPFileUser user) {
return new File( userFilesDirectory, user.getFullName() + ".mpsites" );
return new File( path, user.getFullName() + ".mpsites" );
}
/**
* @return The location on the file system where the user models are stored.
*/
public File getPath() {
return userFilesDirectory;
return path;
}
}

View File

@@ -29,6 +29,7 @@ import org.joda.time.Instant;
/**
* @author lhunath, 2017-09-20
*/
@SuppressWarnings({ "HardcodedLineSeparator", "MagicCharacter" })
public class MPFlatMarshaller implements MPMarshaller {
private static final int FORMAT = 1;

View File

@@ -39,8 +39,8 @@ public enum MPMarshalFormat {
}
@Override
public String fileExtension() {
return "mpsites";
public String fileSuffix() {
return ".mpsites";
}
},
@@ -59,8 +59,8 @@ public enum MPMarshalFormat {
}
@Override
public String fileExtension() {
return "mpsites.json";
public String fileSuffix() {
return ".mpsites.json";
}
};
@@ -70,5 +70,6 @@ public enum MPMarshalFormat {
public abstract MPUnmarshaller unmarshaller();
public abstract String fileExtension();
@SuppressWarnings("MethodReturnAlwaysConstant")
public abstract String fileSuffix();
}

View File

@@ -33,14 +33,15 @@ public interface MPMarshaller {
throws MPInvalidatedException, MPMarshalException;
enum ContentMode {
PROTECTED( "Export of site names and stored passwords (unless device-private) encrypted with the master key." ),
VISIBLE( "Export of site names and passwords in clear-text." );
PROTECTED( "Export of site names and stored passwords (unless device-private) encrypted with the master key.", true ),
VISIBLE( "Export of site names and passwords in clear-text.", false );
private final String description;
private boolean redacted;
private final boolean redacted;
ContentMode(final String description) {
ContentMode(final String description, final boolean redacted) {
this.description = description;
this.redacted = redacted;
}
public String description() {

View File

@@ -45,7 +45,7 @@ public abstract class MPUser<S extends MPSite> {
@Nonnull
public MPMasterKey getMasterKey() {
return Preconditions.checkNotNull( key, "User is not authenticated: " + getFullName() );
return Preconditions.checkNotNull( key, "User is not authenticated: %s", getFullName() );
}
public String exportKeyID()

View File

@@ -29,11 +29,6 @@ import java.util.SortedSet;
public abstract class MPUserManager {
private final Map<String, MPFileUser> usersByName = Maps.newHashMap();
static MPUserManager instance;
public static MPUserManager get() {
return instance;
}
protected MPUserManager(final Iterable<MPFileUser> users) {
for (final MPFileUser user : users)