Skip to content
Snippets Groups Projects
Commit 56cbd40b authored by ale's avatar ale
Browse files

Add authenticator ID field to the userlog

parent 7c1d2d27
No related branches found
No related tags found
No related merge requests found
......@@ -66,13 +66,14 @@ func DecodeDeviceInfoFromMap(m map[string]string, prefix string) *DeviceInfo {
// LogEntry represents an authentication event in the user-specific log.
type LogEntry struct {
Timestamp time.Time `json:"timestamp"`
Username string `json:"username"`
Type string `json:"log_type"`
Message string `json:"message,omitempty"`
Service string `json:"service,omitempty"`
LoginMethod string `json:"login_method,omitempty"`
DeviceInfo *DeviceInfo `json:"device_info,omitempty"`
Timestamp time.Time `json:"timestamp"`
Username string `json:"username"`
Type string `json:"log_type"`
Message string `json:"message,omitempty"`
Service string `json:"service,omitempty"`
LoginMethod string `json:"login_method,omitempty"`
LoginAuthenticatorID string `json:"login_authenticator_id,omitempty"`
DeviceInfo *DeviceInfo `json:"device_info,omitempty"`
}
func (e *LogEntry) Validate() error {
......
......@@ -85,6 +85,9 @@ INSERT INTO userlog (username, service, log_type, login_method, message, device_
DROP TABLE _userlog_old;
`, `
PRAGMA foreign_keys=on;
`),
sqlutil.Statement(`
ALTER TABLE userlog ADD COLUMN login_authenticator_id TEXT;
`),
}
......
......@@ -42,17 +42,17 @@ var userlogDBStatements = map[string]string{
// optional device information).
"insert_userlog": `
INSERT INTO userlog (
username, service, log_type, login_method, message, timestamp
username, service, log_type, login_method, login_authenticator_id, message, timestamp
) VALUES (
?, ?, ?, ?, ?, ?
?, ?, ?, ?, ?, ?, ?
)`,
"insert_userlog_with_device_info": `
INSERT INTO userlog (
username, service, log_type, login_method, message, timestamp,
username, service, log_type, login_method, login_authenticator_id, message, timestamp,
device_id, device_remote_zone, device_user_agent,
device_browser, device_os, device_mobile
) VALUES (
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
)`,
// Database maintenance (prune old entries etc).
......@@ -87,7 +87,7 @@ var userlogDBStatements = map[string]string{
// Retrieve logs for a specific user.
"get_user_logs": `
SELECT
service, log_type, login_method, message, timestamp,
service, log_type, login_method, login_authenticator_id, message, timestamp,
device_id, device_remote_zone, device_user_agent,
device_browser, device_os, device_mobile
FROM
......@@ -229,6 +229,7 @@ func (u *userlogDB) AddLog(ctx context.Context, entry *usermetadb.LogEntry) erro
entry.Service,
entry.Type,
entry.LoginMethod,
entry.LoginAuthenticatorID,
entry.Message,
entry.Timestamp,
}
......@@ -285,6 +286,7 @@ func scanEntryRow(rows *sql.Rows) (*usermetadb.LogEntry, error) {
&e.Service,
&e.Type,
&e.LoginMethod,
&e.LoginAuthenticatorID,
&e.Message,
&e.Timestamp,
&deviceID,
......
......@@ -127,6 +127,7 @@ func bulkLoadTestLogs(t testing.TB, db *sql.DB) *usermetadb.LogEntry {
entry.Service,
entry.Type,
entry.LoginMethod,
entry.LoginAuthenticatorID,
entry.Message,
entry.Timestamp,
entry.DeviceInfo.ID,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment