Skip to content

Commit

Permalink
GUACAMOLE-1479: Move disabled methods up to new Disableable interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
necouchman committed Apr 3, 2024
1 parent 6145768 commit 732a4c5
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,6 @@ public String getIdentifier() {
public void setIdentifier(String identifier) {
throw new UnsupportedOperationException("Users authenticated via share keys are immutable.");
}

/**
* {@inheritDoc}
*
* <p>SharedUser accounts are always enabled, as access is controlled via
* the shared token.
*/
@Override
public boolean isDisabled() {
return false;
}

/**
* {@inheritDoc}
*
* <p>This method silently ignores the value passed in the disabled parameter,
* as disabling the account is done by invalidating the sharing token.
*/
@Override
public void setDisabled(boolean disabled) {
// Silently ignore the parameter
}

@Override
public Map<String, String> getAttributes() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.guacamole.net.auth;

/**
* An interface that defines items that can be enabled or disabled.
*/
public interface Disableable {

/**
* Returns true if this object is disabled, otherwise false.
*
* @return
* True if this object is disabled, otherwise false.
*/
default public boolean isDisabled() {
return false;
}

/**
* Set the disabled status of this object to the boolean value provided,
* true if the object should be disabled, otherwise false.
*
* @param disabled
* True if the object should be disabled, otherwise false.
*/
default public void setDisabled(boolean disabled) {
// Default implementation takes no action.
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* A user of the Guacamole web application.
*/
public interface User extends Identifiable, Attributes, Permissions {
public interface User extends Disableable, Identifiable, Attributes, Permissions {

/**
* All standard attribute names with semantics defined by the Guacamole web
Expand Down Expand Up @@ -79,23 +79,6 @@ public static class Attribute {
* @param password The password to set.
*/
public void setPassword(String password);

/**
* Returns true if this user account is disabled, otherwise false.
*
* @return
* True if this user account is disabled, otherwise false.
*/
public boolean isDisabled();

/**
* Set the disabled status of this account to the boolean parameter as
* provided, true if the account should be disabled, otherwise false.
*
* @param disabled
* True if the account should be disabled, otherwise false.
*/
public void setDisabled(boolean disabled);

/**
* Returns the date and time that this user was last active. If the user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,8 @@
* any number of Guacamole users and other user groups, and defines the
* permissions implicitly granted to its members.
*/
public interface UserGroup extends Identifiable, Attributes, Permissions {
public interface UserGroup extends Disableable, Identifiable, Attributes, Permissions {

/**
* Returns true if the user group is disabled, making membership in the group
* ineffective, meaning that any permissions or other group membership
* assigned to this group will not apply to member groups and users.
*
* @return
* True if the group is disabled, otherwise false.
*/
public boolean isDisabled();

/**
* Set the disabled status of the user group, passing a boolean true value
* if the user group should be disabled, otherwise false.
*
* @param disabled
* True if the user group should be disabled, otherwise false.
*/
public void setDisabled(boolean disabled);

/**
* Returns a set of all readable user groups of which this user group is a
* member. If permission is granted for the current user to modify the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,6 @@ public SimpleUser() {
public SimpleUser(String username) {
super.setIdentifier(username);
}

/**
* {@inheritDoc}
*
* <p>This User implementation is always enabled, so this method will
* always return false.
*/
@Override
public boolean isDisabled() {
return false;
}

/**
* {@inheritDoc}
*
* <p>This User implementation is always enabled, so this method will
* silently ignore the value passed in under the disabled parameter.
*/
@Override
public void setDisabled(boolean disabled) {
// Silently ignore disabled value
}

/**
* Adds a new READ permission to the given set of permissions for each of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,5 @@ public SimpleUserGroup() {
public SimpleUserGroup(String identifier) {
super.setIdentifier(identifier);
}

/**
* {@inheritDoc}
*
* <p>This implementation of UserGroup is always enabled, so this will
* always return false.
*/
@Override
public boolean isDisabled() {
return false;
}

/**
* {@inheritDoc}
*
* <p>This implementation of UserGroup is always enabled, so this method
* will silently ignore the value passed in the disabled parameter.
*/
@Override
public void setDisabled(boolean disabled) {
// Silently ignore as the UserGroup implementation is always enabled.
}

}

0 comments on commit 732a4c5

Please sign in to comment.