mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 00:53:21 +00:00 
			
		
		
		
	GUAC-1170: Remove use of deprecated GuacamoleProperties.
This commit is contained in:
		| @@ -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 || | ||||
|   | ||||
| @@ -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) | ||||
|                     ); | ||||
|  | ||||
|                 } | ||||
|  | ||||
|             }); | ||||
|   | ||||
| @@ -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,7 +108,7 @@ 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) { | ||||
|   | ||||
| @@ -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()); | ||||
|   | ||||
| @@ -25,13 +25,14 @@ 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.environment.LocalEnvironment; | ||||
| 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; | ||||
|  | ||||
| @@ -48,6 +49,11 @@ public class RESTAuthModule extends AbstractModule { | ||||
|      */ | ||||
|     private static final Logger logger = LoggerFactory.getLogger(RESTAuthModule.class); | ||||
|  | ||||
|     /** | ||||
|      * The Guacamole server environment. | ||||
|      */ | ||||
|     private Environment environment; | ||||
|      | ||||
|     /** | ||||
|      * The AuthenticationProvider to use to authenticate all requests. | ||||
|      */ | ||||
| @@ -72,10 +78,16 @@ public class RESTAuthModule extends AbstractModule { | ||||
|     @Override | ||||
|     protected void configure() { | ||||
|  | ||||
|         // Get and bind auth provider instance | ||||
|         try { | ||||
|             authProvider = GuacamoleProperties.getRequiredProperty(BasicGuacamoleProperties.AUTH_PROVIDER); | ||||
|  | ||||
|             // Bind environment | ||||
|             environment = new LocalEnvironment(); | ||||
|             bind(Environment.class).toInstance(environment); | ||||
|  | ||||
|             // Get and bind auth provider instance | ||||
|             authProvider = environment.getRequiredProperty(BasicGuacamoleProperties.AUTH_PROVIDER); | ||||
|             bind(AuthenticationProvider.class).toInstance(authProvider); | ||||
|  | ||||
|         } | ||||
|         catch (GuacamoleException e) { | ||||
|             logger.error("Unable to read authentication provider from guacamole.properties: {}", e.getMessage()); | ||||
|   | ||||
| @@ -37,7 +37,7 @@ public class RESTModule extends AbstractModule { | ||||
|  | ||||
|         // Bind generic low-level services | ||||
|         bind(ObjectRetrievalService.class); | ||||
|          | ||||
|  | ||||
|     } | ||||
|      | ||||
| } | ||||
|   | ||||
| @@ -22,6 +22,7 @@ | ||||
|  | ||||
| package org.glyptodon.guacamole.net.basic.rest.auth; | ||||
|  | ||||
| import com.google.inject.Inject; | ||||
| import com.google.inject.Singleton; | ||||
| import java.util.Collections; | ||||
| import java.util.Iterator; | ||||
| @@ -31,9 +32,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; | ||||
|  | ||||
| @@ -46,6 +47,12 @@ import org.slf4j.LoggerFactory; | ||||
| @Singleton | ||||
| public class BasicTokenSessionMap implements TokenSessionMap { | ||||
|  | ||||
|     /** | ||||
|      * The Guacamole server environment. | ||||
|      */ | ||||
|     @Inject | ||||
|     private Environment environment; | ||||
|      | ||||
|     /** | ||||
|      * Logger for this class. | ||||
|      */ | ||||
| @@ -71,7 +78,7 @@ public class BasicTokenSessionMap implements TokenSessionMap { | ||||
|  | ||||
|         // 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()); | ||||
|   | ||||
| @@ -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()); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user