diff --git a/doc/guacamole-example/pom.xml b/doc/guacamole-example/pom.xml index ae1fcb34f..d1f5d0f4b 100644 --- a/doc/guacamole-example/pom.xml +++ b/doc/guacamole-example/pom.xml @@ -20,9 +20,15 @@ org.apache.maven.plugins maven-compiler-plugin + 3.3 1.6 1.6 + + -Xlint:all + -Werror + + true diff --git a/doc/guacamole-example/src/main/java/org/glyptodon/guacamole/net/example/DummyGuacamoleTunnelServlet.java b/doc/guacamole-example/src/main/java/org/glyptodon/guacamole/net/example/DummyGuacamoleTunnelServlet.java index b7ca41909..a34d47633 100644 --- a/doc/guacamole-example/src/main/java/org/glyptodon/guacamole/net/example/DummyGuacamoleTunnelServlet.java +++ b/doc/guacamole-example/src/main/java/org/glyptodon/guacamole/net/example/DummyGuacamoleTunnelServlet.java @@ -28,6 +28,7 @@ import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.net.GuacamoleSocket; import org.glyptodon.guacamole.net.GuacamoleTunnel; import org.glyptodon.guacamole.net.InetGuacamoleSocket; +import org.glyptodon.guacamole.net.SimpleGuacamoleTunnel; import org.glyptodon.guacamole.protocol.ConfiguredGuacamoleSocket; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; import org.glyptodon.guacamole.servlet.GuacamoleHTTPTunnelServlet; @@ -63,7 +64,7 @@ public class DummyGuacamoleTunnelServlet extends GuacamoleHTTPTunnelServlet { ); // Create tunnel from now-configured socket - GuacamoleTunnel tunnel = new GuacamoleTunnel(socket); + GuacamoleTunnel tunnel = new SimpleGuacamoleTunnel(socket); // Attach tunnel GuacamoleSession session = new GuacamoleSession(httpSession); diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/pom.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/pom.xml index 8d8d72f22..3373587b0 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/pom.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/pom.xml @@ -26,9 +26,15 @@ org.apache.maven.plugins maven-compiler-plugin + 3.3 1.6 1.6 + + -Xlint:all + -Werror + + true diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/ModeledDirectoryObjectService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/ModeledDirectoryObjectService.java index 7d9137075..b5cb2822f 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/ModeledDirectoryObjectService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/ModeledDirectoryObjectService.java @@ -316,7 +316,7 @@ public abstract class ModeledDirectoryObjectServiceemptyList(); Collection objects; diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/ModeledGroupedDirectoryObjectService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/ModeledGroupedDirectoryObjectService.java index 1cfa734d0..4976b3ec8 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/ModeledGroupedDirectoryObjectService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/ModeledGroupedDirectoryObjectService.java @@ -96,7 +96,7 @@ public abstract class ModeledGroupedDirectoryObjectServiceemptyList(); } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ConnectionService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ConnectionService.java index f3fb48261..53c2d3b5d 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ConnectionService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ConnectionService.java @@ -204,7 +204,7 @@ public class ConnectionService extends ModeledGroupedDirectoryObjectService parameters = connection.getConfiguration().getParameters(); // Convert parameters to model objects - Collection parameterModels = new ArrayList(parameters.size()); + Collection parameterModels = new ArrayList(parameters.size()); for (Map.Entry parameterEntry : parameters.entrySet()) { // Get parameter name and value diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/permission/ModeledObjectPermissionService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/permission/ModeledObjectPermissionService.java index ad4f65859..d939fbd49 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/permission/ModeledObjectPermissionService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/permission/ModeledObjectPermissionService.java @@ -106,7 +106,7 @@ public abstract class ModeledObjectPermissionService return false; // Produce collection of affected identifiers - Collection affectedIdentifiers = new HashSet(permissions.size()); + Collection affectedIdentifiers = new HashSet(permissions.size()); for (ObjectPermission permission : permissions) affectedIdentifiers.add(permission.getObjectIdentifier()); diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java index bfa6231e3..9a8c67235 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java @@ -424,12 +424,12 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS // If not a balancing group, there are no balanced connections if (connectionGroup.getType() != ConnectionGroup.Type.BALANCING) - return Collections.EMPTY_LIST; + return Collections.emptyList(); // If group has no children, there are no balanced connections Collection identifiers = connectionMapper.selectIdentifiersWithin(connectionGroup.getIdentifier()); if (identifiers.isEmpty()) - return Collections.EMPTY_LIST; + return Collections.emptyList(); // Retrieve all children Collection models = connectionMapper.select(identifiers); @@ -453,7 +453,7 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS // Simply return empty list if there are no active tunnels Collection records = activeTunnels.values(); if (records.isEmpty()) - return Collections.EMPTY_LIST; + return Collections.emptyList(); // Build set of all connection identifiers associated with active tunnels Set identifiers = new HashSet(records.size()); @@ -521,7 +521,7 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS // If not a balancing group, assume no connections if (connectionGroup.getType() != ConnectionGroup.Type.BALANCING) - return Collections.EMPTY_LIST; + return Collections.emptyList(); return activeConnectionGroups.get(connectionGroup.getIdentifier()); diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/tunnel/ActiveConnectionMultimap.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/tunnel/ActiveConnectionMultimap.java index 4dd011622..26fff00f8 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/tunnel/ActiveConnectionMultimap.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/tunnel/ActiveConnectionMultimap.java @@ -120,7 +120,7 @@ public class ActiveConnectionMultimap { if (connections != null) return Collections.unmodifiableCollection(connections); - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/pom.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/pom.xml index d82f84794..4e38e1953 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/pom.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/pom.xml @@ -26,9 +26,15 @@ org.apache.maven.plugins maven-compiler-plugin + 3.3 1.6 1.6 + + -Xlint:all + -Werror + + true diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLAuthenticationProvider.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLAuthenticationProvider.java index 664ad7e67..617061bc2 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLAuthenticationProvider.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLAuthenticationProvider.java @@ -37,7 +37,6 @@ import org.glyptodon.guacamole.auth.jdbc.tunnel.UnrestrictedGuacamoleTunnelServi import org.glyptodon.guacamole.auth.jdbc.user.UserContextService; import org.glyptodon.guacamole.environment.Environment; import org.glyptodon.guacamole.environment.LocalEnvironment; -import org.glyptodon.guacamole.properties.GuacamoleProperties; /** * Provides a MySQL based implementation of the AuthenticationProvider diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/pom.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/pom.xml index 250996e0f..2dbdc0acf 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/pom.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/pom.xml @@ -26,9 +26,15 @@ org.apache.maven.plugins maven-compiler-plugin + 3.3 1.6 1.6 + + -Xlint:all + -Werror + + true diff --git a/extensions/guacamole-auth-ldap/pom.xml b/extensions/guacamole-auth-ldap/pom.xml index 88dccb9bf..d217a9adb 100644 --- a/extensions/guacamole-auth-ldap/pom.xml +++ b/extensions/guacamole-auth-ldap/pom.xml @@ -20,9 +20,15 @@ org.apache.maven.plugins maven-compiler-plugin + 3.3 1.6 1.6 + + -Xlint:all + -Werror + + true diff --git a/extensions/guacamole-auth-ldap/src/main/java/net/sourceforge/guacamole/net/auth/ldap/LDAPAuthenticationProvider.java b/extensions/guacamole-auth-ldap/src/main/java/net/sourceforge/guacamole/net/auth/ldap/LDAPAuthenticationProvider.java index db6aa6fc4..db1e92c2e 100644 --- a/extensions/guacamole-auth-ldap/src/main/java/net/sourceforge/guacamole/net/auth/ldap/LDAPAuthenticationProvider.java +++ b/extensions/guacamole-auth-ldap/src/main/java/net/sourceforge/guacamole/net/auth/ldap/LDAPAuthenticationProvider.java @@ -36,8 +36,9 @@ import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.net.auth.Credentials; import net.sourceforge.guacamole.net.auth.ldap.properties.LDAPGuacamoleProperties; 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.properties.GuacamoleProperties; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,6 +57,23 @@ public class LDAPAuthenticationProvider extends SimpleAuthenticationProvider { */ private Logger logger = LoggerFactory.getLogger(LDAPAuthenticationProvider.class); + /** + * Guacamole server environment. + */ + private final Environment environment; + + /** + * Creates a new LDAPAuthenticationProvider that authenticates users + * against an LDAP directory. + * + * @throws GuacamoleException + * If a required property is missing, or an error occurs while parsing + * a property. + */ + public LDAPAuthenticationProvider() throws GuacamoleException { + environment = new LocalEnvironment(); + } + // Courtesy of OWASP: https://www.owasp.org/index.php/Preventing_LDAP_Injection_in_Java private static String escapeLDAPSearchFilter(String filter) { StringBuilder sb = new StringBuilder(); @@ -146,8 +164,8 @@ public class LDAPAuthenticationProvider extends SimpleAuthenticationProvider { ldapConnection = new LDAPConnection(); ldapConnection.connect( - GuacamoleProperties.getRequiredProperty(LDAPGuacamoleProperties.LDAP_HOSTNAME), - GuacamoleProperties.getRequiredProperty(LDAPGuacamoleProperties.LDAP_PORT) + environment.getRequiredProperty(LDAPGuacamoleProperties.LDAP_HOSTNAME), + environment.getRequiredProperty(LDAPGuacamoleProperties.LDAP_PORT) ); } @@ -156,12 +174,12 @@ public class LDAPAuthenticationProvider extends SimpleAuthenticationProvider { } // Get username attribute - String username_attribute = GuacamoleProperties.getRequiredProperty( + String username_attribute = environment.getRequiredProperty( LDAPGuacamoleProperties.LDAP_USERNAME_ATTRIBUTE ); // Get user base DN - String user_base_dn = GuacamoleProperties.getRequiredProperty( + String user_base_dn = environment.getRequiredProperty( LDAPGuacamoleProperties.LDAP_USER_BASE_DN ); @@ -191,7 +209,7 @@ public class LDAPAuthenticationProvider extends SimpleAuthenticationProvider { } // Get config base DN - String config_base_dn = GuacamoleProperties.getRequiredProperty( + String config_base_dn = environment.getRequiredProperty( LDAPGuacamoleProperties.LDAP_CONFIG_BASE_DN ); @@ -234,10 +252,10 @@ public class LDAPAuthenticationProvider extends SimpleAuthenticationProvider { if (parameterAttribute != null) { // For each parameter - Enumeration parameters = parameterAttribute.getStringValues(); + Enumeration parameters = parameterAttribute.getStringValues(); while (parameters.hasMoreElements()) { - String parameter = parameters.nextElement(); + String parameter = (String) parameters.nextElement(); // Parse parameter int equals = parameter.indexOf('='); diff --git a/extensions/guacamole-auth-noauth/pom.xml b/extensions/guacamole-auth-noauth/pom.xml index 2b74646dd..a543ee2da 100644 --- a/extensions/guacamole-auth-noauth/pom.xml +++ b/extensions/guacamole-auth-noauth/pom.xml @@ -20,9 +20,15 @@ org.apache.maven.plugins maven-compiler-plugin + 3.3 1.6 1.6 + + -Xlint:all + -Werror + + true diff --git a/extensions/guacamole-auth-noauth/src/main/java/net/sourceforge/guacamole/net/auth/noauth/NoAuthenticationProvider.java b/extensions/guacamole-auth-noauth/src/main/java/net/sourceforge/guacamole/net/auth/noauth/NoAuthenticationProvider.java index 06cd7e03d..7b0adfafb 100644 --- a/extensions/guacamole-auth-noauth/src/main/java/net/sourceforge/guacamole/net/auth/noauth/NoAuthenticationProvider.java +++ b/extensions/guacamole-auth-noauth/src/main/java/net/sourceforge/guacamole/net/auth/noauth/NoAuthenticationProvider.java @@ -30,10 +30,11 @@ import java.io.IOException; import java.io.Reader; 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.properties.FileGuacamoleProperty; -import org.glyptodon.guacamole.properties.GuacamoleProperties; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; import org.slf4j.LoggerFactory; import org.slf4j.Logger; @@ -86,6 +87,11 @@ public class NoAuthenticationProvider extends SimpleAuthenticationProvider { */ private long configTime; + /** + * Guacamole server environment. + */ + private final Environment environment; + /** * The filename of the XML file to read the user mapping from. */ @@ -98,6 +104,19 @@ public class NoAuthenticationProvider extends SimpleAuthenticationProvider { }; + /** + * Creates a new NoAuthenticationProvider that does not perform any + * authentication at all. All attempts to access the Guacamole system are + * presumed to be authorized. + * + * @throws GuacamoleException + * If a required property is missing, or an error occurs while parsing + * a property. + */ + public NoAuthenticationProvider() throws GuacamoleException { + environment = new LocalEnvironment(); + } + /** * Retrieves the configuration file, as defined within guacamole.properties. * @@ -106,7 +125,7 @@ public class NoAuthenticationProvider extends SimpleAuthenticationProvider { * property. */ private File getConfigurationFile() throws GuacamoleException { - return GuacamoleProperties.getRequiredProperty(NOAUTH_CONFIG); + return environment.getRequiredProperty(NOAUTH_CONFIG); } public synchronized void init() throws GuacamoleException { diff --git a/guacamole-common/pom.xml b/guacamole-common/pom.xml index 2581bfefc..c4de00582 100644 --- a/guacamole-common/pom.xml +++ b/guacamole-common/pom.xml @@ -54,9 +54,15 @@ org.apache.maven.plugins maven-compiler-plugin + 3.3 1.6 1.6 + + -Xlint:all + -Werror + + true diff --git a/guacamole-ext/pom.xml b/guacamole-ext/pom.xml index b50c62173..298207f7a 100644 --- a/guacamole-ext/pom.xml +++ b/guacamole-ext/pom.xml @@ -54,9 +54,15 @@ org.apache.maven.plugins maven-compiler-plugin + 3.3 1.6 1.6 + + -Xlint:all + -Werror + + true diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/CredentialsInfo.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/CredentialsInfo.java index 91a415fba..3bd4afbc8 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/CredentialsInfo.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/credentials/CredentialsInfo.java @@ -65,7 +65,7 @@ public class CredentialsInfo { * CredentialsInfo object which describes empty credentials. No parameters * are required. */ - public static final CredentialsInfo EMPTY = new CredentialsInfo(Collections.EMPTY_LIST); + public static final CredentialsInfo EMPTY = new CredentialsInfo(Collections.emptyList()); /** * CredentialsInfo object which describes standard username/password diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java index a1ae0e3f0..ee3973359 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java @@ -117,7 +117,7 @@ public class SimpleConnection extends AbstractConnection { @Override public List getHistory() throws GuacamoleException { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleDirectory.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleDirectory.java index caee07e2a..cf207785e 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleDirectory.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleDirectory.java @@ -45,7 +45,7 @@ public class SimpleDirectory implements Directory { /** * The Map of objects to provide access to. */ - private Map objects = Collections.EMPTY_MAP; + private Map objects = Collections.emptyMap(); /** * Creates a new empty SimpleDirectory which does not provide access to diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleObjectPermissionSet.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleObjectPermissionSet.java index b265ca5ca..b884263c1 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleObjectPermissionSet.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleObjectPermissionSet.java @@ -42,7 +42,7 @@ public class SimpleObjectPermissionSet implements ObjectPermissionSet { /** * The set of all permissions currently granted. */ - private Set permissions = Collections.EMPTY_SET; + private Set permissions = Collections.emptySet(); /** * Creates a new empty SimpleObjectPermissionSet. diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleSystemPermissionSet.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleSystemPermissionSet.java index bd6a5c2e0..a83a5d17e 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleSystemPermissionSet.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleSystemPermissionSet.java @@ -40,7 +40,7 @@ public class SimpleSystemPermissionSet implements SystemPermissionSet { /** * The set of all permissions currently granted. */ - private Set permissions = Collections.EMPTY_SET; + private Set permissions = Collections.emptySet(); /** * Creates a new empty SimpleSystemPermissionSet. diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java index 4ebc2d6a3..fd558a668 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java @@ -126,7 +126,7 @@ public class SimpleUserContext implements UserContext { // Add root group that contains only the given configurations this.rootGroup = new SimpleConnectionGroup( ROOT_IDENTIFIER, ROOT_IDENTIFIER, - connectionIdentifiers, Collections.EMPTY_LIST + connectionIdentifiers, Collections.emptyList() ); // Build new user from credentials diff --git a/guacamole/pom.xml b/guacamole/pom.xml index e6c736606..3d5847433 100644 --- a/guacamole/pom.xml +++ b/guacamole/pom.xml @@ -54,9 +54,15 @@ org.apache.maven.plugins maven-compiler-plugin + 3.3 1.6 1.6 + + -Xlint:all + -Werror + + true diff --git a/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider.java b/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider.java index 5cedcaa79..6694f5eea 100644 --- a/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider.java +++ b/guacamole/src/main/java/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider.java @@ -29,6 +29,8 @@ import java.io.IOException; import java.io.InputStream; import java.util.Map; import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.environment.Environment; +import org.glyptodon.guacamole.environment.LocalEnvironment; import org.glyptodon.guacamole.net.auth.Credentials; import org.glyptodon.guacamole.net.auth.simple.SimpleAuthenticationProvider; import org.glyptodon.guacamole.net.basic.auth.Authorization; @@ -36,7 +38,6 @@ import org.glyptodon.guacamole.net.basic.auth.UserMapping; import org.glyptodon.guacamole.xml.DocumentHandler; import org.glyptodon.guacamole.net.basic.xml.user_mapping.UserMappingTagHandler; import org.glyptodon.guacamole.properties.FileGuacamoleProperty; -import org.glyptodon.guacamole.properties.GuacamoleProperties; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,6 +70,11 @@ public class BasicFileAuthenticationProvider extends SimpleAuthenticationProvide */ private UserMapping user_mapping; + /** + * Guacamole server environment. + */ + private final Environment environment; + /** * The filename of the XML file to read the user user_mapping from. */ @@ -79,6 +85,18 @@ public class BasicFileAuthenticationProvider extends SimpleAuthenticationProvide }; + /** + * Creates a new BasicFileAuthenticationProvider that authenticates users + * against simple, monolithic XML file. + * + * @throws GuacamoleException + * If a required property is missing, or an error occurs while parsing + * a property. + */ + public BasicFileAuthenticationProvider() throws GuacamoleException { + environment = new LocalEnvironment(); + } + /** * Returns a UserMapping containing all authorization data given within * the XML file specified by the "basic-user-mapping" property in @@ -94,7 +112,7 @@ public class BasicFileAuthenticationProvider extends SimpleAuthenticationProvide // Get user user_mapping file File user_mapping_file = - GuacamoleProperties.getRequiredProperty(BASIC_USER_MAPPING); + environment.getRequiredProperty(BASIC_USER_MAPPING); // If user_mapping not yet read, or user_mapping has been modified, reread if (user_mapping == null || diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/BasicServletContextListener.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/BasicServletContextListener.java index ab028157e..82f3983de 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/BasicServletContextListener.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/BasicServletContextListener.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Glyptodon LLC + * Copyright (C) 2015 Glyptodon LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,35 +24,67 @@ package org.glyptodon.guacamole.net.basic; import com.google.inject.Guice; import com.google.inject.Injector; +import com.google.inject.Stage; import com.google.inject.servlet.GuiceServletContextListener; import javax.servlet.ServletContextEvent; +import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.environment.Environment; +import org.glyptodon.guacamole.environment.LocalEnvironment; import org.glyptodon.guacamole.net.basic.log.LogModule; import org.glyptodon.guacamole.net.basic.rest.RESTAuthModule; -import org.glyptodon.guacamole.net.basic.rest.RESTModule; import org.glyptodon.guacamole.net.basic.rest.RESTServletModule; import org.glyptodon.guacamole.net.basic.rest.auth.BasicTokenSessionMap; import org.glyptodon.guacamole.net.basic.rest.auth.TokenSessionMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A ServletContextListener to listen for initialization of the servlet context * in order to set up dependency injection. - * + * * @author James Muehlner */ public class BasicServletContextListener extends GuiceServletContextListener { + /** + * Logger for this class. + */ + private final Logger logger = LoggerFactory.getLogger(BasicServletContextListener.class); + + /** + * The Guacamole server environment. + */ + private Environment environment; + /** * Singleton instance of a TokenSessionMap. */ - private final TokenSessionMap sessionMap = new BasicTokenSessionMap(); - + private TokenSessionMap sessionMap; + + @Override + public void contextInitialized(ServletContextEvent servletContextEvent) { + + try { + environment = new LocalEnvironment(); + sessionMap = new BasicTokenSessionMap(environment); + } + catch (GuacamoleException e) { + logger.error("Unable to read guacamole.properties: {}", e.getMessage()); + logger.debug("Error reading guacamole.properties.", e); + throw new RuntimeException(e); + } + + super.contextInitialized(servletContextEvent); + + } + @Override protected Injector getInjector() { - return Guice.createInjector( - new LogModule(), - new RESTServletModule(), - new RESTAuthModule(sessionMap), - new RESTModule(), + return Guice.createInjector(Stage.PRODUCTION, + new EnvironmentModule(environment), + new LogModule(environment), + new RESTAuthModule(environment, sessionMap), + new RESTServletModule(), new TunnelModule() ); } @@ -60,11 +92,12 @@ public class BasicServletContextListener extends GuiceServletContextListener { @Override public void contextDestroyed(ServletContextEvent servletContextEvent) { - // Shutdown TokenSessionMap - sessionMap.shutdown(); - super.contextDestroyed(servletContextEvent); - + + // Shutdown TokenSessionMap + if (sessionMap != null) + sessionMap.shutdown(); + } - + } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTModule.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/EnvironmentModule.java similarity index 60% rename from guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTModule.java rename to guacamole/src/main/java/org/glyptodon/guacamole/net/basic/EnvironmentModule.java index 7cdbb71a8..7032d5eb1 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTModule.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/EnvironmentModule.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Glyptodon LLC + * Copyright (C) 2015 Glyptodon LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,24 +20,41 @@ * THE SOFTWARE. */ -package org.glyptodon.guacamole.net.basic.rest; +package org.glyptodon.guacamole.net.basic; import com.google.inject.AbstractModule; +import org.glyptodon.guacamole.environment.Environment; /** - * A Guice Module for setting up dependency injection for the - * Guacamole REST API. - * - * @author James Muehlner + * Guice module which binds the base Guacamole server environment. + * + * @author Michael Jumper */ -public class RESTModule extends AbstractModule { +public class EnvironmentModule extends AbstractModule { + + /** + * The Guacamole server environment. + */ + private final Environment environment; + + /** + * Creates a new EnvironmentModule which will bind the given environment + * for future injection. + * + * @param environment + * The environment to bind. + */ + public EnvironmentModule(Environment environment) { + this.environment = environment; + } @Override protected void configure() { - // Bind generic low-level services - bind(ObjectRetrievalService.class); - + // Bind environment + bind(Environment.class).toInstance(environment); + } - + } + diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/GuacamoleClassLoader.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/GuacamoleClassLoader.java index 218d01396..1dcb37048 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/GuacamoleClassLoader.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/GuacamoleClassLoader.java @@ -33,8 +33,9 @@ import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Collection; import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.environment.Environment; +import org.glyptodon.guacamole.environment.LocalEnvironment; import org.glyptodon.guacamole.net.basic.properties.BasicGuacamoleProperties; -import org.glyptodon.guacamole.properties.GuacamoleProperties; /** * A ClassLoader implementation which finds classes within a configurable @@ -69,9 +70,14 @@ public class GuacamoleClassLoader extends ClassLoader { @Override public GuacamoleClassLoader run() throws GuacamoleException { + + // TODONT: This should be injected, but GuacamoleClassLoader will be removed soon. + Environment environment = new LocalEnvironment(); + return new GuacamoleClassLoader( - GuacamoleProperties.getProperty(BasicGuacamoleProperties.LIB_DIRECTORY) + environment.getProperty(BasicGuacamoleProperties.LIB_DIRECTORY) ); + } }); diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/GuacamoleSession.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/GuacamoleSession.java index 563203fd7..ed2223436 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/GuacamoleSession.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/GuacamoleSession.java @@ -29,11 +29,11 @@ import java.util.Collections; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.environment.Environment; import org.glyptodon.guacamole.net.GuacamoleTunnel; import org.glyptodon.guacamole.net.auth.Credentials; import org.glyptodon.guacamole.net.auth.UserContext; import org.glyptodon.guacamole.net.basic.properties.BasicGuacamoleProperties; -import org.glyptodon.guacamole.properties.GuacamoleProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -83,12 +83,21 @@ public class GuacamoleSession { /** * Creates a new Guacamole session associated with the given user context. * - * @param credentials The credentials provided by the user during login. - * @param userContext The user context to associate this session with. - * @throws GuacamoleException If an error prevents the session from being - * created. + * @param environment + * The environment of the Guacamole server associated with this new + * session. + * + * @param credentials + * The credentials provided by the user during login. + * + * @param userContext + * The user context to associate this session with. + * + * @throws GuacamoleException + * If an error prevents the session from being created. */ - public GuacamoleSession(Credentials credentials, UserContext userContext) throws GuacamoleException { + public GuacamoleSession(Environment environment, Credentials credentials, + UserContext userContext) throws GuacamoleException { this.lastAccessedTime = System.currentTimeMillis(); this.credentials = credentials; @@ -99,11 +108,11 @@ public class GuacamoleSession { // Get all listener classes from properties Collection listenerClasses = - GuacamoleProperties.getProperty(BasicGuacamoleProperties.EVENT_LISTENERS); + environment.getProperty(BasicGuacamoleProperties.EVENT_LISTENERS); // Add an instance of each class to the list if (listenerClasses != null) { - for (Class listenerClass : listenerClasses) { + for (Class listenerClass : listenerClasses) { // Instantiate listener Object listener = listenerClass.getConstructor().newInstance(); diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/TunnelModule.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/TunnelModule.java index afce169b5..4df334947 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/TunnelModule.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/TunnelModule.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Glyptodon LLC + * Copyright (C) 2015 Glyptodon LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory; /** * Module which loads tunnel implementations. - * + * * @author Michael Jumper */ public class TunnelModule extends ServletModule { @@ -54,12 +54,11 @@ public class TunnelModule extends ServletModule { try { - // Attempt to find WebSocket module - Class module = (Class) - GuacamoleClassLoader.getInstance().findClass(classname); + // Attempt to find WebSocket module + Class module = (Class) GuacamoleClassLoader.getInstance().findClass(classname); // Create loader - TunnelLoader loader = module.getConstructor().newInstance(); + TunnelLoader loader = (TunnelLoader) module.getConstructor().newInstance(); // Install module, if supported if (loader.isSupported()) { @@ -119,4 +118,3 @@ public class TunnelModule extends ServletModule { } } - diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/TunnelRequestService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/TunnelRequestService.java index 43ec2d395..3f312160a 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/TunnelRequestService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/TunnelRequestService.java @@ -29,6 +29,7 @@ import java.util.List; import org.glyptodon.guacamole.GuacamoleClientException; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleSecurityException; +import org.glyptodon.guacamole.environment.Environment; import org.glyptodon.guacamole.io.GuacamoleReader; import org.glyptodon.guacamole.net.DelegatingGuacamoleTunnel; import org.glyptodon.guacamole.net.GuacamoleTunnel; @@ -41,7 +42,6 @@ import org.glyptodon.guacamole.net.event.TunnelCloseEvent; import org.glyptodon.guacamole.net.event.TunnelConnectEvent; import org.glyptodon.guacamole.net.event.listener.TunnelCloseListener; import org.glyptodon.guacamole.net.event.listener.TunnelConnectListener; -import org.glyptodon.guacamole.properties.GuacamoleProperties; import org.glyptodon.guacamole.protocol.GuacamoleClientInformation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,6 +59,12 @@ import org.slf4j.LoggerFactory; @Singleton public class TunnelRequestService { + /** + * The Guacamole server environment. + */ + @Inject + private Environment environment; + /** * Logger for this class. */ @@ -309,7 +315,7 @@ public class TunnelRequestService { // Monitor instructions which pertain to server-side events, if necessary try { - if (GuacamoleProperties.getProperty(ClipboardRESTService.INTEGRATION_ENABLED, false)) { + if (environment.getProperty(ClipboardRESTService.INTEGRATION_ENABLED, false)) { ClipboardState clipboard = session.getClipboardState(); return new MonitoringGuacamoleReader(clipboard, super.acquireReader()); diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/log/LogModule.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/log/LogModule.java index a5ba1a039..94589b807 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/log/LogModule.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/log/LogModule.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Glyptodon LLC + * Copyright (C) 2015 Glyptodon LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,7 +28,7 @@ import ch.qos.logback.core.joran.spi.JoranException; import ch.qos.logback.core.util.StatusPrinter; import com.google.inject.AbstractModule; import java.io.File; -import org.glyptodon.guacamole.properties.GuacamoleHome; +import org.glyptodon.guacamole.environment.Environment; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,11 +44,27 @@ public class LogModule extends AbstractModule { */ private final Logger logger = LoggerFactory.getLogger(LogModule.class); + /** + * The Guacamole server environment. + */ + private final Environment environment; + + /** + * Creates a new LogModule which uses the given environment to determine + * the logging configuration. + * + * @param environment + * The environment to use when configuring logging. + */ + public LogModule(Environment environment) { + this.environment = environment; + } + @Override protected void configure() { // Only load logback configuration if GUACAMOLE_HOME exists - File guacamoleHome = GuacamoleHome.getDirectory(); + File guacamoleHome = environment.getGuacamoleHome(); if (!guacamoleHome.isDirectory()) return; @@ -58,7 +74,7 @@ public class LogModule extends AbstractModule { return; logger.info("Loading logback configuration from \"{}\".", logbackConfiguration); - + LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); context.reset(); @@ -77,8 +93,7 @@ public class LogModule extends AbstractModule { logger.error("Initialization of logback failed: {}", e.getMessage()); logger.debug("Unable to load logback configuration..", e); } - + } } - diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTAuthModule.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTAuthModule.java index 456c883d2..d79746ad3 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTAuthModule.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTAuthModule.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Glyptodon LLC + * Copyright (C) 2015 Glyptodon LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,21 +23,20 @@ package org.glyptodon.guacamole.net.basic.rest; import com.google.inject.AbstractModule; -import com.google.inject.matcher.Matchers; import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.environment.Environment; import org.glyptodon.guacamole.net.auth.AuthenticationProvider; import org.glyptodon.guacamole.net.basic.properties.BasicGuacamoleProperties; import org.glyptodon.guacamole.net.basic.rest.auth.AuthTokenGenerator; import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService; import org.glyptodon.guacamole.net.basic.rest.auth.SecureRandomAuthTokenGenerator; import org.glyptodon.guacamole.net.basic.rest.auth.TokenSessionMap; -import org.glyptodon.guacamole.properties.GuacamoleProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A Guice Module for setting up authentication-specific dependency injection. - * + * * @author James Muehlner * @author Michael Jumper */ @@ -46,35 +45,48 @@ public class RESTAuthModule extends AbstractModule { /** * Logger for this class. */ - private static final Logger logger = LoggerFactory.getLogger(RESTAuthModule.class); + private final Logger logger = LoggerFactory.getLogger(RESTAuthModule.class); /** - * The AuthenticationProvider to use to authenticate all requests. + * The Guacamole server environment. */ - private AuthenticationProvider authProvider; + private final Environment environment; /** - * Singleton instance of a TokenSessionMap. + * Singleton instance of TokenSessionMap. */ - private final TokenSessionMap sessionMap; + private final TokenSessionMap tokenSessionMap; /** * Creates a module which handles binding of authentication-related * objects, including the singleton TokenSessionMap. - * - * @param sessionMap An instance of TokenSessionMap to inject as a singleton - * wherever needed. + * + * @param environment + * The environment to use when configuring authentication. + * + * @param tokenSessionMap + * An instance of TokenSessionMap to inject as a singleton wherever + * needed. */ - public RESTAuthModule(TokenSessionMap sessionMap) { - this.sessionMap = sessionMap; + public RESTAuthModule(Environment environment, + TokenSessionMap tokenSessionMap) { + this.environment = environment; + this.tokenSessionMap = tokenSessionMap; } - + @Override protected void configure() { + // Bind session map + bind(TokenSessionMap.class).toInstance(tokenSessionMap); + + // Bind low-level services + bind(AuthenticationService.class); + bind(AuthTokenGenerator.class).to(SecureRandomAuthTokenGenerator.class); + // Get and bind auth provider instance try { - authProvider = GuacamoleProperties.getRequiredProperty(BasicGuacamoleProperties.AUTH_PROVIDER); + AuthenticationProvider authProvider = environment.getRequiredProperty(BasicGuacamoleProperties.AUTH_PROVIDER); bind(AuthenticationProvider.class).toInstance(authProvider); } catch (GuacamoleException e) { @@ -83,15 +95,6 @@ public class RESTAuthModule extends AbstractModule { throw new RuntimeException(e); } - // Bind singleton TokenSessionMap - bind(TokenSessionMap.class).toInstance(sessionMap); - - bind(AuthenticationService.class); - bind(AuthTokenGenerator.class).to(SecureRandomAuthTokenGenerator.class); - - // Bind @AuthProviderRESTExposure annotation - bindInterceptor(Matchers.any(), Matchers.annotatedWith(AuthProviderRESTExposure.class), new AuthProviderRESTExceptionWrapper()); - } - + } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletModule.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletModule.java index e87ac7e54..a6e54c7a6 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletModule.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletModule.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Glyptodon LLC + * Copyright (C) 2015 Glyptodon LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,6 +23,7 @@ package org.glyptodon.guacamole.net.basic.rest; import com.google.inject.Scopes; +import com.google.inject.matcher.Matchers; import com.google.inject.servlet.ServletModule; import com.sun.jersey.guice.spi.container.servlet.GuiceContainer; import org.codehaus.jackson.jaxrs.JacksonJsonProvider; @@ -37,14 +38,24 @@ import org.glyptodon.guacamole.net.basic.rest.user.UserRESTService; /** * A Guice Module to set up the servlet mappings for the Guacamole REST API. - * + * * @author James Muehlner */ public class RESTServletModule extends ServletModule { - + @Override protected void configureServlets() { - + + // Bind @AuthProviderRESTExposure annotation + bindInterceptor( + Matchers.any(), + Matchers.annotatedWith(AuthProviderRESTExposure.class), + new AuthProviderRESTExceptionWrapper() + ); + + // Bind convenience services used by the REST API + bind(ObjectRetrievalService.class); + // Set up the API endpoints bind(ActiveConnectionRESTService.class); bind(ClipboardRESTService.class); @@ -54,12 +65,12 @@ public class RESTServletModule extends ServletModule { bind(ProtocolRESTService.class); bind(TokenRESTService.class); bind(UserRESTService.class); - + // Set up the servlet and JSON mappings bind(GuiceContainer.class); bind(JacksonJsonProvider.class).in(Scopes.SINGLETON); serve("/api/*").with(GuiceContainer.class); } - + } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/auth/BasicTokenSessionMap.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/auth/BasicTokenSessionMap.java index 98530c6c5..bbeaa43db 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/auth/BasicTokenSessionMap.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/auth/BasicTokenSessionMap.java @@ -22,7 +22,6 @@ package org.glyptodon.guacamole.net.basic.rest.auth; -import com.google.inject.Singleton; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; @@ -31,9 +30,9 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.environment.Environment; import org.glyptodon.guacamole.net.basic.GuacamoleSession; import org.glyptodon.guacamole.net.basic.properties.BasicGuacamoleProperties; -import org.glyptodon.guacamole.properties.GuacamoleProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,7 +42,6 @@ import org.slf4j.LoggerFactory; * * @author James Muehlner */ -@Singleton public class BasicTokenSessionMap implements TokenSessionMap { /** @@ -63,15 +61,19 @@ public class BasicTokenSessionMap implements TokenSessionMap { Collections.synchronizedMap(new LinkedHashMap(16, 0.75f, true)); /** - * Create a new BasicTokenGuacamoleSessionMap and initialize the session timeout value. + * Create a new BasicTokenGuacamoleSessionMap configured using the given + * environment. + * + * @param environment + * The environment to use when configuring the token session map. */ - public BasicTokenSessionMap() { + public BasicTokenSessionMap(Environment environment) { int sessionTimeoutValue; // Read session timeout from guacamole.properties try { - sessionTimeoutValue = GuacamoleProperties.getProperty(BasicGuacamoleProperties.API_SESSION_TIMEOUT, 60); + sessionTimeoutValue = environment.getProperty(BasicGuacamoleProperties.API_SESSION_TIMEOUT, 60); } catch (GuacamoleException e) { logger.error("Unable to read guacamole.properties: {}", e.getMessage()); diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/auth/TokenRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/auth/TokenRESTService.java index 3951c59e4..5b87456ce 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/auth/TokenRESTService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/auth/TokenRESTService.java @@ -37,6 +37,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.xml.bind.DatatypeConverter; import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.environment.Environment; import org.glyptodon.guacamole.net.auth.AuthenticationProvider; import org.glyptodon.guacamole.net.auth.Credentials; import org.glyptodon.guacamole.net.auth.UserContext; @@ -58,6 +59,12 @@ import org.slf4j.LoggerFactory; @Path("/tokens") @Produces(MediaType.APPLICATION_JSON) public class TokenRESTService { + + /** + * The Guacamole server environment. + */ + @Inject + private Environment environment; /** * The authentication provider used to authenticate this user. @@ -269,7 +276,7 @@ public class TokenRESTService { // If no existing session, generate a new token/session pair else { authToken = authTokenGenerator.getToken(); - tokenSessionMap.put(authToken, new GuacamoleSession(credentials, userContext)); + tokenSessionMap.put(authToken, new GuacamoleSession(environment, credentials, userContext)); } logger.debug("Login was successful for user \"{}\".", userContext.self().getIdentifier()); diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/clipboard/ClipboardRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/clipboard/ClipboardRESTService.java index 972895cc4..6d60d238e 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/clipboard/ClipboardRESTService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/clipboard/ClipboardRESTService.java @@ -29,12 +29,12 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleUnsupportedException; +import org.glyptodon.guacamole.environment.Environment; import org.glyptodon.guacamole.net.basic.ClipboardState; import org.glyptodon.guacamole.net.basic.GuacamoleSession; import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure; import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService; import org.glyptodon.guacamole.properties.BooleanGuacamoleProperty; -import org.glyptodon.guacamole.properties.GuacamoleProperties; /** * A REST service for reading the current contents of the clipboard. @@ -44,6 +44,12 @@ import org.glyptodon.guacamole.properties.GuacamoleProperties; @Path("/clipboard") public class ClipboardRESTService { + /** + * The Guacamole server environment. + */ + @Inject + private Environment environment; + /** * A service for authenticating users from auth tokens. */ @@ -71,7 +77,7 @@ public class ClipboardRESTService { throws GuacamoleException { // Only bother if actually enabled - if (GuacamoleProperties.getProperty(INTEGRATION_ENABLED, false)) { + if (environment.getProperty(INTEGRATION_ENABLED, false)) { // Get clipboard GuacamoleSession session = authenticationService.getGuacamoleSession(authToken); diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnectionWrapper.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnectionWrapper.java index bbfb6916c..41d64ceb3 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnectionWrapper.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnectionWrapper.java @@ -122,7 +122,7 @@ public class APIConnectionWrapper implements Connection { @Override public List getHistory() throws GuacamoleException { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/language/LanguageRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/language/LanguageRESTService.java index 8c1131bb8..80917a395 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/language/LanguageRESTService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/language/LanguageRESTService.java @@ -79,7 +79,7 @@ public class LanguageRESTService { * filename. */ private static final Pattern LANGUAGE_KEY_PATTERN = Pattern.compile(".*/([a-z]+_[A-Z]+)\\.json"); - + /** * Returns a map of all available language keys to their corresponding * human-readable names. @@ -104,16 +104,19 @@ public class LanguageRESTService { @Context ServletContext servletContext) throws GuacamoleException { // Get the paths of all the translation files - Set resourcePaths = servletContext.getResourcePaths(TRANSLATION_PATH); + Set resourcePaths = servletContext.getResourcePaths(TRANSLATION_PATH); // If no translation files found, return an empty map if (resourcePaths == null) - return Collections.EMPTY_MAP; + return Collections.emptyMap(); Map languageMap = new HashMap(); // Iterate through all the found language files and add them to the return map - for (String resourcePath : resourcePaths) { + for (Object resourcePathObject : resourcePaths) { + + // Each resource path is guaranteed to be a string + String resourcePath = (String) resourcePathObject; // Get input stream for language file InputStream languageFileStream = servletContext.getResourceAsStream(resourcePath);