Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last_used property to clients #675

Merged
merged 40 commits into from
Apr 10, 2024
Merged

Add last_used property to clients #675

merged 40 commits into from
Apr 10, 2024

Conversation

darcato
Copy link
Member

@darcato darcato commented Dec 4, 2023

Related to issue #605

We want to keep track of the last time a client has been used so that the long unused clients can be easily identified and deleted by the administrators.

A last_used column is added to the ClientDetails table and the API and dashboard are updated accordingly.
This requires an update to the ClientDetailsEntity on MitreID.

@darcato darcato linked an issue Dec 4, 2023 that may be closed by this pull request
@enricovianello enricovianello marked this pull request as ready for review December 20, 2023 13:18
@darcato
Copy link
Member Author

darcato commented Jan 25, 2024

I added the IAM_CLIENT_LAST_USED table with a bidirectional one to one relationship with CLIENT_DETAILS. The column LAST_USED on CLIENT_DETAILS references the ID of IAM_CLIENT_LAST_USED and initially is set to null.

The first time a client is used an entry is added to IAM_CLIENT_LAST_USED and its ID is written to the CLIENT_DETAILS(LAST_USED).

Then, when a client is used again the entry in the IAM_CLIENT_LAST_USED is updated with the new date. So this update does not write to the CLIENT_DETAILS table. Also, by updating the date corresponding to an existing ID, we avoid adding lines to the table each time a client is used.

Still, the read operation always performs two queries to the DB (as far as I understand).

I added the ClientLastUsed entity to MitreID, since it must be visible by ClientDetailsEntity. I called the table with the IAM_ prefix since it is defined in the SQL migrations in the IAM project, while the entity is defined in MitreID and thus I avoided the Iam prefix on the entity name. Should I move the the SQL table creation to MitreID?

@giacomini
Copy link
Contributor

I added the IAM_CLIENT_LAST_USED table with a bidirectional one to one relationship with CLIENT_DETAILS. The column LAST_USED on CLIENT_DETAILS references the ID of IAM_CLIENT_LAST_USED and initially is set to null.

Is it necessary to have an entry if the value is set to null?

@darcato
Copy link
Member Author

darcato commented Feb 6, 2024

The value of LAST_USED_ID on CLIENT_DETAILS is set to null when the client has been created but not used yet. Anyway with the last commits I modified the one-to-one relationship to use a shared primary key. The primary key of IAM_CLIENT_LAST_USED references the primary key of CLIENT_DETAILS. This way we avoid having the LAST_USED_ID column on CLIENT_DETAILS.

Copy link

Copy link

@darcato darcato merged commit 51ab5d8 into develop Apr 10, 2024
4 checks passed
@enricovianello enricovianello deleted the issue-605 branch April 10, 2024 14:03
enricovianello pushed a commit that referenced this pull request Apr 14, 2024
* Add table CLIENT_LAST_USED
* Add last used column on dashboard clients table
* Add TOKEN event to IamAuditApplicationEvent and publish AccessTokenIssuedEvent and AccessTokenRefreshedEvent
* Hide column on dashboard when tracking disabled
* Enable the tracking by default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

IAM should highlight how long a client has not been used
5 participants