mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Move NoAuthenticationProvider under extensions/
New auth providers shouldn't go in guacamole-ext, which is strictly the API used by extensions to Guacamole. Instead this should be a separate project like "guacamole-auth-noauth", and should go under extensions/.
This commit is contained in:
committed by
Michael Jumper
parent
b3e3855fd1
commit
f1f2e04860
1
extensions/guacamole-auth-noauth/.gitignore
vendored
Normal file
1
extensions/guacamole-auth-noauth/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
target/
|
57
extensions/guacamole-auth-noauth/README.rst
Normal file
57
extensions/guacamole-auth-noauth/README.rst
Normal file
@@ -0,0 +1,57 @@
|
||||
guacamole-noauth
|
||||
================
|
||||
|
||||
Remove login screen from the `Guacamole <http://guac-dev.org/>`_ web interface.
|
||||
|
||||
Build
|
||||
-----
|
||||
|
||||
- Download
|
||||
|
||||
::
|
||||
|
||||
git clone http://git.deltalima.net/guacamole-noauth/
|
||||
|
||||
- Compile
|
||||
|
||||
::
|
||||
|
||||
cd extensions/guacamole-auth-noauth/
|
||||
mvn package
|
||||
|
||||
These will create a new jar file `guacamole-noauth-VERSION.jar` in the
|
||||
`target/` folder.
|
||||
|
||||
|
||||
Install
|
||||
-------
|
||||
|
||||
- Copy `guacamole-noauth-VERSION.jar` in `webapps/guacamole/WEB-INF/lib/`. It
|
||||
does not work if you copy the jar in `common/lib/` or `shared/lib/`.
|
||||
|
||||
Configure
|
||||
---------
|
||||
|
||||
- Edit the Guacamole configuration file (`/etc/guacamole/guacamole.properties`):
|
||||
|
||||
::
|
||||
|
||||
# Hostname and port of guacamole proxy
|
||||
guacd-hostname: localhost
|
||||
guacd-port: 4822
|
||||
|
||||
auth-provider: net.sourceforge.guacamole.net.auth.noauth.NoAuthenticationProvider
|
||||
noauth-config: /etc/guacamole/noauth-config.xml
|
||||
|
||||
- Create a new file `/etc/gacamole/noauth-config.xml`:
|
||||
|
||||
::
|
||||
|
||||
<configs>
|
||||
<config name="my-rdp-server" protocol="rdp">
|
||||
<param name="hostname" value="my-rdp-server-hostname" />
|
||||
<param name="port" value="3389" />
|
||||
</config>
|
||||
</configs>
|
||||
|
||||
- Restart Tomcat
|
@@ -0,0 +1,6 @@
|
||||
<configs>
|
||||
<config name="myconfig" protocol="rdp">
|
||||
<param name="hostname" value="rdp-server" />
|
||||
<param name="port" value="3389" />
|
||||
</config>
|
||||
</configs>
|
@@ -0,0 +1,4 @@
|
||||
# Add these two lines to your guacamole.properties file
|
||||
|
||||
auth-provider: net.sourceforge.guacamole.net.auth.noauth.NoAuthenticationProvider
|
||||
noauth-config: /etc/guacamole/noauth-config.xml
|
67
extensions/guacamole-auth-noauth/pom.xml
Normal file
67
extensions/guacamole-auth-noauth/pom.xml
Normal file
@@ -0,0 +1,67 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.deltalima.guacamole</groupId>
|
||||
<artifactId>guacamole-noauth</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.8.0</version>
|
||||
<name>guacamole-noauth</name>
|
||||
<url>http://guacamole.sourceforge.net/</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Written for 1.6 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- SLF4J - logging -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jcl</artifactId>
|
||||
<version>1.6.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Guacamole Java API -->
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.guacamole</groupId>
|
||||
<artifactId>guacamole-common</artifactId>
|
||||
<version>0.8.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Guacamole Extension API -->
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.guacamole</groupId>
|
||||
<artifactId>guacamole-ext</artifactId>
|
||||
<version>0.8.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<!-- Central Guacamole repository -->
|
||||
<repository>
|
||||
<id>guac-dev</id>
|
||||
<url>http://guac-dev.org/repo</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
@@ -0,0 +1,202 @@
|
||||
|
||||
package net.sourceforge.guacamole.net.auth.noauth;
|
||||
|
||||
/* ***** 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.HashMap;
|
||||
import java.util.Map;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.net.auth.simple.SimpleAuthenticationProvider;
|
||||
import net.sourceforge.guacamole.net.auth.Credentials;
|
||||
import net.sourceforge.guacamole.properties.FileGuacamoleProperty;
|
||||
import net.sourceforge.guacamole.properties.GuacamoleProperties;
|
||||
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Disable authentication in Guacamole. All users accessing Guacamole are
|
||||
* automatically authenticated as "Anonymous" user and are able to use all
|
||||
* available GuacamoleConfigurations.
|
||||
*
|
||||
* GuacamoleConfiguration are read from the XML file defined by `noauth-config`
|
||||
* in the Guacamole configuration file (`guacamole.properties`).
|
||||
*
|
||||
*
|
||||
* Example `guacamole.properties`:
|
||||
*
|
||||
* auth-provider: net.sourceforge.guacamole.net.auth.noauth.NoAuthenticationProvider
|
||||
* noauth-config: /etc/guacamole/noauth-config.xml
|
||||
*
|
||||
*
|
||||
* Example `noauth-config.xml`:
|
||||
*
|
||||
* <configs>
|
||||
* <config name="my-rdp-server" protocol="rdp">
|
||||
* <param name="hostname" value="my-rdp-server-hostname" />
|
||||
* <param name="port" value="3389" />
|
||||
* </config>
|
||||
* </configs>
|
||||
*
|
||||
*/
|
||||
public class NoAuthenticationProvider extends SimpleAuthenticationProvider {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(NoAuthenticationProvider.class);
|
||||
private Map<String, GuacamoleConfiguration> configs;
|
||||
private long configTime;
|
||||
|
||||
/**
|
||||
* The filename of the XML file to read the user mapping from.
|
||||
*/
|
||||
public static final FileGuacamoleProperty NOAUTH_CONFIG = new FileGuacamoleProperty() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "noauth-config";
|
||||
}
|
||||
};
|
||||
|
||||
private File getConfigurationFile() throws GuacamoleException {
|
||||
// Get configuration file
|
||||
return GuacamoleProperties.getProperty(NOAUTH_CONFIG);
|
||||
}
|
||||
|
||||
public synchronized void init() throws GuacamoleException {
|
||||
// Get configuration file
|
||||
File configFile = getConfigurationFile();
|
||||
if(configFile == null) {
|
||||
throw new GuacamoleException(
|
||||
"Missing \"noauth-config\" parameter required for NoAuthenticationProvider."
|
||||
);
|
||||
}
|
||||
|
||||
logger.info("Reading configuration file: {}", configFile);
|
||||
|
||||
// Parse document
|
||||
try {
|
||||
// Set up parser
|
||||
NoAuthConfigContentHandler contentHandler = new NoAuthConfigContentHandler();
|
||||
|
||||
XMLReader parser = XMLReaderFactory.createXMLReader();
|
||||
parser.setContentHandler(contentHandler);
|
||||
|
||||
// Read and parse file
|
||||
Reader reader = new BufferedReader(new FileReader(configFile));
|
||||
parser.parse(new InputSource(reader));
|
||||
reader.close();
|
||||
|
||||
// Init configs
|
||||
configTime = configFile.lastModified();
|
||||
configs = contentHandler.getConfigs();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new GuacamoleException("Error reading configuration file: " + e.getMessage(), e);
|
||||
}
|
||||
catch (SAXException e) {
|
||||
throw new GuacamoleException("Error parsing XML file: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, GuacamoleConfiguration> getAuthorizedConfigurations(Credentials credentials) throws GuacamoleException {
|
||||
// Check mapping file mod time
|
||||
File configFile = getConfigurationFile();
|
||||
if (configFile.exists() && configTime < configFile.lastModified()) {
|
||||
// If modified recently, gain exclusive access and recheck
|
||||
synchronized (this) {
|
||||
if (configFile.exists() && configTime < configFile.lastModified()) {
|
||||
logger.info("Config file {} has been modified.", configFile);
|
||||
init(); // If still not up to date, re-init
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If no mapping available, report as such
|
||||
if (configs == null) {
|
||||
throw new GuacamoleException("Configuration could not be read.");
|
||||
}
|
||||
|
||||
// Guacamole 0.8 wants a username to be set, otherwise the
|
||||
// authentication process will fail.
|
||||
credentials.setUsername("Anonymous");
|
||||
|
||||
return configs;
|
||||
}
|
||||
|
||||
private static class NoAuthConfigContentHandler extends DefaultHandler {
|
||||
private Map<String, GuacamoleConfiguration> configs = new HashMap<String, GuacamoleConfiguration>();
|
||||
private String current = null;
|
||||
private GuacamoleConfiguration currentConfig = null;
|
||||
|
||||
public Map<String, GuacamoleConfiguration> getConfigs() {
|
||||
return Collections.unmodifiableMap(configs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
if(localName.equals("config")) {
|
||||
configs.put(current, currentConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
if(localName.equals("config")) {
|
||||
current = attributes.getValue("name");
|
||||
currentConfig = new GuacamoleConfiguration();
|
||||
currentConfig.setProtocol(attributes.getValue("protocol"));
|
||||
return;
|
||||
} else if(localName.equals("param")) {
|
||||
currentConfig.setParameter(attributes.getValue("name"),
|
||||
attributes.getValue("value"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user