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.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
@@ -426,40 +425,51 @@ public class ModeledUser extends ModeledPermissions<UserModel> implements User {
private void setRestrictedAttributes(Map<String, String> attributes) { private void setRestrictedAttributes(Map<String, String> attributes) {
// Translate disabled attribute // Translate disabled attribute
if (attributes.containsKey(DISABLED_ATTRIBUTE_NAME))
getModel().setDisabled("true".equals(attributes.get(DISABLED_ATTRIBUTE_NAME))); getModel().setDisabled("true".equals(attributes.get(DISABLED_ATTRIBUTE_NAME)));
// Translate password expired attribute // Translate password expired attribute
if (attributes.containsKey(EXPIRED_ATTRIBUTE_NAME))
getModel().setExpired("true".equals(attributes.get(EXPIRED_ATTRIBUTE_NAME))); getModel().setExpired("true".equals(attributes.get(EXPIRED_ATTRIBUTE_NAME)));
// Translate access window start time // Translate access window start time
if (attributes.containsKey(ACCESS_WINDOW_START_ATTRIBUTE_NAME)) {
try { getModel().setAccessWindowStart(parseTime(attributes.get(ACCESS_WINDOW_START_ATTRIBUTE_NAME))); } try { getModel().setAccessWindowStart(parseTime(attributes.get(ACCESS_WINDOW_START_ATTRIBUTE_NAME))); }
catch (ParseException e) { catch (ParseException e) {
logger.warn("Not setting start time of user access window: {}", e.getMessage()); logger.warn("Not setting start time of user access window: {}", e.getMessage());
logger.debug("Unable to parse time attribute.", e); logger.debug("Unable to parse time attribute.", e);
} }
}
// Translate access window end time // Translate access window end time
if (attributes.containsKey(ACCESS_WINDOW_END_ATTRIBUTE_NAME)) {
try { getModel().setAccessWindowEnd(parseTime(attributes.get(ACCESS_WINDOW_END_ATTRIBUTE_NAME))); } try { getModel().setAccessWindowEnd(parseTime(attributes.get(ACCESS_WINDOW_END_ATTRIBUTE_NAME))); }
catch (ParseException e) { catch (ParseException e) {
logger.warn("Not setting end time of user access window: {}", e.getMessage()); logger.warn("Not setting end time of user access window: {}", e.getMessage());
logger.debug("Unable to parse time attribute.", e); logger.debug("Unable to parse time attribute.", e);
} }
}
// Translate account validity start date // Translate account validity start date
if (attributes.containsKey(VALID_FROM_ATTRIBUTE_NAME)) {
try { getModel().setValidFrom(parseDate(attributes.get(VALID_FROM_ATTRIBUTE_NAME))); } try { getModel().setValidFrom(parseDate(attributes.get(VALID_FROM_ATTRIBUTE_NAME))); }
catch (ParseException e) { catch (ParseException e) {
logger.warn("Not setting user validity start date: {}", e.getMessage()); logger.warn("Not setting user validity start date: {}", e.getMessage());
logger.debug("Unable to parse date attribute.", e); logger.debug("Unable to parse date attribute.", e);
} }
}
// Translate account validity end date // Translate account validity end date
if (attributes.containsKey(VALID_UNTIL_ATTRIBUTE_NAME)) {
try { getModel().setValidUntil(parseDate(attributes.get(VALID_UNTIL_ATTRIBUTE_NAME))); } try { getModel().setValidUntil(parseDate(attributes.get(VALID_UNTIL_ATTRIBUTE_NAME))); }
catch (ParseException e) { catch (ParseException e) {
logger.warn("Not setting user validity end date: {}", e.getMessage()); logger.warn("Not setting user validity end date: {}", e.getMessage());
logger.debug("Unable to parse date attribute.", e); logger.debug("Unable to parse date attribute.", e);
} }
}
// Translate timezone attribute // Translate timezone attribute
if (attributes.containsKey(TIMEZONE_ATTRIBUTE_NAME))
getModel().setTimeZone(TimeZoneField.parse(attributes.get(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) { private void setUnrestrictedAttributes(Map<String, String> attributes) {
// Translate full name attribute // Translate full name attribute
if (attributes.containsKey(User.Attribute.FULL_NAME))
getModel().setFullName(TextField.parse(attributes.get(User.Attribute.FULL_NAME))); getModel().setFullName(TextField.parse(attributes.get(User.Attribute.FULL_NAME)));
// Translate email address attribute // Translate email address attribute
if (attributes.containsKey(User.Attribute.EMAIL_ADDRESS))
getModel().setEmailAddress(TextField.parse(attributes.get(User.Attribute.EMAIL_ADDRESS))); getModel().setEmailAddress(TextField.parse(attributes.get(User.Attribute.EMAIL_ADDRESS)));
// Translate organization attribute // Translate organization attribute
if (attributes.containsKey(User.Attribute.ORGANIZATION))
getModel().setOrganization(TextField.parse(attributes.get(User.Attribute.ORGANIZATION))); getModel().setOrganization(TextField.parse(attributes.get(User.Attribute.ORGANIZATION)));
// Translate role attribute // Translate role attribute
if (attributes.containsKey(User.Attribute.ORGANIZATIONAL_ROLE))
getModel().setOrganizationalRole(TextField.parse(attributes.get(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 // Get mutable set of attributes
User self = context.self(); User self = context.self();
Map<String, String> attributes = new HashMap<String, String>(); Map<String, String> attributes = new HashMap<>();
// Set/overwrite current TOTP key state // Set/overwrite current TOTP key state
attributes.put(TOTPUser.TOTP_KEY_SECRET_ATTRIBUTE_NAME, BASE32.encode(key.getSecret())); attributes.put(TOTPUser.TOTP_KEY_SECRET_ATTRIBUTE_NAME, BASE32.encode(key.getSecret()));