Skip to content

Commit 015117f

Browse files
committed
GUACAMOLE-1479: Switch JDBC module to use disabled methods instead of attributes.
1 parent 7525014 commit 015117f

File tree

3 files changed

+45
-56
lines changed

3 files changed

+45
-56
lines changed

extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/user/SharedUser.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ public String getIdentifier() {
7878
public void setIdentifier(String identifier) {
7979
throw new UnsupportedOperationException("Users authenticated via share keys are immutable.");
8080
}
81+
82+
/**
83+
* {@inheritDoc}
84+
*
85+
* <p>SharedUser accounts are always enabled, as access is controlled via
86+
* the shared token.
87+
*/
88+
@Override
89+
public boolean isDisabled() {
90+
return false;
91+
}
92+
93+
/**
94+
* {@inheritDoc}
95+
*
96+
* <p>This method silently ignores the value passed in the disabled parameter,
97+
* as disabling the account is done by invalidating the sharing token.
98+
*/
99+
@Override
100+
public void setDisabled(boolean disabled) {
101+
// Silently ignore the parameter
102+
}
81103

82104
@Override
83105
public Map<String, String> getAttributes() {

extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledUser.java

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ public class ModeledUser extends ModeledPermissions<UserModel> implements User {
6363
*/
6464
private static final Logger logger = LoggerFactory.getLogger(ModeledUser.class);
6565

66-
/**
67-
* The name of the attribute which controls whether a user account is
68-
* disabled.
69-
*/
70-
public static final String DISABLED_ATTRIBUTE_NAME = "disabled";
71-
7266
/**
7367
* The name of the attribute which controls whether a user's password is
7468
* expired and must be reset upon login.
@@ -121,7 +115,6 @@ public class ModeledUser extends ModeledPermissions<UserModel> implements User {
121115
* form.
122116
*/
123117
public static final Form ACCOUNT_RESTRICTIONS = new Form("restrictions", Arrays.<Field>asList(
124-
new BooleanField(DISABLED_ATTRIBUTE_NAME, "true"),
125118
new BooleanField(EXPIRED_ATTRIBUTE_NAME, "true"),
126119
new TimeField(ACCESS_WINDOW_START_ATTRIBUTE_NAME),
127120
new TimeField(ACCESS_WINDOW_END_ATTRIBUTE_NAME),
@@ -149,7 +142,6 @@ public class ModeledUser extends ModeledPermissions<UserModel> implements User {
149142
User.Attribute.EMAIL_ADDRESS,
150143
User.Attribute.ORGANIZATION,
151144
User.Attribute.ORGANIZATIONAL_ROLE,
152-
DISABLED_ATTRIBUTE_NAME,
153145
EXPIRED_ATTRIBUTE_NAME,
154146
ACCESS_WINDOW_START_ATTRIBUTE_NAME,
155147
ACCESS_WINDOW_END_ATTRIBUTE_NAME,
@@ -281,6 +273,16 @@ public void setPassword(String password) {
281273
userModel.setPasswordDate(new Timestamp(System.currentTimeMillis()));
282274

283275
}
276+
277+
@Override
278+
public boolean isDisabled() {
279+
return getModel().isDisabled();
280+
}
281+
282+
@Override
283+
public void setDisabled(boolean disabled) {
284+
getModel().setDisabled(disabled);
285+
}
284286

285287
/**
286288
* Returns the this user's current password record. If the user is new, this
@@ -309,9 +311,6 @@ public PasswordRecordModel getPasswordRecord() {
309311
*/
310312
private void putRestrictedAttributes(Map<String, String> attributes) {
311313

312-
// Set disabled attribute
313-
attributes.put(DISABLED_ATTRIBUTE_NAME, getModel().isDisabled() ? "true" : null);
314-
315314
// Set password expired attribute
316315
attributes.put(EXPIRED_ATTRIBUTE_NAME, getModel().isExpired() ? "true" : null);
317316

@@ -424,10 +423,6 @@ private Time parseTime(String timeString)
424423
*/
425424
private void setRestrictedAttributes(Map<String, String> attributes) {
426425

427-
// Translate disabled attribute
428-
if (attributes.containsKey(DISABLED_ATTRIBUTE_NAME))
429-
getModel().setDisabled("true".equals(attributes.get(DISABLED_ATTRIBUTE_NAME)));
430-
431426
// Translate password expired attribute
432427
if (attributes.containsKey(EXPIRED_ATTRIBUTE_NAME))
433428
getModel().setExpired("true".equals(attributes.get(EXPIRED_ATTRIBUTE_NAME)));
@@ -737,19 +732,6 @@ public boolean isAccountAccessible() {
737732
return isActive(getAccessWindowStart(), getAccessWindowEnd());
738733
}
739734

740-
/**
741-
* Returns whether this user account has been disabled. The credentials of
742-
* disabled user accounts are treated as invalid, effectively disabling
743-
* that user's access to data for which they would otherwise have
744-
* permission.
745-
*
746-
* @return
747-
* true if this user account has been disabled, false otherwise.
748-
*/
749-
public boolean isDisabled() {
750-
return getModel().isDisabled();
751-
}
752-
753735
/**
754736
* Returns whether this user's password has expired. If a user's password
755737
* is expired, it must be immediately changed upon login. A user account

extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/usergroup/ModeledUserGroup.java

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,17 @@
4242
public class ModeledUserGroup extends ModeledPermissions<UserGroupModel>
4343
implements UserGroup {
4444

45-
/**
46-
* The name of the attribute which controls whether a user group is
47-
* disabled.
48-
*/
49-
public static final String DISABLED_ATTRIBUTE_NAME = "disabled";
50-
51-
/**
52-
* All attributes related to restricting user groups, within a logical
53-
* form.
54-
*/
55-
public static final Form ACCOUNT_RESTRICTIONS = new Form("restrictions", Arrays.<Field>asList(
56-
new BooleanField(DISABLED_ATTRIBUTE_NAME, "true")
57-
));
58-
5945
/**
6046
* All possible attributes of user groups organized as individual,
6147
* logical forms.
6248
*/
63-
public static final Collection<Form> ATTRIBUTES = Collections.unmodifiableCollection(Arrays.asList(
64-
ACCOUNT_RESTRICTIONS
65-
));
66-
49+
public static final Collection<Form> ATTRIBUTES = Collections.emptyList();
50+
6751
/**
6852
* The names of all attributes which are explicitly supported by this
6953
* extension's UserGroup objects.
7054
*/
71-
public static final Set<String> ATTRIBUTE_NAMES =
72-
Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(
73-
DISABLED_ATTRIBUTE_NAME
74-
)));
55+
public static final Set<String> ATTRIBUTE_NAMES = Collections.emptySet();
7556

7657
/**
7758
* Provider for RelatedObjectSets containing the user groups of which this
@@ -121,6 +102,16 @@ public void init(ModeledAuthenticatedUser currentUser, UserGroupModel model,
121102
super.init(currentUser, model);
122103
this.exposeRestrictedAttributes = exposeRestrictedAttributes;
123104
}
105+
106+
@Override
107+
public boolean isDisabled() {
108+
return getModel().isDisabled();
109+
}
110+
111+
@Override
112+
public void setDisabled(boolean disabled) {
113+
getModel().setDisabled(disabled);
114+
}
124115

125116
/**
126117
* Stores all restricted (privileged) attributes within the given Map,
@@ -133,9 +124,6 @@ public void init(ModeledAuthenticatedUser currentUser, UserGroupModel model,
133124
*/
134125
private void putRestrictedAttributes(Map<String, String> attributes) {
135126

136-
// Set disabled attribute
137-
attributes.put(DISABLED_ATTRIBUTE_NAME, getModel().isDisabled() ? "true" : null);
138-
139127
}
140128

141129
/**
@@ -147,9 +135,6 @@ private void putRestrictedAttributes(Map<String, String> attributes) {
147135
*/
148136
private void setRestrictedAttributes(Map<String, String> attributes) {
149137

150-
// Translate disabled attribute
151-
getModel().setDisabled("true".equals(attributes.get(DISABLED_ATTRIBUTE_NAME)));
152-
153138
}
154139

155140
@Override

0 commit comments

Comments
 (0)