From 72eb1ba36e3047158cd6194cbcb860847120e03d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 30 Jan 2013 23:39:45 -0800 Subject: [PATCH] Implement UserDirectory within SimpleUserContext. --- .../net/auth/simple/SimpleUserContext.java | 10 +- .../net/auth/simple/SimpleUserDirectory.java | 103 ++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserDirectory.java diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserContext.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserContext.java index a7697ea19..c96a00a77 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserContext.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserContext.java @@ -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; } } diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserDirectory.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserDirectory.java new file mode 100644 index 000000000..9fe3b8a64 --- /dev/null +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserDirectory.java @@ -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 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."); + } + +}