Merge pull request #165 from glyptodon/build-warnings

GUAC-1170: Fix Java compiler warnings.
This commit is contained in:
James Muehlner
2015-04-26 21:43:57 -07:00
40 changed files with 351 additions and 126 deletions

View File

@@ -20,9 +20,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Werror</arg>
</compilerArgs>
<fork>true</fork>
</configuration>
</plugin>

View File

@@ -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);

View File

@@ -26,9 +26,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Werror</arg>
</compilerArgs>
<fork>true</fork>
</configuration>
</plugin>

View File

@@ -316,7 +316,7 @@ public abstract class ModeledDirectoryObjectService<InternalType extends Modeled
// Do not query if no identifiers given
if (identifiers.isEmpty())
return Collections.EMPTY_LIST;
return Collections.<InternalType>emptyList();
Collection<ModelType> objects;

View File

@@ -96,7 +96,7 @@ public abstract class ModeledGroupedDirectoryObjectService<InternalType extends
// If both parents have the same identifier, nothing has changed
if (parentIdentifier != null && parentIdentifier.equals(oldParentIdentifier))
return Collections.EMPTY_LIST;
return Collections.<String>emptyList();
}

View File

@@ -204,7 +204,7 @@ public class ConnectionService extends ModeledGroupedDirectoryObjectService<Mode
Map<String, String> parameters = connection.getConfiguration().getParameters();
// Convert parameters to model objects
Collection<ParameterModel> parameterModels = new ArrayList(parameters.size());
Collection<ParameterModel> parameterModels = new ArrayList<ParameterModel>(parameters.size());
for (Map.Entry<String, String> parameterEntry : parameters.entrySet()) {
// Get parameter name and value

View File

@@ -106,7 +106,7 @@ public abstract class ModeledObjectPermissionService
return false;
// Produce collection of affected identifiers
Collection<String> affectedIdentifiers = new HashSet(permissions.size());
Collection<String> affectedIdentifiers = new HashSet<String>(permissions.size());
for (ObjectPermission permission : permissions)
affectedIdentifiers.add(permission.getObjectIdentifier());

View File

@@ -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.<ModeledConnection>emptyList();
// If group has no children, there are no balanced connections
Collection<String> identifiers = connectionMapper.selectIdentifiersWithin(connectionGroup.getIdentifier());
if (identifiers.isEmpty())
return Collections.EMPTY_LIST;
return Collections.<ModeledConnection>emptyList();
// Retrieve all children
Collection<ConnectionModel> 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<ActiveConnectionRecord> records = activeTunnels.values();
if (records.isEmpty())
return Collections.EMPTY_LIST;
return Collections.<ActiveConnectionRecord>emptyList();
// Build set of all connection identifiers associated with active tunnels
Set<String> identifiers = new HashSet<String>(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.<ActiveConnectionRecord>emptyList();
return activeConnectionGroups.get(connectionGroup.getIdentifier());

View File

@@ -120,7 +120,7 @@ public class ActiveConnectionMultimap {
if (connections != null)
return Collections.unmodifiableCollection(connections);
return Collections.EMPTY_LIST;
return Collections.<ActiveConnectionRecord>emptyList();
}
}

View File

@@ -26,9 +26,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Werror</arg>
</compilerArgs>
<fork>true</fork>
</configuration>
</plugin>

View File

@@ -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

View File

@@ -26,9 +26,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Werror</arg>
</compilerArgs>
<fork>true</fork>
</configuration>
</plugin>

View File

@@ -20,9 +20,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Werror</arg>
</compilerArgs>
<fork>true</fork>
</configuration>
</plugin>

View File

@@ -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<String> 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('=');

View File

@@ -20,9 +20,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Werror</arg>
</compilerArgs>
<fork>true</fork>
</configuration>
</plugin>

View File

@@ -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 {

View File

@@ -54,9 +54,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Werror</arg>
</compilerArgs>
<fork>true</fork>
</configuration>
</plugin>

View File

@@ -54,9 +54,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Werror</arg>
</compilerArgs>
<fork>true</fork>
</configuration>
</plugin>

View File

@@ -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.<Parameter>emptyList());
/**
* CredentialsInfo object which describes standard username/password

View File

@@ -117,7 +117,7 @@ public class SimpleConnection extends AbstractConnection {
@Override
public List<ConnectionRecord> getHistory() throws GuacamoleException {
return Collections.EMPTY_LIST;
return Collections.<ConnectionRecord>emptyList();
}
}

View File

@@ -45,7 +45,7 @@ public class SimpleDirectory<ObjectType> implements Directory<ObjectType> {
/**
* The Map of objects to provide access to.
*/
private Map<String, ObjectType> objects = Collections.EMPTY_MAP;
private Map<String, ObjectType> objects = Collections.<String, ObjectType>emptyMap();
/**
* Creates a new empty SimpleDirectory which does not provide access to

View File

@@ -42,7 +42,7 @@ public class SimpleObjectPermissionSet implements ObjectPermissionSet {
/**
* The set of all permissions currently granted.
*/
private Set<ObjectPermission> permissions = Collections.EMPTY_SET;
private Set<ObjectPermission> permissions = Collections.<ObjectPermission>emptySet();
/**
* Creates a new empty SimpleObjectPermissionSet.

View File

@@ -40,7 +40,7 @@ public class SimpleSystemPermissionSet implements SystemPermissionSet {
/**
* The set of all permissions currently granted.
*/
private Set<SystemPermission> permissions = Collections.EMPTY_SET;
private Set<SystemPermission> permissions = Collections.<SystemPermission>emptySet();
/**
* Creates a new empty SimpleSystemPermissionSet.

View File

@@ -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.<String>emptyList()
);
// Build new user from credentials

View File

@@ -54,9 +54,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Werror</arg>
</compilerArgs>
<fork>true</fork>
</configuration>
</plugin>

View File

@@ -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 ||

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -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)
);
}
});

View File

@@ -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<Class> 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();

View File

@@ -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<TunnelLoader> module = (Class<TunnelLoader>)
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 {
}
}

View File

@@ -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());

View File

@@ -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);
}
}
}

View File

@@ -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());
}
}

View File

@@ -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);
}
}

View File

@@ -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<String, GuacamoleSession>(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());

View File

@@ -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());

View File

@@ -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);

View File

@@ -122,7 +122,7 @@ public class APIConnectionWrapper implements Connection {
@Override
public List<? extends ConnectionRecord> getHistory() throws GuacamoleException {
return Collections.EMPTY_LIST;
return Collections.<ConnectionRecord>emptyList();
}
}

View File

@@ -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<String> 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.<String, String>emptyMap();
Map<String, String> languageMap = new HashMap<String, String>();
// 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);