GUACAMOLE-1199: Merge corrections to handling of unchanged, database-stored attributes.

This commit is contained in:
Mike Jumper
2021-08-21 18:01:25 -07:00
committed by GitHub
2 changed files with 40 additions and 26 deletions

View File

@@ -30,7 +30,6 @@ import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
@@ -426,40 +425,51 @@ public class ModeledUser extends ModeledPermissions<UserModel> implements User {
private void setRestrictedAttributes(Map<String, String> attributes) {
// Translate disabled attribute
if (attributes.containsKey(DISABLED_ATTRIBUTE_NAME))
getModel().setDisabled("true".equals(attributes.get(DISABLED_ATTRIBUTE_NAME)));
// Translate password expired attribute
if (attributes.containsKey(EXPIRED_ATTRIBUTE_NAME))
getModel().setExpired("true".equals(attributes.get(EXPIRED_ATTRIBUTE_NAME)));
// Translate access window start time
if (attributes.containsKey(ACCESS_WINDOW_START_ATTRIBUTE_NAME)) {
try { getModel().setAccessWindowStart(parseTime(attributes.get(ACCESS_WINDOW_START_ATTRIBUTE_NAME))); }
catch (ParseException e) {
logger.warn("Not setting start time of user access window: {}", e.getMessage());
logger.debug("Unable to parse time attribute.", e);
}
}
// Translate access window end time
if (attributes.containsKey(ACCESS_WINDOW_END_ATTRIBUTE_NAME)) {
try { getModel().setAccessWindowEnd(parseTime(attributes.get(ACCESS_WINDOW_END_ATTRIBUTE_NAME))); }
catch (ParseException e) {
logger.warn("Not setting end time of user access window: {}", e.getMessage());
logger.debug("Unable to parse time attribute.", e);
}
}
// Translate account validity start date
if (attributes.containsKey(VALID_FROM_ATTRIBUTE_NAME)) {
try { getModel().setValidFrom(parseDate(attributes.get(VALID_FROM_ATTRIBUTE_NAME))); }
catch (ParseException e) {
logger.warn("Not setting user validity start date: {}", e.getMessage());
logger.debug("Unable to parse date attribute.", e);
}
}
// Translate account validity end date
if (attributes.containsKey(VALID_UNTIL_ATTRIBUTE_NAME)) {
try { getModel().setValidUntil(parseDate(attributes.get(VALID_UNTIL_ATTRIBUTE_NAME))); }
catch (ParseException e) {
logger.warn("Not setting user validity end date: {}", e.getMessage());
logger.debug("Unable to parse date attribute.", e);
}
}
// Translate timezone attribute
if (attributes.containsKey(TIMEZONE_ATTRIBUTE_NAME))
getModel().setTimeZone(TimeZoneField.parse(attributes.get(TIMEZONE_ATTRIBUTE_NAME)));
}
@@ -474,15 +484,19 @@ public class ModeledUser extends ModeledPermissions<UserModel> implements User {
private void setUnrestrictedAttributes(Map<String, String> attributes) {
// Translate full name attribute
if (attributes.containsKey(User.Attribute.FULL_NAME))
getModel().setFullName(TextField.parse(attributes.get(User.Attribute.FULL_NAME)));
// Translate email address attribute
if (attributes.containsKey(User.Attribute.EMAIL_ADDRESS))
getModel().setEmailAddress(TextField.parse(attributes.get(User.Attribute.EMAIL_ADDRESS)));
// Translate organization attribute
if (attributes.containsKey(User.Attribute.ORGANIZATION))
getModel().setOrganization(TextField.parse(attributes.get(User.Attribute.ORGANIZATION)));
// Translate role attribute
if (attributes.containsKey(User.Attribute.ORGANIZATIONAL_ROLE))
getModel().setOrganizationalRole(TextField.parse(attributes.get(User.Attribute.ORGANIZATIONAL_ROLE)));
}

View File

@@ -166,7 +166,7 @@ public class UserVerificationService {
// Get mutable set of attributes
User self = context.self();
Map<String, String> attributes = new HashMap<String, String>();
Map<String, String> attributes = new HashMap<>();
// Set/overwrite current TOTP key state
attributes.put(TOTPUser.TOTP_KEY_SECRET_ATTRIBUTE_NAME, BASE32.encode(key.getSecret()));