Java API
HSM Dinamo
Loading...
Looking for...
No entries found
InvalidLoginAttempts.java

Example of recovering a user's invalid login attempts.

See Note on examples.
package doxy.examples;
import java.util.concurrent.TimeUnit;
import com.dinamonetworks.Dinamo;
import br.com.trueaccess.TacException;
import br.com.trueaccess.TacNDJavaLib;
public class InvalidLoginAttempts {
public static void main(String[] args) throws TacException, InterruptedException {
/*
* Creates an ordinary user using an operator user.
*
* */
Dinamo opUserSession = new Dinamo();
String hsmIP = "127.0.0.1";
String operatorId = "master";
String operatorPwd = "12345678";
String userId = "user01";
String userPwd = "12345678";
int authMask = 0;
opUserSession.openSession(hsmIP, operatorId, operatorPwd, TacNDJavaLib.DEFAULT_PORT, false, false, true);
opUserSession.createUser(userId, userPwd, authMask);
/*
* Tests recovery of the number of invalid login attempts.
*
* */
System.out.println("User " + userId + " invalid login attempts: " +
opUserSession.getUserInvalidLoginAttempts(userId));
/*
* Attempts an invalid authentication.
* */
Dinamo userSession = new Dinamo();
try {
userSession.openSession(hsmIP,
userId,
"invalidpwd",
TacNDJavaLib.DEFAULT_PORT,
false,
false,
true);
}catch(TacException e)
{
/* Expected failure. */
}
/*
* The number of invalid logins is increased when the policy
* of invalid attempt passwords is set.
*/
System.out.println("User " + userId + " invalid login attempts: " +
opUserSession.getUserInvalidLoginAttempts(userId));
/*
* Performs a successful authentication.
* */
userSession.openSession(hsmIP,
userId,
userPwd,
TacNDJavaLib.DEFAULT_PORT,
false,
false,
true);
System.out.println("User " + userId + " invalid login attempts: " +
opUserSession.getUserInvalidLoginAttempts(userId));
userSession.closeSession(true);
/*
* Wait a while for the session to close completely.
*/
TimeUnit.SECONDS.sleep(1);
/*
* Remove test user.
* */
opUserSession.deleteUser(userId);
opUserSession.closeSession();
}
}