Implement UserDirectory within SimpleUserContext.

This commit is contained in:
Michael Jumper
2013-01-30 23:39:45 -08:00
parent 8dc7a25977
commit 72eb1ba36e
2 changed files with 112 additions and 1 deletions

View File

@@ -68,6 +68,12 @@ public class SimpleUserContext implements UserContext {
*/
private final GuacamoleConfigurationDirectory configDirectory;
/**
* The UserDirectory with access only to the User associated with this
* UserContext.
*/
private final UserDirectory userDirectory;
/**
* Creates a new SimpleUserContext which provides access to only those
* configurations within the given Map. The User given must be the user
@@ -86,6 +92,8 @@ public class SimpleUserContext implements UserContext {
this.configDirectory =
new SimpleGuacamoleConfigurationDirectory(configs);
this.userDirectory = new SimpleUserDirectory(self);
}
@Override
@@ -101,7 +109,7 @@ public class SimpleUserContext implements UserContext {
@Override
public UserDirectory getUserDirectory() throws GuacamoleException {
throw new GuacamoleSecurityException("Permission denied.");
return userDirectory;
}
}

View File

@@ -0,0 +1,103 @@
package net.sourceforge.guacamole.net.auth.simple;
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is guacamole-auth.
*
* The Initial Developer of the Original Code is
* Michael Jumper.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
import java.util.Collections;
import java.util.Set;
import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.GuacamoleSecurityException;
import net.sourceforge.guacamole.net.auth.User;
import net.sourceforge.guacamole.net.auth.UserDirectory;
/**
* An extremely simple read-only implementation of a UserDirectory which
* provides access to a single pre-defined User.
*
* @author Michael Jumper
*/
public class SimpleUserDirectory implements UserDirectory {
/**
* The only user to be contained within this directory.
*/
private User user;
/**
* Creates a new SimpleUserDirectory which provides access to the single
* user provided.
*
* @param user The user to provide access to.
*/
public SimpleUserDirectory(User user) {
this.user = user;
}
@Override
public User getUser(String username) throws GuacamoleException {
// If username matches, return the user
if (user.getUsername().equals(username))
return user;
// Otherwise, not found
return null;
}
@Override
public Set<User> getUsers() throws GuacamoleException {
return Collections.singleton(user);
}
@Override
public void addUser(User user) throws GuacamoleException {
throw new GuacamoleSecurityException("Permission denied.");
}
@Override
public void updateUser(User user) throws GuacamoleException {
throw new GuacamoleSecurityException("Permission denied.");
}
@Override
public void removeUser(String username) throws GuacamoleException {
throw new GuacamoleSecurityException("Permission denied.");
}
}