mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-220: Deprecate built-in support for storage of permissions in SimpleUser. Add convenience constructors for SimpleObjectPermissionSet.
This commit is contained in:
@@ -34,8 +34,10 @@ import org.apache.guacamole.net.auth.ConnectionGroup;
|
|||||||
import org.apache.guacamole.net.auth.Directory;
|
import org.apache.guacamole.net.auth.Directory;
|
||||||
import org.apache.guacamole.net.auth.User;
|
import org.apache.guacamole.net.auth.User;
|
||||||
import org.apache.guacamole.net.auth.UserGroup;
|
import org.apache.guacamole.net.auth.UserGroup;
|
||||||
|
import org.apache.guacamole.net.auth.permission.ObjectPermissionSet;
|
||||||
import org.apache.guacamole.net.auth.simple.SimpleConnectionGroup;
|
import org.apache.guacamole.net.auth.simple.SimpleConnectionGroup;
|
||||||
import org.apache.guacamole.net.auth.simple.SimpleDirectory;
|
import org.apache.guacamole.net.auth.simple.SimpleDirectory;
|
||||||
|
import org.apache.guacamole.net.auth.simple.SimpleObjectPermissionSet;
|
||||||
import org.apache.guacamole.net.auth.simple.SimpleUser;
|
import org.apache.guacamole.net.auth.simple.SimpleUser;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -149,13 +151,29 @@ public class UserContext extends AbstractUserContext {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Init self with basic permissions
|
// Init self with basic permissions
|
||||||
self = new SimpleUser(
|
self = new SimpleUser(user.getIdentifier()) {
|
||||||
user.getIdentifier(),
|
|
||||||
userDirectory.getIdentifiers(),
|
@Override
|
||||||
userGroupDirectory.getIdentifiers(),
|
public ObjectPermissionSet getUserPermissions() throws GuacamoleException {
|
||||||
connectionDirectory.getIdentifiers(),
|
return new SimpleObjectPermissionSet(userDirectory.getIdentifiers());
|
||||||
Collections.singleton(LDAPAuthenticationProvider.ROOT_CONNECTION_GROUP)
|
}
|
||||||
);
|
|
||||||
|
@Override
|
||||||
|
public ObjectPermissionSet getUserGroupPermissions() throws GuacamoleException {
|
||||||
|
return new SimpleObjectPermissionSet(userGroupDirectory.getIdentifiers());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectPermissionSet getConnectionPermissions() throws GuacamoleException {
|
||||||
|
return new SimpleObjectPermissionSet(connectionDirectory.getIdentifiers());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectPermissionSet getConnectionGroupPermissions() throws GuacamoleException {
|
||||||
|
return new SimpleObjectPermissionSet(Collections.singleton(LDAPAuthenticationProvider.ROOT_CONNECTION_GROUP));
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,6 +26,8 @@ import org.apache.guacamole.net.auth.AbstractUserContext;
|
|||||||
import org.apache.guacamole.net.auth.AuthenticationProvider;
|
import org.apache.guacamole.net.auth.AuthenticationProvider;
|
||||||
import org.apache.guacamole.net.auth.ConnectionGroup;
|
import org.apache.guacamole.net.auth.ConnectionGroup;
|
||||||
import org.apache.guacamole.net.auth.User;
|
import org.apache.guacamole.net.auth.User;
|
||||||
|
import org.apache.guacamole.net.auth.permission.ObjectPermissionSet;
|
||||||
|
import org.apache.guacamole.net.auth.simple.SimpleObjectPermissionSet;
|
||||||
import org.apache.guacamole.net.auth.simple.SimpleUser;
|
import org.apache.guacamole.net.auth.simple.SimpleUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,10 +95,19 @@ public class QuickConnectUserContext extends AbstractUserContext {
|
|||||||
|
|
||||||
// Initialize the user to a SimpleUser with the provided username,
|
// Initialize the user to a SimpleUser with the provided username,
|
||||||
// no connections, and the single root group.
|
// no connections, and the single root group.
|
||||||
this.self = new SimpleUser(username,
|
this.self = new SimpleUser(username) {
|
||||||
connectionDirectory.getIdentifiers(),
|
|
||||||
Collections.singleton(ROOT_IDENTIFIER)
|
@Override
|
||||||
);
|
public ObjectPermissionSet getConnectionPermissions() throws GuacamoleException {
|
||||||
|
return new SimpleObjectPermissionSet(connectionDirectory.getIdentifiers());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectPermissionSet getConnectionGroupPermissions() throws GuacamoleException {
|
||||||
|
return new SimpleObjectPermissionSet(Collections.singleton(ROOT_IDENTIFIER));
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
// Set the authProvider to the calling authProvider object.
|
// Set the authProvider to the calling authProvider object.
|
||||||
this.authProvider = authProvider;
|
this.authProvider = authProvider;
|
||||||
|
@@ -22,6 +22,7 @@ package org.apache.guacamole.net.auth.simple;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.apache.guacamole.GuacamoleException;
|
import org.apache.guacamole.GuacamoleException;
|
||||||
import org.apache.guacamole.GuacamoleSecurityException;
|
import org.apache.guacamole.GuacamoleSecurityException;
|
||||||
@@ -45,6 +46,66 @@ public class SimpleObjectPermissionSet implements ObjectPermissionSet {
|
|||||||
public SimpleObjectPermissionSet() {
|
public SimpleObjectPermissionSet() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new set of ObjectPermissions for each possible combination of
|
||||||
|
* the given identifiers and permission types.
|
||||||
|
*
|
||||||
|
* @param identifiers
|
||||||
|
* The identifiers which should have one ObjectPermission for each of
|
||||||
|
* the given permission types.
|
||||||
|
*
|
||||||
|
* @param types
|
||||||
|
* The permissions which should be granted for each of the given
|
||||||
|
* identifiers.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* A new set of ObjectPermissions containing one ObjectPermission for
|
||||||
|
* each possible combination of the given identifiers and permission
|
||||||
|
* types.
|
||||||
|
*/
|
||||||
|
private static Set<ObjectPermission> createPermissions(Collection<String> identifiers,
|
||||||
|
Collection<ObjectPermission.Type> types) {
|
||||||
|
|
||||||
|
// Add a permission of each type to the set for each identifier given
|
||||||
|
Set<ObjectPermission> permissions = new HashSet<>(identifiers.size());
|
||||||
|
types.forEach(type -> {
|
||||||
|
identifiers.forEach(identifier -> permissions.add(new ObjectPermission(type, identifier)));
|
||||||
|
});
|
||||||
|
|
||||||
|
return permissions;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new SimpleObjectPermissionSet which contains permissions for
|
||||||
|
* all possible unique combinations of the given identifiers and permission
|
||||||
|
* types.
|
||||||
|
*
|
||||||
|
* @param identifiers
|
||||||
|
* The identifiers which should be associated permissions having each
|
||||||
|
* of the given permission types.
|
||||||
|
*
|
||||||
|
* @param types
|
||||||
|
* The types of permissions which should be granted for each of the
|
||||||
|
* given identifiers.
|
||||||
|
*/
|
||||||
|
public SimpleObjectPermissionSet(Collection<String> identifiers,
|
||||||
|
Collection<ObjectPermission.Type> types) {
|
||||||
|
this(createPermissions(identifiers, types));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new SimpleObjectPermissionSet which contains only READ
|
||||||
|
* permissions for each of the given identifiers.
|
||||||
|
*
|
||||||
|
* @param identifiers
|
||||||
|
* The identifiers which should each be associated with READ
|
||||||
|
* permission.
|
||||||
|
*/
|
||||||
|
public SimpleObjectPermissionSet(Collection<String> identifiers) {
|
||||||
|
this(identifiers, Collections.singletonList(ObjectPermission.Type.READ));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new SimpleObjectPermissionSet which contains the permissions
|
* Creates a new SimpleObjectPermissionSet which contains the permissions
|
||||||
* within the given Set.
|
* within the given Set.
|
||||||
|
@@ -45,11 +45,6 @@ public class SimpleUser extends AbstractUser {
|
|||||||
*/
|
*/
|
||||||
private final Set<ObjectPermission> userPermissions = new HashSet<>();
|
private final Set<ObjectPermission> userPermissions = new HashSet<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* All user group permissions granted to this user.
|
|
||||||
*/
|
|
||||||
private final Set<ObjectPermission> userGroupPermissions = new HashSet<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All connection permissions granted to this user.
|
* All connection permissions granted to this user.
|
||||||
*/
|
*/
|
||||||
@@ -115,7 +110,15 @@ public class SimpleUser extends AbstractUser {
|
|||||||
* @param connectionGroupIdentifiers
|
* @param connectionGroupIdentifiers
|
||||||
* The identifiers of all connection groups this user has READ access
|
* The identifiers of all connection groups this user has READ access
|
||||||
* to.
|
* to.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
* Extend and override the applicable permission set getters instead,
|
||||||
|
* relying on SimpleUser to expose no permissions by default for all
|
||||||
|
* permission sets that aren't overridden. See {@link SimpleObjectPermissionSet}
|
||||||
|
* for convenient methods of providing a read-only permission set with
|
||||||
|
* specific permissions.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public SimpleUser(String username,
|
public SimpleUser(String username,
|
||||||
Collection<String> connectionIdentifiers,
|
Collection<String> connectionIdentifiers,
|
||||||
Collection<String> connectionGroupIdentifiers) {
|
Collection<String> connectionGroupIdentifiers) {
|
||||||
@@ -128,43 +131,6 @@ public class SimpleUser extends AbstractUser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new SimpleUser having the given username and READ access to
|
|
||||||
* the users, user groups, connections, and connection groups having the
|
|
||||||
* given identifiers.
|
|
||||||
*
|
|
||||||
* @param username
|
|
||||||
* The username to assign to this SimpleUser.
|
|
||||||
*
|
|
||||||
* @param userIdentifiers
|
|
||||||
* The identifiers of all users this user has READ access to.
|
|
||||||
*
|
|
||||||
* @param userGroupIdentifiers
|
|
||||||
* The identifiers of all user groups this user has READ access to.
|
|
||||||
*
|
|
||||||
* @param connectionIdentifiers
|
|
||||||
* The identifiers of all connections this user has READ access to.
|
|
||||||
*
|
|
||||||
* @param connectionGroupIdentifiers
|
|
||||||
* The identifiers of all connection groups this user has READ access
|
|
||||||
* to.
|
|
||||||
*/
|
|
||||||
public SimpleUser(String username,
|
|
||||||
Collection<String> userIdentifiers,
|
|
||||||
Collection<String> userGroupIdentifiers,
|
|
||||||
Collection<String> connectionIdentifiers,
|
|
||||||
Collection<String> connectionGroupIdentifiers) {
|
|
||||||
|
|
||||||
this(username);
|
|
||||||
|
|
||||||
// Add permissions
|
|
||||||
addReadPermissions(userPermissions, userIdentifiers);
|
|
||||||
addReadPermissions(userGroupPermissions, userGroupIdentifiers);
|
|
||||||
addReadPermissions(connectionPermissions, connectionIdentifiers);
|
|
||||||
addReadPermissions(connectionGroupPermissions, connectionGroupIdentifiers);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new SimpleUser having the given username and READ access to
|
* Creates a new SimpleUser having the given username and READ access to
|
||||||
* the users, connections, and groups having the given identifiers.
|
* the users, connections, and groups having the given identifiers.
|
||||||
@@ -181,7 +147,15 @@ public class SimpleUser extends AbstractUser {
|
|||||||
* @param connectionGroupIdentifiers
|
* @param connectionGroupIdentifiers
|
||||||
* The identifiers of all connection groups this user has READ access
|
* The identifiers of all connection groups this user has READ access
|
||||||
* to.
|
* to.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
* Extend and override the applicable permission set getters instead,
|
||||||
|
* relying on SimpleUser to expose no permissions by default for all
|
||||||
|
* permission sets that aren't overridden. See {@link SimpleObjectPermissionSet}
|
||||||
|
* for convenient methods of providing a read-only permission set with
|
||||||
|
* specific permissions.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public SimpleUser(String username,
|
public SimpleUser(String username,
|
||||||
Collection<String> userIdentifiers,
|
Collection<String> userIdentifiers,
|
||||||
Collection<String> connectionIdentifiers,
|
Collection<String> connectionIdentifiers,
|
||||||
|
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package org.apache.guacamole.net.auth.simple;
|
package org.apache.guacamole.net.auth.simple;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import org.apache.guacamole.GuacamoleException;
|
import org.apache.guacamole.GuacamoleException;
|
||||||
@@ -29,6 +28,7 @@ import org.apache.guacamole.net.auth.AuthenticationProvider;
|
|||||||
import org.apache.guacamole.net.auth.Connection;
|
import org.apache.guacamole.net.auth.Connection;
|
||||||
import org.apache.guacamole.net.auth.Directory;
|
import org.apache.guacamole.net.auth.Directory;
|
||||||
import org.apache.guacamole.net.auth.User;
|
import org.apache.guacamole.net.auth.User;
|
||||||
|
import org.apache.guacamole.net.auth.permission.ObjectPermissionSet;
|
||||||
import org.apache.guacamole.protocol.GuacamoleConfiguration;
|
import org.apache.guacamole.protocol.GuacamoleConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,20 +113,19 @@ public class SimpleUserContext extends AbstractUserContext {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User self() {
|
public User self() {
|
||||||
|
return new SimpleUser(username) {
|
||||||
|
|
||||||
try {
|
@Override
|
||||||
return new SimpleUser(username,
|
public ObjectPermissionSet getConnectionGroupPermissions() throws GuacamoleException {
|
||||||
getConnectionDirectory().getIdentifiers(),
|
return new SimpleObjectPermissionSet(getConnectionDirectory().getIdentifiers());
|
||||||
getConnectionGroupDirectory().getIdentifiers()
|
}
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (GuacamoleException e) {
|
@Override
|
||||||
return new SimpleUser(username,
|
public ObjectPermissionSet getConnectionPermissions() throws GuacamoleException {
|
||||||
Collections.<String>emptySet(),
|
return new SimpleObjectPermissionSet(getConnectionGroupDirectory().getIdentifiers());
|
||||||
Collections.<String>emptySet());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user