Automatically insert user history records upon login.
@@ -26,9 +26,11 @@ import org.apache.guacamole.auth.jdbc.connection.ConnectionDirectory;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.util.Collection;
+import java.util.Date;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.auth.jdbc.base.RestrictedObject;
import org.apache.guacamole.auth.jdbc.activeconnection.ActiveConnectionDirectory;
+import org.apache.guacamole.auth.jdbc.base.ActivityRecordModel;
import org.apache.guacamole.auth.jdbc.connection.ConnectionRecordSet;
import org.apache.guacamole.auth.jdbc.connection.ModeledConnection;
import org.apache.guacamole.auth.jdbc.connectiongroup.ModeledConnectionGroup;
@@ -44,7 +46,6 @@ import org.apache.guacamole.net.auth.ConnectionGroup;
import org.apache.guacamole.net.auth.Directory;
import org.apache.guacamole.net.auth.SharingProfile;
import org.apache.guacamole.net.auth.User;
-import org.apache.guacamole.net.auth.simple.SimpleActivityRecordSet;
/**
* UserContext implementation which is driven by an arbitrary, underlying
@@ -106,6 +107,17 @@ public class ModeledUserContext extends RestrictedObject
@Inject
private Provider<UserRecordSet> userRecordSetProvider;
+ /**
+ * Mapper for user login records.
+ */
+ @Inject
+ private UserRecordMapper userRecordMapper;
+
+ /**
+ * The activity record associated with this user's Guacamole session.
+ */
+ private ActivityRecordModel userRecord;
+
@Override
public void init(ModeledAuthenticatedUser currentUser) {
@@ -118,6 +130,16 @@ public class ModeledUserContext extends RestrictedObject
sharingProfileDirectory.init(currentUser);
activeConnectionDirectory.init(currentUser);
+ // Create login record for user
+ userRecord = new ActivityRecordModel();
+ userRecord.setUserID(currentUser.getUser().getModel().getObjectID());
+ userRecord.setUsername(currentUser.getIdentifier());
+ userRecord.setStartDate(new Date());
+ userRecord.setRemoteHost(currentUser.getCredentials().getRemoteHostname());
+
+ // Insert record representing login
+ userRecordMapper.insert(userRecord);
+
}
@Override
