Auto-Inactivate Users
Can anyone think of a creative way to automatically inactivate users after a certain time period after their last log-in?
For example, if someone logs in and then they don’t log-in again for another 60 days, Agile sends a notification that their account will be inactivated and then, if no log-in has occurred by the 90 day mark, Agile automatically moves their account status from Active to Inactive.
Any ideas? Can Agile do this somehow?
Hello,
This can be achieved through custom solution. Last login can be found from DB table. Unfortunately there is no API available for this.
You can prepare a cron job which will fetch the last login date of users from DB and calculate the inactive period for each user. It can then inactive the identified user using standard SDK APIs.
In 9.3.x, groovy based Scheduled Event px is identified for anything that requires time based automation.
We use this to deactivate any user who has not logged in for 95 days or more. As previous post runs as a scheduled PX once a month.
//
import com.agile.agileDSL.ScriptObj.*;
import com.agile.api.*;
import com.agile.px.*;
import com.agile.util.sql.*;
import java.sql.*;
void invokeScript(IBaseScriptObj object) {
Connection connection = null;
PreparedStatement statement = null;
ResultSet rows = null;
try {
connection = ConnectionFactory.getFactory().getConnection();
statement = connection.prepareStatement(“SELECT a.LOGINID FROM (SELECT MAX(LOGIN_TIME)AS LAST_LOGIN, AU.LOGINID
from USER_USAGE_HISTORY uuh
JOIN AGILEUSER AU ON(uuh.USERNAME LIKE AU.LOGINID)
WHERE AU.ENABLED = 1
AND AU.DATE_CREATED < (SYSDATE-95)
GROUP BY AU.LOGINID) a
JOIN AGILEUSER AUU ON (a.LOGINID = AUU.LOGINID)
WHERE LAST_LOGIN < (SYSDATE-95)”);
rows = statement.executeQuery();
while(rows.next()) {
// modify user status
IUser user = (IUser)m_session.getObject(IUser.OBJECT_TYPE, rows.getString(“LOGINID”));
IAttribute attr = (String)user.getValue(UserConstants.ATT_GENERAL_INFO_STATUS);
if ( attr == “Active” ) {
// user.setValue(UserConstants.ATT_GENERAL_INFO_STATUS, “Inactive”);
object.logMonitor( rows.getString(“LOGINID”) + “deactivated due to account inactivity” );
}
}
} catch (Exception e) {
object.logMonitor( e.getMessage() );
}
}
AK
Hi Adrian. Thank you so much for sharing.
I received a small error in the PX script you sent me. My error message says “unexpected token: a @ line 16, column 49. 1 error” (line 16 after deleting all of the default text with Script PX; line 21 with default text). I’m not a programmer, so I can’t really diagnose it. Do you think you know what is the issue? Picture attached if it’ll help.
-Matt P
To answer my own question after one of our programmers took a look:
If anyone in the future copies and pastes this into their Java Client, you must manually replace all quotation marks with quotation marks. The fonts are just barely different in such a way that it affects the programming.
Hello,
Yes – unfortunately cut and pasting code can cause unexpected character substituting. Glad you go it working OK.
PS I am no programmer either so hope your softie was not too horrified by my coding 😉