mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUACAMOLE-5: Implement retrieval of sharing credentials from an active connection via REST.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.activeconnection;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import org.apache.guacamole.form.Field;
|
||||
import org.apache.guacamole.net.auth.credentials.UserCredentials;
|
||||
|
||||
/**
|
||||
* The object returned by REST API calls to define a full set of valid
|
||||
* credentials, including field definitions and corresponding expected
|
||||
* values.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class APIUserCredentials {
|
||||
|
||||
/**
|
||||
* All expected request parameters, if any, as a collection of fields.
|
||||
*/
|
||||
private final Collection<Field> expected;
|
||||
|
||||
/**
|
||||
* A map of all field values by field name.
|
||||
*/
|
||||
private final Map<String, String> values;
|
||||
|
||||
/**
|
||||
* Creates a new APIUserCredentials object whose required parameters and
|
||||
* corresponding values are defined by the given UserCredentials.
|
||||
*
|
||||
* @param userCredentials
|
||||
* The UserCredentials which defines the parameters and corresponding
|
||||
* values of this APIUserCredentials.
|
||||
*/
|
||||
public APIUserCredentials(UserCredentials userCredentials) {
|
||||
this.expected = userCredentials.getFields();
|
||||
this.values = userCredentials.getValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of all required parameters, where each parameter is
|
||||
* represented by a field.
|
||||
*
|
||||
* @return
|
||||
* A collection of all required parameters.
|
||||
*/
|
||||
public Collection<Field> getExpected() {
|
||||
return expected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of all field values by field name. The fields having the
|
||||
* names used within this map should be defined within the collection of
|
||||
* required parameters returned by getExpected().
|
||||
*
|
||||
* @return
|
||||
* A map of all field values by field name.
|
||||
*/
|
||||
public Map<String, String> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
}
|
@@ -23,7 +23,9 @@ 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.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.apache.guacamole.GuacamoleException;
|
||||
@@ -116,4 +118,29 @@ public class ActiveConnectionResource
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a set of credentials which can be POSTed by another user to the
|
||||
* "/api/tokens" endpoint to obtain access strictly to this connection. The
|
||||
* retrieved credentials may be purpose-generated and temporary.
|
||||
*
|
||||
* @param sharingProfileIdentifier The identifier of the sharing connection
|
||||
* defining the semantics of the shared session.
|
||||
*
|
||||
* @return The set of credentials which should be used to access strictly
|
||||
* this connection.
|
||||
*
|
||||
* @throws GuacamoleException If an error occurs while retrieving the
|
||||
* sharing credentials for this connection.
|
||||
*/
|
||||
@GET
|
||||
@Path("sharingCredentials/{sharingProfile}")
|
||||
public APIUserCredentials getSharingCredentials(
|
||||
@PathParam("sharingProfile") String sharingProfileIdentifier)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Generate and return sharing credentials for the active connection
|
||||
return new APIUserCredentials(activeConnection.getSharingCredentials(sharingProfileIdentifier));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user