public class WebClientSpawner extends ClientSpawner<WebClientConfig>
This class is tricky to understand because the main part of it runs on the server while the
TemporaryClientTask
inner class is serialized and sent down to execute on the
client side. That client side code then calls methods which are implemented as a remote
object with the Spawner
interface, which the server portions of this class implement.
In the interactive login mode, the spawned process first tries to authenticate the userid and password at the OS level. On success a new process (client) is spawned with those credentials.
In trusted mode, the spawner process will connect to the server using a secure socket and temporary credentials to establish a secure session. If that works, it will lookup the credentials to use for spawning the client based on a unique UUID for this spawning session. Using those credentials it will start the client and notify the server about success or failure.
In both modes, the spawned process will call a remote object method to get the server's KeyStore which is used to start the client's embedded web server. Finally, the client will call a remote object method to notify this (server side) instance about the URI on which the client's embedded web server is listening. If a notification does not occur within a specific amount of time, a failure in spawning is asserted.
Modifier and Type | Class and Description |
---|---|
private static class |
WebClientSpawner.TemporaryClientTask
On P2J client side, it will do custom work after authenticating using the temporary
credentials.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
gui
Flag that denotes client type (
true for GUI, false for ChUI). |
static java.lang.String |
PARAM_TOKEN
Authorization token query parameter name
|
private java.lang.String |
remoteUri
Remote server URI
|
private java.lang.String[] |
requestParameters
The request parameters
|
private WebClientsManager |
webClientsManager
The web clients manager
|
cb, cfg
Constructor and Description |
---|
WebClientSpawner(java.lang.String[] requestParameters,
boolean gui,
boolean trusted,
java.lang.String referrer,
java.lang.String[] options)
Create a new web client spawner.
|
Modifier and Type | Method and Description |
---|---|
WebClientConfig |
allocateClient(java.lang.String host)
Allocates the system resources for the spawned client if it is necessarily.
|
void |
clientIsReady(java.lang.Object data)
Notify when the client has started.
|
protected ClientBuilder |
getBuilder(ClientBuilderParameters cfg)
Get a
WebClientBuilder used to spawn P2J clients. |
java.lang.String |
getRemoteUri()
Get the remote server URI to which the browser will be redirected.
|
java.lang.Object |
getServerData()
Get the server key store.
|
TemporaryClient |
getTemporaryClient()
Get a
TemporaryClient worker which will do the work after authenticating on the P2J
server using the temporary credentials. |
void |
releaseClient()
Releases the system resources for this spawned client.
|
getExitCode, spawn
public static final java.lang.String PARAM_TOKEN
private volatile java.lang.String remoteUri
private boolean gui
true
for GUI, false
for ChUI).private final WebClientsManager webClientsManager
private final java.lang.String[] requestParameters
public WebClientSpawner(java.lang.String[] requestParameters, boolean gui, boolean trusted, java.lang.String referrer, java.lang.String[] options)
requestParameters
- Holds additional parameters if they are provided. It is expected that the first
requestParameters[0] holds the forwarded host of "X-Forwarded-Host" HTTP header,
requestParameters[1] holds the corresponding forwarded protocol that is provided
by "X-Forwarded-Proto" value and requestParameters[2] holds the client IP address.gui
- Flag that denotes client type (true
for GUI, false
for
ChUI).trusted
- If this instance will be used to launch clients in trusted mode.referrer
- The referrer string to provide the web client. If the client gets disconnected
it will be redirected back to this URL.options
- The command-line configuration options. May be null
.public void clientIsReady(java.lang.Object data)
clientIsReady
in interface SpawnerListener<WebClientConfig>
clientIsReady
in class ClientSpawner<WebClientConfig>
data
- Custom data sent by the P2J client back to the server. For web clients, this is
the remote URI to which it will redirect the browser.public java.lang.Object getServerData()
protected ClientBuilder getBuilder(ClientBuilderParameters cfg)
WebClientBuilder
used to spawn P2J clients.getBuilder
in class ClientSpawner<WebClientConfig>
cfg
- The P2J web client configuration.public java.lang.String getRemoteUri() throws java.net.URISyntaxException
null
.java.net.URISyntaxException
public TemporaryClient getTemporaryClient()
TemporaryClient
worker which will do the work after authenticating on the P2J
server using the temporary credentials.public WebClientConfig allocateClient(java.lang.String host) throws Spawner.OutOfResources
host
- The remote host for the spawned clientSpawner.OutOfResources
- If the required resources can't be allocated.public void releaseClient()