indigo-iam / iam

INDIGO Identity and Access Management Service
https://indigo-iam.github.io/
Other
99 stars 43 forks source link

Add last_used property to clients #675

Closed darcato closed 2 months ago

darcato commented 7 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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.

sonarcloud[bot] commented 4 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
96.8% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
96.8% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud