mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
Migrate SimpleAuthenticationProvider to model with permissions residing in User.
This commit is contained in:
@@ -90,7 +90,7 @@ public abstract class SimpleAuthenticationProvider
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Build new user from credentials
|
// Build new user from credentials
|
||||||
User user = new SimpleUser(credentials.getUsername());
|
User user = new SimpleUser(credentials.getUsername(), configs);
|
||||||
|
|
||||||
// Return user context restricted to authorized configs
|
// Return user context restricted to authorized configs
|
||||||
return new SimpleUserContext(user, configs);
|
return new SimpleUserContext(user, configs);
|
||||||
|
@@ -37,7 +37,16 @@ package net.sourceforge.guacamole.net.auth.simple;
|
|||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleSecurityException;
|
||||||
import net.sourceforge.guacamole.net.auth.AbstractUser;
|
import net.sourceforge.guacamole.net.auth.AbstractUser;
|
||||||
|
import net.sourceforge.guacamole.net.auth.permission.GuacamoleConfigurationPermission;
|
||||||
|
import net.sourceforge.guacamole.net.auth.permission.ObjectPermission;
|
||||||
|
import net.sourceforge.guacamole.net.auth.permission.Permission;
|
||||||
|
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,6 +56,11 @@ import net.sourceforge.guacamole.net.auth.AbstractUser;
|
|||||||
*/
|
*/
|
||||||
public class SimpleUser extends AbstractUser {
|
public class SimpleUser extends AbstractUser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The set of all permissions available to this user.
|
||||||
|
*/
|
||||||
|
private Set<Permission> permissions = new HashSet<Permission>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a completely uninitialized SimpleUser.
|
* Creates a completely uninitialized SimpleUser.
|
||||||
*/
|
*/
|
||||||
@@ -57,9 +71,51 @@ public class SimpleUser extends AbstractUser {
|
|||||||
* Creates a new SimpleUser having the given username.
|
* Creates a new SimpleUser having the given username.
|
||||||
*
|
*
|
||||||
* @param username The username to assign to this SimpleUser.
|
* @param username The username to assign to this SimpleUser.
|
||||||
|
* @param configs All configurations this user has read access to.
|
||||||
*/
|
*/
|
||||||
public SimpleUser(String username) {
|
public SimpleUser(String username,
|
||||||
|
Map<String, GuacamoleConfiguration> configs) {
|
||||||
|
|
||||||
|
// Set username
|
||||||
setUsername(username);
|
setUsername(username);
|
||||||
|
|
||||||
|
// Add permissions
|
||||||
|
for (String identifier : configs.keySet()) {
|
||||||
|
|
||||||
|
// Create permission
|
||||||
|
Permission permission = new GuacamoleConfigurationPermission(
|
||||||
|
ObjectPermission.Type.READ,
|
||||||
|
identifier
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add to set
|
||||||
|
permissions.add(permission);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Permission> getPermissions() throws GuacamoleException {
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(Permission permission) throws GuacamoleException {
|
||||||
|
|
||||||
|
/* FIXME: STUB! */
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addPermission(Permission permission) throws GuacamoleException {
|
||||||
|
throw new GuacamoleSecurityException("Permission denied.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removePermission(Permission permission) throws GuacamoleException {
|
||||||
|
throw new GuacamoleSecurityException("Permission denied.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user