mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-5: Add ActiveConnection subresource to the tunnel REST resource.
This commit is contained in:
@@ -40,6 +40,8 @@ import org.apache.guacamole.rest.language.LanguageRESTService;
|
|||||||
import org.apache.guacamole.rest.patch.PatchRESTService;
|
import org.apache.guacamole.rest.patch.PatchRESTService;
|
||||||
import org.apache.guacamole.rest.session.SessionResourceFactory;
|
import org.apache.guacamole.rest.session.SessionResourceFactory;
|
||||||
import org.apache.guacamole.rest.sharingprofile.SharingProfileModule;
|
import org.apache.guacamole.rest.sharingprofile.SharingProfileModule;
|
||||||
|
import org.apache.guacamole.rest.tunnel.TunnelCollectionResourceFactory;
|
||||||
|
import org.apache.guacamole.rest.tunnel.TunnelResourceFactory;
|
||||||
import org.apache.guacamole.rest.user.UserModule;
|
import org.apache.guacamole.rest.user.UserModule;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,6 +93,8 @@ public class RESTServiceModule extends ServletModule {
|
|||||||
// Root-level resources
|
// Root-level resources
|
||||||
bind(SessionRESTService.class);
|
bind(SessionRESTService.class);
|
||||||
install(new FactoryModuleBuilder().build(SessionResourceFactory.class));
|
install(new FactoryModuleBuilder().build(SessionResourceFactory.class));
|
||||||
|
install(new FactoryModuleBuilder().build(TunnelCollectionResourceFactory.class));
|
||||||
|
install(new FactoryModuleBuilder().build(TunnelResourceFactory.class));
|
||||||
install(new FactoryModuleBuilder().build(UserContextResourceFactory.class));
|
install(new FactoryModuleBuilder().build(UserContextResourceFactory.class));
|
||||||
|
|
||||||
// Resources below root
|
// Resources below root
|
||||||
|
@@ -31,6 +31,7 @@ import org.apache.guacamole.GuacamoleException;
|
|||||||
import org.apache.guacamole.GuacamoleSession;
|
import org.apache.guacamole.GuacamoleSession;
|
||||||
import org.apache.guacamole.net.auth.UserContext;
|
import org.apache.guacamole.net.auth.UserContext;
|
||||||
import org.apache.guacamole.rest.tunnel.TunnelCollectionResource;
|
import org.apache.guacamole.rest.tunnel.TunnelCollectionResource;
|
||||||
|
import org.apache.guacamole.rest.tunnel.TunnelCollectionResourceFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A REST resource which exposes all data associated with a Guacamole user's
|
* A REST resource which exposes all data associated with a Guacamole user's
|
||||||
@@ -54,6 +55,13 @@ public class SessionResource {
|
|||||||
@Inject
|
@Inject
|
||||||
private UserContextResourceFactory userContextResourceFactory;
|
private UserContextResourceFactory userContextResourceFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for creating instances of resources which represent the
|
||||||
|
* collection of tunnels within a GuacamoleSession.
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
private TunnelCollectionResourceFactory tunnelCollectionResourceFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new SessionResource which exposes the data within the given
|
* Creates a new SessionResource which exposes the data within the given
|
||||||
* GuacamoleSession.
|
* GuacamoleSession.
|
||||||
@@ -105,7 +113,7 @@ public class SessionResource {
|
|||||||
*/
|
*/
|
||||||
@Path("tunnels")
|
@Path("tunnels")
|
||||||
public TunnelCollectionResource getTunnelCollectionResource() {
|
public TunnelCollectionResource getTunnelCollectionResource() {
|
||||||
return new TunnelCollectionResource(session);
|
return tunnelCollectionResourceFactory.create(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
package org.apache.guacamole.rest.tunnel;
|
package org.apache.guacamole.rest.tunnel;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
import com.google.inject.assistedinject.AssistedInject;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
@@ -46,6 +49,12 @@ public class TunnelCollectionResource {
|
|||||||
*/
|
*/
|
||||||
private final GuacamoleSession session;
|
private final GuacamoleSession session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for creating instances of resources which represent tunnels.
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
private TunnelResourceFactory tunnelResourceFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new TunnelCollectionResource which exposes the active tunnels
|
* Creates a new TunnelCollectionResource which exposes the active tunnels
|
||||||
* of the given GuacamoleSession.
|
* of the given GuacamoleSession.
|
||||||
@@ -54,7 +63,8 @@ public class TunnelCollectionResource {
|
|||||||
* The GuacamoleSession whose tunnels should be exposed by this
|
* The GuacamoleSession whose tunnels should be exposed by this
|
||||||
* resource.
|
* resource.
|
||||||
*/
|
*/
|
||||||
public TunnelCollectionResource(GuacamoleSession session) {
|
@AssistedInject
|
||||||
|
public TunnelCollectionResource(@Assisted GuacamoleSession session) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +107,7 @@ public class TunnelCollectionResource {
|
|||||||
throw new GuacamoleResourceNotFoundException("No such tunnel.");
|
throw new GuacamoleResourceNotFoundException("No such tunnel.");
|
||||||
|
|
||||||
// Return corresponding tunnel resource
|
// Return corresponding tunnel resource
|
||||||
return new TunnelResource(tunnel);
|
return tunnelResourceFactory.create(tunnel);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.guacamole.rest.tunnel;
|
||||||
|
|
||||||
|
import org.apache.guacamole.GuacamoleSession;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory which creates resources that expose the collection of tunnels
|
||||||
|
* contained within a given GuacamoleSession.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public interface TunnelCollectionResourceFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new TunnelCollectionResource which exposes the collection of
|
||||||
|
* tunnels stored within the given GuacamoleSession.
|
||||||
|
*
|
||||||
|
* @param session
|
||||||
|
* The GuacamoleSession whose collection of tunnels should be exposed.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* A new TunnelCollectionResource which exposes the collection of
|
||||||
|
* tunnels stored within the given GuacamoleSession.
|
||||||
|
*/
|
||||||
|
TunnelCollectionResource create(GuacamoleSession session);
|
||||||
|
|
||||||
|
}
|
@@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
package org.apache.guacamole.rest.tunnel;
|
package org.apache.guacamole.rest.tunnel;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
import com.google.inject.assistedinject.AssistedInject;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DefaultValue;
|
import javax.ws.rs.DefaultValue;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
@@ -27,6 +30,11 @@ import javax.ws.rs.Produces;
|
|||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import org.apache.guacamole.GuacamoleException;
|
import org.apache.guacamole.GuacamoleException;
|
||||||
|
import org.apache.guacamole.net.auth.ActiveConnection;
|
||||||
|
import org.apache.guacamole.net.auth.UserContext;
|
||||||
|
import org.apache.guacamole.rest.activeconnection.APIActiveConnection;
|
||||||
|
import org.apache.guacamole.rest.directory.DirectoryObjectResource;
|
||||||
|
import org.apache.guacamole.rest.directory.DirectoryObjectResourceFactory;
|
||||||
import org.apache.guacamole.tunnel.UserTunnel;
|
import org.apache.guacamole.tunnel.UserTunnel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,6 +58,14 @@ public class TunnelResource {
|
|||||||
*/
|
*/
|
||||||
private final UserTunnel tunnel;
|
private final UserTunnel tunnel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A factory which can be used to create instances of resources representing
|
||||||
|
* ActiveConnections.
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
private DirectoryObjectResourceFactory<ActiveConnection, APIActiveConnection>
|
||||||
|
activeConnectionResourceFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new TunnelResource which exposes the operations and
|
* Creates a new TunnelResource which exposes the operations and
|
||||||
* subresources available for the given tunnel.
|
* subresources available for the given tunnel.
|
||||||
@@ -57,10 +73,36 @@ public class TunnelResource {
|
|||||||
* @param tunnel
|
* @param tunnel
|
||||||
* The tunnel that this TunnelResource should represent.
|
* The tunnel that this TunnelResource should represent.
|
||||||
*/
|
*/
|
||||||
public TunnelResource(UserTunnel tunnel) {
|
@AssistedInject
|
||||||
|
public TunnelResource(@Assisted UserTunnel tunnel) {
|
||||||
this.tunnel = tunnel;
|
this.tunnel = tunnel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a resource representing the ActiveConnection object associated
|
||||||
|
* with this tunnel.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* A resource representing the ActiveConnection object associated with
|
||||||
|
* this tunnel.
|
||||||
|
*
|
||||||
|
* @throws GuacamoleException
|
||||||
|
* If an error occurs while retrieving the ActiveConnection.
|
||||||
|
*/
|
||||||
|
@Path("activeConnection")
|
||||||
|
public DirectoryObjectResource<ActiveConnection, APIActiveConnection>
|
||||||
|
getActiveConnection() throws GuacamoleException {
|
||||||
|
|
||||||
|
// Pull the UserContext from the tunnel
|
||||||
|
UserContext userContext = tunnel.getUserContext();
|
||||||
|
|
||||||
|
// Return the associated ActiveConnection as a resource
|
||||||
|
return activeConnectionResourceFactory.create(userContext,
|
||||||
|
userContext.getActiveConnectionDirectory(),
|
||||||
|
tunnel.getActiveConnection());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Intercepts and returns the entire contents of a specific stream.
|
* Intercepts and returns the entire contents of a specific stream.
|
||||||
*
|
*
|
||||||
|
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.guacamole.rest.tunnel;
|
||||||
|
|
||||||
|
import org.apache.guacamole.tunnel.UserTunnel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory which creates resources that expose the contents of a given
|
||||||
|
* tunnel.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public interface TunnelResourceFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new TunnelResource which exposes the contents of the
|
||||||
|
* given tunnel.
|
||||||
|
*
|
||||||
|
* @param tunnel
|
||||||
|
* The tunnel whose contents should be exposed.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* A new TunnelResource which exposes the contents of the given tunnel.
|
||||||
|
*/
|
||||||
|
TunnelResource create(UserTunnel tunnel);
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user