mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-1101: Implement connection record retrieval.
This commit is contained in:
@@ -30,6 +30,7 @@ import com.google.inject.Module;
|
||||
import com.google.inject.name.Names;
|
||||
import java.util.Properties;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionMapper;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionRecordMapper;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.dao.ParameterMapper;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.dao.SystemPermissionMapper;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
@@ -144,6 +145,7 @@ public class MySQLAuthenticationProvider implements AuthenticationProvider {
|
||||
|
||||
// Add MyBatis mappers
|
||||
addMapperClass(ConnectionMapper.class);
|
||||
addMapperClass(ConnectionRecordMapper.class);
|
||||
addMapperClass(ParameterMapper.class);
|
||||
addMapperClass(SystemPermissionMapper.class);
|
||||
addMapperClass(UserMapper.class);
|
||||
|
@@ -24,7 +24,6 @@ package net.sourceforge.guacamole.net.auth.mysql;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionModel;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.service.ConnectionService;
|
||||
@@ -181,8 +180,7 @@ public class MySQLConnection implements Connection, DirectoryObject<ConnectionMo
|
||||
|
||||
@Override
|
||||
public List<? extends ConnectionRecord> getHistory() throws GuacamoleException {
|
||||
/* STUB */
|
||||
return Collections.EMPTY_LIST;
|
||||
return connectionService.retrieveHistory(currentUser, this.getIdentifier());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -24,72 +24,52 @@ package net.sourceforge.guacamole.net.auth.mysql;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionRecordModel;
|
||||
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
|
||||
|
||||
/**
|
||||
* A ConnectionRecord which is based on data stored in MySQL.
|
||||
*
|
||||
* @author James Muehlner
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class MySQLConnectionRecord implements ConnectionRecord {
|
||||
|
||||
/**
|
||||
* The start date of the ConnectionRecord.
|
||||
* The model object backing this connection record.
|
||||
*/
|
||||
private Date startDate;
|
||||
private ConnectionRecordModel model;
|
||||
|
||||
/**
|
||||
* The end date of the ConnectionRecord.
|
||||
* Creates a new MySQLConnectionRecord backed by the given model object.
|
||||
* Changes to this record will affect the backing model object, and changes
|
||||
* to the backing model object will affect this record.
|
||||
*
|
||||
* @param model
|
||||
* The model object to use to back this connection record.
|
||||
*/
|
||||
private Date endDate;
|
||||
|
||||
/**
|
||||
* The name of the user that is associated with this ConnectionRecord.
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* Whether this connection is currently active.
|
||||
*/
|
||||
private boolean active;
|
||||
|
||||
/**
|
||||
* Initialize this MySQLConnectionRecord with the start/end dates,
|
||||
* and the name of the user it represents.
|
||||
*
|
||||
* @param startDate The start date of the connection history.
|
||||
* @param endDate The end date of the connection history.
|
||||
* @param username The name of the user that used the connection.
|
||||
* @param active Whether the connection is currently active.
|
||||
*/
|
||||
public MySQLConnectionRecord(Date startDate, Date endDate,
|
||||
String username, boolean active) {
|
||||
if (startDate != null) this.startDate = new Date(startDate.getTime());
|
||||
if (endDate != null) this.endDate = new Date(endDate.getTime());
|
||||
this.username = username;
|
||||
this.active = active;
|
||||
public MySQLConnectionRecord(ConnectionRecordModel model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getStartDate() {
|
||||
if (startDate == null) return null;
|
||||
return new Date(startDate.getTime());
|
||||
return model.getStartDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getEndDate() {
|
||||
if (endDate == null) return null;
|
||||
return new Date(endDate.getTime());
|
||||
return model.getEndDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return username;
|
||||
return model.getUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.sourceforge.guacamole.net.auth.mysql.dao;
|
||||
|
||||
import java.util.List;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionRecordModel;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* Mapper for connection record objects.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public interface ConnectionRecordMapper {
|
||||
|
||||
/**
|
||||
* Returns a collection of all connection records associated with the
|
||||
* connection having the given identifier.
|
||||
*
|
||||
* @param identifier
|
||||
* The identifier of the connection whose records are to be retrieved.
|
||||
*
|
||||
* @return
|
||||
* A collection of all connection records associated with the
|
||||
* connection having the given identifier. This collection will be
|
||||
* empty if no such connection exists.
|
||||
*/
|
||||
List<ConnectionRecordModel> select(@Param("identifier") String identifier);
|
||||
|
||||
/**
|
||||
* Inserts the given connection record.
|
||||
*
|
||||
* @param record
|
||||
* The connection record to insert.
|
||||
*
|
||||
* @return
|
||||
* The number of rows inserted.
|
||||
*/
|
||||
int insert(@Param("record") ConnectionRecordModel record);
|
||||
|
||||
}
|
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.sourceforge.guacamole.net.auth.mysql.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* A single connection record representing a past usage of a particular
|
||||
* connection.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class ConnectionRecordModel {
|
||||
|
||||
/**
|
||||
* The identifier of the connection associated with this connection record.
|
||||
*/
|
||||
private String connectionIdentifier;
|
||||
|
||||
/**
|
||||
* The database ID of the user associated with this connection record.
|
||||
*/
|
||||
private Integer userID;
|
||||
|
||||
/**
|
||||
* The username of the user associated with this connection record.
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* The time the connection was initiated by the associated user.
|
||||
*/
|
||||
private Date startDate;
|
||||
|
||||
/**
|
||||
* The time the connection ended, or null if the end time is not known or
|
||||
* the connection is still running.
|
||||
*/
|
||||
private Date endDate;
|
||||
|
||||
/**
|
||||
* Returns the identifier of the connection associated with this connection
|
||||
* record.
|
||||
*
|
||||
* @return
|
||||
* The identifier of the connection associated with this connection
|
||||
* record.
|
||||
*/
|
||||
public String getConnectionIdentifier() {
|
||||
return connectionIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the identifier of the connection associated with this connection
|
||||
* record.
|
||||
*
|
||||
* @param connectionIdentifier
|
||||
* The identifier of the connection to associate with this connection
|
||||
* record.
|
||||
*/
|
||||
public void setConnectionIdentifier(String connectionIdentifier) {
|
||||
this.connectionIdentifier = connectionIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the database ID of the user associated with this connection
|
||||
* record.
|
||||
*
|
||||
* @return
|
||||
* The database ID of the user associated with this connection record.
|
||||
*/
|
||||
public Integer getUserID() {
|
||||
return userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the database ID of the user associated with this connection record.
|
||||
*
|
||||
* @param userID
|
||||
* The database ID of the user to associate with this connection
|
||||
* record.
|
||||
*/
|
||||
public void setUserID(Integer userID) {
|
||||
this.userID = userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the username of the user associated with this connection record.
|
||||
*
|
||||
* @return
|
||||
* The username of the user associated with this connection record.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username of the user associated with this connection record.
|
||||
*
|
||||
* @param username
|
||||
* The username of the user to associate with this connection record.
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date that the associated connection was established.
|
||||
*
|
||||
* @return
|
||||
* The date the associated connection was established.
|
||||
*/
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the date that the associated connection was established.
|
||||
*
|
||||
* @param startDate
|
||||
* The date that the associated connection was established.
|
||||
*/
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date that the associated connection ended, or null if no
|
||||
* end date was recorded. The lack of an end date does not necessarily
|
||||
* mean that the connection is still active.
|
||||
*
|
||||
* @return
|
||||
* The date the associated connection ended, or null if no end date was
|
||||
* recorded.
|
||||
*/
|
||||
public Date getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the date that the associated connection ended.
|
||||
*
|
||||
* @param endDate
|
||||
* The date that the associated connection ended.
|
||||
*/
|
||||
public void setEndDate(Date endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
}
|
@@ -27,14 +27,18 @@ import com.google.inject.Provider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.AuthenticatedUser;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.MySQLConnection;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.MySQLConnectionRecord;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionMapper;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionRecordMapper;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.dao.DirectoryObjectMapper;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.dao.ParameterMapper;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionModel;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionRecordModel;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.model.ParameterModel;
|
||||
import org.glyptodon.guacamole.GuacamoleClientException;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
@@ -67,6 +71,12 @@ public class ConnectionService extends DirectoryObjectService<MySQLConnection, C
|
||||
@Inject
|
||||
private ParameterMapper parameterMapper;
|
||||
|
||||
/**
|
||||
* Mapper for accessing connection history.
|
||||
*/
|
||||
@Inject
|
||||
private ConnectionRecordMapper connectionRecordMapper;
|
||||
|
||||
/**
|
||||
* Provider for creating connections.
|
||||
*/
|
||||
@@ -262,6 +272,43 @@ public class ConnectionService extends DirectoryObjectService<MySQLConnection, C
|
||||
return parameterMap;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the connection history of the connection with the given
|
||||
* identifier.
|
||||
*
|
||||
* @param user
|
||||
* The user retrieving the connection history.
|
||||
*
|
||||
* @param identifier
|
||||
* The identifier of the connection whose history is being retrieved.
|
||||
*
|
||||
* @return
|
||||
* @throws GuacamoleException
|
||||
*/
|
||||
public List<MySQLConnectionRecord> retrieveHistory(AuthenticatedUser user,
|
||||
String identifier) throws GuacamoleException {
|
||||
|
||||
// Retrieve history only if READ permission is granted
|
||||
if (hasObjectPermission(user, identifier, ObjectPermission.Type.READ)) {
|
||||
|
||||
// Retrieve history
|
||||
List<ConnectionRecordModel> models = connectionRecordMapper.select(identifier);
|
||||
|
||||
// Convert model objects into standard records
|
||||
List<MySQLConnectionRecord> records = new ArrayList<MySQLConnectionRecord>(models.size());
|
||||
for (ConnectionRecordModel model : models)
|
||||
records.add(new MySQLConnectionRecord(model));
|
||||
|
||||
// Return converted history list
|
||||
return records;
|
||||
|
||||
}
|
||||
|
||||
// The user does not have permission to read the history
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to the given connection as the given user, using the given
|
||||
|
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
|
||||
<!--
|
||||
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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
-->
|
||||
|
||||
<mapper namespace="net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionRecordMapper" >
|
||||
|
||||
<!-- Result mapper for system permissions -->
|
||||
<resultMap id="ConnectionRecordResultMap" type="net.sourceforge.guacamole.net.auth.mysql.model.ConnectionRecordModel">
|
||||
<result column="connection_id" property="connectionIdentifier" jdbcType="INTEGER"/>
|
||||
<result column="user_id" property="userID" jdbcType="INTEGER"/>
|
||||
<result column="username" property="username" jdbcType="VARCHAR"/>
|
||||
<result column="start_date" property="startDate" jdbcType="TIMESTAMP"/>
|
||||
<result column="end_date" property="endDate" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- Select all connection records from a given connection -->
|
||||
<select id="select" resultMap="ConnectionRecordResultMap">
|
||||
|
||||
SELECT
|
||||
connection_id,
|
||||
guacamole_connection_history.user_id,
|
||||
username,
|
||||
start_date,
|
||||
end_date
|
||||
FROM guacamole_connection_history
|
||||
JOIN guacamole_user ON guacamole_connection_history.user_id = guacamole_user.user_id
|
||||
WHERE
|
||||
connection_id = #{identifier,jdbcType=VARCHAR}
|
||||
ORDER BY
|
||||
start_date,
|
||||
end_date
|
||||
|
||||
</select>
|
||||
|
||||
<!-- Insert the given connection record -->
|
||||
<insert id="insert" parameterType="net.sourceforge.guacamole.net.auth.mysql.model.ConnectionRecordModel">
|
||||
|
||||
INSERT INTO guacamole_connection_history (
|
||||
connection_id,
|
||||
user_id,
|
||||
start_date,
|
||||
end_date
|
||||
)
|
||||
VALUES (
|
||||
#{record.connectionIdentifier,jdbcType=VARCHAR},
|
||||
#{record.userID,jdbcType=INTEGER},
|
||||
#{record.startDate,jdbcType=TIMESTAMP},
|
||||
#{record.endDate,jdbcType=TIMESTAMP}
|
||||
)
|
||||
|
||||
</insert>
|
||||
|
||||
</mapper>
|
Reference in New Issue
Block a user