You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by mj...@apache.org on 2016/03/20 03:15:37 UTC
[27/50] incubator-guacamole-manual git commit: GUAC-1436: Go through
authentication tutorial. Add resulting source.
GUAC-1436: Go through authentication tutorial. Add resulting source.
Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-manual/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-manual/commit/45c2d74f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-manual/tree/45c2d74f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-manual/diff/45c2d74f
Branch: refs/heads/master
Commit: 45c2d74f5962f3d9b64bcfeae41743873409f24f
Parents: 5c4baab
Author: Michael Jumper <mi...@guac-dev.org>
Authored: Wed Dec 16 13:14:09 2015 -0800
Committer: Michael Jumper <mi...@guac-dev.org>
Committed: Wed Dec 16 13:14:09 2015 -0800
----------------------------------------------------------------------
tutorials/guacamole-auth-tutorial/.gitignore | 3 +
tutorials/guacamole-auth-tutorial/pom.xml | 54 +++++++++++++
.../auth/TutorialAuthenticationProvider.java | 82 ++++++++++++++++++++
.../auth/TutorialGuacamoleProperties.java | 59 ++++++++++++++
4 files changed, 198 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-manual/blob/45c2d74f/tutorials/guacamole-auth-tutorial/.gitignore
----------------------------------------------------------------------
diff --git a/tutorials/guacamole-auth-tutorial/.gitignore b/tutorials/guacamole-auth-tutorial/.gitignore
new file mode 100644
index 0000000..c3a023f
--- /dev/null
+++ b/tutorials/guacamole-auth-tutorial/.gitignore
@@ -0,0 +1,3 @@
+*~
+target/
+META-INF/
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-manual/blob/45c2d74f/tutorials/guacamole-auth-tutorial/pom.xml
----------------------------------------------------------------------
diff --git a/tutorials/guacamole-auth-tutorial/pom.xml b/tutorials/guacamole-auth-tutorial/pom.xml
new file mode 100644
index 0000000..33d5c50
--- /dev/null
+++ b/tutorials/guacamole-auth-tutorial/pom.xml
@@ -0,0 +1,54 @@
+<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>org.glyptodon.guacamole</groupId>
+ <artifactId>guacamole-auth-tutorial</artifactId>
+ <packaging>jar</packaging>
+ <version>0.9.9</version>
+ <name>guacamole-auth-tutorial</name>
+ <url>http://guac-dev.org/</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>
+
+ <!-- Guacamole Java API -->
+ <dependency>
+ <groupId>org.glyptodon.guacamole</groupId>
+ <artifactId>guacamole-common</artifactId>
+ <version>0.9.9</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Guacamole Extension API -->
+ <dependency>
+ <groupId>org.glyptodon.guacamole</groupId>
+ <artifactId>guacamole-ext</artifactId>
+ <version>0.9.9</version>
+ <scope>provided</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-manual/blob/45c2d74f/tutorials/guacamole-auth-tutorial/src/main/java/org/glyptodon/guacamole/auth/TutorialAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/tutorials/guacamole-auth-tutorial/src/main/java/org/glyptodon/guacamole/auth/TutorialAuthenticationProvider.java b/tutorials/guacamole-auth-tutorial/src/main/java/org/glyptodon/guacamole/auth/TutorialAuthenticationProvider.java
new file mode 100644
index 0000000..4084b6b
--- /dev/null
+++ b/tutorials/guacamole-auth-tutorial/src/main/java/org/glyptodon/guacamole/auth/TutorialAuthenticationProvider.java
@@ -0,0 +1,82 @@
+package org.glyptodon.guacamole.auth;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.glyptodon.guacamole.GuacamoleException;
+import org.glyptodon.guacamole.GuacamoleServerException;
+import org.glyptodon.guacamole.environment.Environment;
+import org.glyptodon.guacamole.environment.LocalEnvironment;
+import org.glyptodon.guacamole.net.auth.simple.SimpleAuthenticationProvider;
+import org.glyptodon.guacamole.net.auth.Credentials;
+import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
+
+public class TutorialAuthenticationProvider extends SimpleAuthenticationProvider {
+
+ @Override
+ public String getIdentifier() {
+ return "tutorial";
+ }
+
+ @Override
+ public Map<String, GuacamoleConfiguration>
+ getAuthorizedConfigurations(Credentials credentials)
+ throws GuacamoleException {
+
+ // Get the Guacamole server environment
+ Environment environment = new LocalEnvironment();
+
+ // Get username from guacamole.properties
+ String username = environment.getRequiredProperty(
+ TutorialGuacamoleProperties.TUTORIAL_USER
+ );
+
+ // If wrong username, fail
+ if (!username.equals(credentials.getUsername()))
+ return null;
+
+ // Get password from guacamole.properties
+ String password = environment.getRequiredProperty(
+ TutorialGuacamoleProperties.TUTORIAL_PASSWORD
+ );
+
+ // If wrong password, fail
+ if (!password.equals(credentials.getPassword()))
+ return null;
+
+ // Successful login. Return configurations.
+ Map<String, GuacamoleConfiguration> configs =
+ new HashMap<String, GuacamoleConfiguration>();
+
+ // Create new configuration
+ GuacamoleConfiguration config = new GuacamoleConfiguration();
+
+ // Set protocol specified in properties
+ config.setProtocol(environment.getRequiredProperty(
+ TutorialGuacamoleProperties.TUTORIAL_PROTOCOL
+ ));
+
+ // Set all parameters, splitting at commas
+ for (String parameterValue : environment.getRequiredProperty(
+ TutorialGuacamoleProperties.TUTORIAL_PARAMETERS
+ ).split(",\\s*")) {
+
+ // Find the equals sign
+ int equals = parameterValue.indexOf('=');
+ if (equals == -1)
+ throw new GuacamoleServerException("Required equals sign missing");
+
+ // Get name and value from parameter string
+ String name = parameterValue.substring(0, equals);
+ String value = parameterValue.substring(equals+1);
+
+ // Set parameter as specified
+ config.setParameter(name, value);
+
+ }
+
+ configs.put("Tutorial Connection", config);
+ return configs;
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-manual/blob/45c2d74f/tutorials/guacamole-auth-tutorial/src/main/java/org/glyptodon/guacamole/auth/TutorialGuacamoleProperties.java
----------------------------------------------------------------------
diff --git a/tutorials/guacamole-auth-tutorial/src/main/java/org/glyptodon/guacamole/auth/TutorialGuacamoleProperties.java b/tutorials/guacamole-auth-tutorial/src/main/java/org/glyptodon/guacamole/auth/TutorialGuacamoleProperties.java
new file mode 100644
index 0000000..4f98d0c
--- /dev/null
+++ b/tutorials/guacamole-auth-tutorial/src/main/java/org/glyptodon/guacamole/auth/TutorialGuacamoleProperties.java
@@ -0,0 +1,59 @@
+package org.glyptodon.guacamole.auth;
+
+import org.glyptodon.guacamole.properties.StringGuacamoleProperty;
+
+public class TutorialGuacamoleProperties {
+
+ /**
+ * This class should not be instantiated.
+ */
+ private TutorialGuacamoleProperties() {}
+
+ /**
+ * The only user to allow.
+ */
+ public static final StringGuacamoleProperty TUTORIAL_USER =
+ new StringGuacamoleProperty() {
+
+ @Override
+ public String getName() { return "tutorial-user"; }
+
+ };
+
+ /**
+ * The password required for the specified user.
+ */
+ public static final StringGuacamoleProperty TUTORIAL_PASSWORD =
+ new StringGuacamoleProperty() {
+
+ @Override
+ public String getName() { return "tutorial-password"; }
+
+ };
+
+
+ /**
+ * The protocol to use when connecting.
+ */
+ public static final StringGuacamoleProperty TUTORIAL_PROTOCOL =
+ new StringGuacamoleProperty() {
+
+ @Override
+ public String getName() { return "tutorial-protocol"; }
+
+ };
+
+
+ /**
+ * All parameters associated with the connection, as a comma-delimited
+ * list of name="value"
+ */
+ public static final StringGuacamoleProperty TUTORIAL_PARAMETERS =
+ new StringGuacamoleProperty() {
+
+ @Override
+ public String getName() { return "tutorial-parameters"; }
+
+ };
+
+}