java.lang.Object
page.codeberg.friedolyn.meta.BannedUser
- All Implemented Interfaces:
Copyable<BannedUser>
Represents a user of the Friedolyn application who has been banned from using certain features. For privacy reasons,
the user's name, e-mail address, and clear name are stored as hashes, because they are published online in the
PolledMetadata.-
Field Summary
FieldsModifier and TypeFieldDescriptionAll features of the application that the user is banned from using.private HashingResultThe Argon2 hash of theclear nameof the user who was banned.private final @NonNull ReentrantLockFacilitates mutual exclusion whendecryptingthemessageto the user who was banned.private StringThe decryptedmessageto the user who was banned.private HashingResultThe Argon2 hash of thee-mail addressof the user who was banned.private CipherTextAn explanation from the developers to the user banned about why they were banned and what this means for them.private HashingResult -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDeprecated.Only to be used by Jackson during deserialisation.BannedUser(@NonNull Set<BanLevel> banLevels) Creates a newBannedUserwith the given ban levels. -
Method Summary
Modifier and TypeMethodDescription@NonNull BannedUsercopy()decryptMessage(@NonNull Configuration configuration) Decryptsthe developers'messageto the user, trying theuser name, thee-mail address, and theclear nameas the password.booleanCompares thisBannedUserwith the given object.@NonNull Optional<HashingResult> @NonNull Optional<HashingResult> getEmail()@NonNull Optional<CipherText> @NonNull Optional<HashingResult> matches(@NonNull Configuration configuration) Checks if the user corresponding to the givenConfigurationmatches this banned user.private booleanmatchesClearName(@NonNull Configuration configuration) private booleanmatchesEmail(@NonNull Configuration configuration) private booleanmatchesUser(@NonNull Configuration configuration) voidsetBanLevels(@NonNull Set<BanLevel> banLevels) private voidsetClearName(@NonNull String clearNameHash) Deprecated.Only to be used by Jackson during deserialisation.voidsetClearName(@NonNull HashingResult clearName) Updates theclearNamehash of the user who was banned.private voidDeprecated.Only to be used by Jackson during deserialisation.voidsetEmail(@NonNull HashingResult email) Updates theemailhash of the user who was banned.private voidsetMessage(@NonNull String message) Deprecated.Only to be used by Jackson during deserialisation.voidsetMessage(@NonNull CipherText encryptedMessage) Updates themessageto the user who was banned.private voidsetUsername(@NonNull String usernameHash) Deprecated.Only to be used by Jackson during deserialisation.voidsetUsername(@NonNull HashingResult username) Updates theusernamehash of the user who was banned.private voidupdateBanLevels(@NonNull Set<String> banLevels) Deprecated.Only to be used by Jackson during deserialisation.
-
Field Details
-
username
-
email
The Argon2 hash of thee-mail addressof the user who was banned. May benullif the e-mail address was not provided. -
clearName
The Argon2 hash of theclear nameof the user who was banned. May benullif the clear name was not provided. -
message
An explanation from the developers to the user banned about why they were banned and what this means for them. May benullif no message was provided. -
decryptedMessage
-
DECRYPT_MESSAGE_LOCK
Facilitates mutual exclusion whendecryptingthemessageto the user who was banned. -
banLevels
-
-
Constructor Details
-
BannedUser
Creates a newBannedUserwith the given ban levels.- Parameters:
banLevels- The application features that the user is banned from using.
-
BannedUser
Deprecated.Only to be used by Jackson during deserialisation. UseBannedUser(Set)instead.
-
-
Method Details
-
setUsername
Updates theusernamehash of the user who was banned.- Parameters:
username- The new hash of the user name.
-
setEmail
Updates theemailhash of the user who was banned.- Parameters:
email- The new hash of the e-mail address.
-
setClearName
Updates theclearNamehash of the user who was banned.- Parameters:
clearName- The new hash of the clear name.
-
setMessage
-
setUsername
@Deprecated private void setUsername(@NonNull @NonNull String usernameHash) throws IllegalArgumentException Deprecated.Only to be used by Jackson during deserialisation. Use(CipherText)instead.- Parameters:
usernameHash- The new hash of the user name that was banned.- Throws:
IllegalArgumentException- SeeHashingResult.parse(String).
-
setEmail
@Deprecated private void setEmail(@NonNull @NonNull String emailHash) throws IllegalArgumentException Deprecated.Only to be used by Jackson during deserialisation. Use(CipherText)instead.- Parameters:
emailHash- The new hash of the e-mail address of the user who was banned.- Throws:
IllegalArgumentException- SeeHashingResult.parse(String).
-
setClearName
@Deprecated private void setClearName(@NonNull @NonNull String clearNameHash) throws IllegalArgumentException Deprecated.Only to be used by Jackson during deserialisation. Use(CipherText)instead.- Parameters:
clearNameHash- The new hash of the clear name of the user who was banned.- Throws:
IllegalArgumentException- SeeHashingResult.parse(String).
-
setMessage
@Deprecated private void setMessage(@NonNull @NonNull String message) throws IllegalArgumentException Deprecated.Only to be used by Jackson during deserialisation.- Parameters:
message- The new message to the user who was banned.- Throws:
IllegalArgumentException- SeeCipherText.parse(String).
-
updateBanLevels
@Deprecated private void updateBanLevels(@NonNull @NonNull Set<String> banLevels) throws IllegalArgumentException Deprecated.Only to be used by Jackson during deserialisation.- Parameters:
banLevels- The new ban levels that the user is banned from using.- Throws:
IllegalArgumentException- SeeBanLevel.valueOf(String).
-
setBanLevels
Updates thebanLevelswith a deep copy of the givenBanLevelsthat indicate which features of the application the user is not allowed to use.- Parameters:
banLevels- The new bans imposed on the user. Must not be empty. UseBanLevel.LIFTEDto communicate that previous bans are no longer in effect.- Throws:
IllegalArgumentException- If the given set of ban levels is empty.
-
getUsername
-
getEmail
-
getClearName
-
getMessage
- Returns:
- A deep copy of the
messageto the user who was banned. Empty if no message was provided.
-
getDecryptedMessage
-
getBanLevels
-
matches
Checks if the user corresponding to the givenConfigurationmatches this banned user.Configuration.getUserHash()is matched againstusernameConfiguration.getEmailHash()is matched againstemailConfiguration.getClearnameHash()is matched againstclearName
Argon2 parametersdiffer, the respective hash of theConfigurationis re-computed.Message to the banned user
If the developers have attached anexplanationto the banned user, it is decrypted with the user's user name as the AES password. If this fails, thedecryptionis tried with the user'se-mailor, if that fails too, with the user'sclear name.- Parameters:
configuration- The settings of the user who shall be checked against this banned user.- Returns:
- A
Resultthat indicates whether the user matches this banned user. If the given user is, in fact, banned,successwill be true. If the developers have left amessagethat could be decrypted, it is returned as theresult.
-
matchesUser
Checks if theuser name'shashmatches theusernameof this banned user. The hash may need to be computed first, potentially resulting in a delay.- Parameters:
configuration- The settings of the user who shall be checked against this banned user.- Returns:
trueif the user name hashes match,falseotherwise.
-
matchesEmail
Checks if thee-mail address'shashmatches theemailof this banned user. The hash may need to be computed first, potentially resulting in a delay.- Parameters:
configuration- The settings of the user who shall be checked against this banned user.- Returns:
trueif the e-mail address hashes match,falseotherwise.
-
matchesClearName
Checks if theclear name'shashmatches theclearNameof this banned user. The hash may need to be computed first, potentially resulting in a delay.- Parameters:
configuration- The settings of the user who shall be checked against this banned user.- Returns:
trueif the clear name hashes match,falseotherwise.
-
decryptMessage
@NonNull private @NonNull Optional<String> decryptMessage(@NonNull @NonNull Configuration configuration) Decryptsthe developers'messageto the user, trying theuser name, thee-mail address, and theclear nameas the password. If successful, the decrypted message is stored in thedecryptedMessagefield.- Parameters:
configuration- The user whose properties shall be tried as the decryption password.- Returns:
- The decrypted message to the banned user. Empty if
- there is no
messageor - the message had not been decrypted previously and
-
the given configuration does not
matchthis banned user or -
the message could not be decrypted using the
user name, thee-mail addressor theclear nameas the password
-
the given configuration does not
- there is no
- Implementation Note:
- This method is mutually exclusive, in order not to overwhelm the CPU with simultaneous decryption attempts and in order not to waste resources by doing the same decryption multiple times.
-
copy
- Specified by:
copyin interfaceCopyable<BannedUser>- Returns:
- A deep copy of the object, i.e. a clone that has the exact same values as the original object, but is a different instance (new reference).
-
equals
Compares thisBannedUserwith the given object.- Overrides:
equalsin classObject- Parameters:
object- The object to compare thisBannedUserwith.- Returns:
-
trueif the given object is aBannedUserwhose fields' values match their equivalents in thisBannedUser, especially (but not exclusively) if the givenBannedUseris the exact same reference as thisBannedUser. -
falseif the given object is not aBannedUseror if any of the fields' values differ from their equivalents in thisBannedUser.
-
-