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 HashingResult
The Argon2 hash of theclear name
of the user who was banned.private final @NonNull ReentrantLock
Facilitates mutual exclusion whendecrypting
themessage
to the user who was banned.private String
The decryptedmessage
to the user who was banned.private HashingResult
The Argon2 hash of thee-mail address
of the user who was banned.private CipherText
An explanation from the developers to the user banned about why they were banned and what this means for them.private HashingResult
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Deprecated.Only to be used by Jackson during deserialisation.BannedUser
(@NonNull Set<BanLevel> banLevels) Creates a newBannedUser
with the given ban levels. -
Method Summary
Modifier and TypeMethodDescription@NonNull BannedUser
copy()
decryptMessage
(@NonNull Configuration configuration) Decrypts
the developers'message
to the user, trying theuser name
, thee-mail address
, and theclear name
as the password.boolean
Compares thisBannedUser
with 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 givenConfiguration
matches this banned user.private boolean
matchesClearName
(@NonNull Configuration configuration) private boolean
matchesEmail
(@NonNull Configuration configuration) private boolean
matchesUser
(@NonNull Configuration configuration) void
setBanLevels
(@NonNull Set<BanLevel> banLevels) private void
setClearName
(@NonNull String clearNameHash) Deprecated.Only to be used by Jackson during deserialisation.void
setClearName
(@NonNull HashingResult clearName) Updates theclearName
hash of the user who was banned.private void
Deprecated.Only to be used by Jackson during deserialisation.void
setEmail
(@NonNull HashingResult email) Updates theemail
hash of the user who was banned.private void
setMessage
(@NonNull String message) Deprecated.Only to be used by Jackson during deserialisation.void
setMessage
(@NonNull CipherText encryptedMessage) Updates themessage
to the user who was banned.private void
setUsername
(@NonNull String usernameHash) Deprecated.Only to be used by Jackson during deserialisation.void
setUsername
(@NonNull HashingResult username) Updates theusername
hash of the user who was banned.private void
updateBanLevels
(@NonNull Set<String> banLevels) Deprecated.Only to be used by Jackson during deserialisation.
-
Field Details
-
username
-
email
The Argon2 hash of thee-mail address
of the user who was banned. May benull
if the e-mail address was not provided. -
clearName
The Argon2 hash of theclear name
of the user who was banned. May benull
if 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 benull
if no message was provided. -
decryptedMessage
-
DECRYPT_MESSAGE_LOCK
Facilitates mutual exclusion whendecrypting
themessage
to the user who was banned. -
banLevels
-
-
Constructor Details
-
BannedUser
Creates a newBannedUser
with 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 theusername
hash of the user who was banned.- Parameters:
username
- The new hash of the user name.
-
setEmail
Updates theemail
hash of the user who was banned.- Parameters:
email
- The new hash of the e-mail address.
-
setClearName
Updates theclearName
hash 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 thebanLevels
with a deep copy of the givenBanLevels
that 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.LIFTED
to 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
message
to the user who was banned. Empty if no message was provided.
-
getDecryptedMessage
-
getBanLevels
-
matches
Checks if the user corresponding to the givenConfiguration
matches this banned user.Configuration.getUserHash()
is matched againstusername
Configuration.getEmailHash()
is matched againstemail
Configuration.getClearnameHash()
is matched againstclearName
Argon2 parameters
differ, the respective hash of theConfiguration
is re-computed.Message to the banned user
If the developers have attached anexplanation
to the banned user, it is decrypted with the user's user name as the AES password. If this fails, thedecryption
is tried with the user'se-mail
or, 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
Result
that indicates whether the user matches this banned user. If the given user is, in fact, banned,success
will be true. If the developers have left amessage
that could be decrypted, it is returned as theresult
.
-
matchesUser
Checks if theuser name
'shash
matches theusername
of 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:
true
if the user name hashes match,false
otherwise.
-
matchesEmail
Checks if thee-mail address
'shash
matches theemail
of 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:
true
if the e-mail address hashes match,false
otherwise.
-
matchesClearName
Checks if theclear name
'shash
matches theclearName
of 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:
true
if the clear name hashes match,false
otherwise.
-
decryptMessage
@NonNull private @NonNull Optional<String> decryptMessage(@NonNull @NonNull Configuration configuration) Decrypts
the developers'message
to the user, trying theuser name
, thee-mail address
, and theclear name
as the password. If successful, the decrypted message is stored in thedecryptedMessage
field.- 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
message
or - the message had not been decrypted previously and
-
the given configuration does not
match
this banned user or -
the message could not be decrypted using the
user name
, thee-mail address
or theclear name
as 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:
copy
in 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 thisBannedUser
with the given object.- Overrides:
equals
in classObject
- Parameters:
object
- The object to compare thisBannedUser
with.- Returns:
-
true
if the given object is aBannedUser
whose fields' values match their equivalents in thisBannedUser
, especially (but not exclusively) if the givenBannedUser
is the exact same reference as thisBannedUser
. -
false
if the given object is not aBannedUser
or if any of the fields' values differ from their equivalents in thisBannedUser
.
-
-