GUACAMOLE-770: Switch to Boolean field for clearing data.
This commit is contained in:
1 parent
43e5024676
commit
4f4a060d4a
4 files changed
+25
-55
No files matched your search
+24
-1
@@ -43,13 +43,18 @@ public class TOTPUser extends DelegatingUser {
|
||||
* confirmed by the user, and the user is thus fully enrolled.
|
||||
*/
|
||||
public static final String TOTP_KEY_CONFIRMED_ATTRIBUTE_NAME = "guac-totp-key-confirmed";
|
||||
|
||||
/**
|
||||
* The name of the field used to trigger a reset of the TOTP data.
|
||||
*/
|
||||
public static final String TOTP_KEY_SECRET_RESET_FIELD = "guac-totp-reset";
|
||||
|
||||
/**
|
||||
* The form which contains all configurable properties for this user.
|
||||
*/
|
||||
public static final Form TOTP_CONFIG_FORM = new Form("totp-config-form",
|
||||
Arrays.asList(
|
||||
new BooleanField(TOTP_KEY_SECRET_ATTRIBUTE_NAME, ""),
|
||||
new BooleanField(TOTP_KEY_SECRET_RESET_FIELD, "true"),
|
||||
new BooleanField(TOTP_KEY_CONFIRMED_ATTRIBUTE_NAME, "true")
|
||||
)
|
||||
);
|
||||
@@ -81,6 +86,17 @@ public class TOTPUser extends DelegatingUser {
|
||||
|
||||
// Create independent, mutable copy of attributes
|
||||
Map<String, String> attributes = new HashMap<>(super.getAttributes());
|
||||
|
||||
// Protect the secret value by removing it
|
||||
String secret = attributes.remove(TOTP_KEY_SECRET_ATTRIBUTE_NAME);
|
||||
|
||||
// If secret is null or empty, mark the reset as true.
|
||||
if (secret == null || secret.isEmpty())
|
||||
attributes.put(TOTP_KEY_SECRET_RESET_FIELD, "true");
|
||||
|
||||
// If secret has a value, mark the reset as false.
|
||||
else
|
||||
attributes.put(TOTP_KEY_SECRET_RESET_FIELD, "false");
|
||||
|
||||
return attributes;
|
||||
|
||||
@@ -91,6 +107,13 @@ public class TOTPUser extends DelegatingUser {
|
||||
|
||||
// Create independent, mutable copy of attributes
|
||||
attributes = new HashMap<>(attributes);
|
||||
|
||||
// Pull off the boolean reset field
|
||||
String reset = attributes.remove(TOTP_KEY_SECRET_RESET_FIELD);
|
||||
|
||||
// If reset has been set to true, clear the secret.
|
||||
if (reset != null && reset.equals("true"))
|
||||
attributes.put(TOTP_KEY_SECRET_ATTRIBUTE_NAME, null);
|
||||
|
||||
super.setAttributes(attributes);
|
||||
|
||||
|
||||
Reference in new issue
Block a user