Ejemplo de tokens de acceso con HSM.
package doxy.examples;
import java.util.Base64;
import com.dinamonetworks.Dinamo;
import br.com.trueaccess.TacAccessToken;
import br.com.trueaccess.TacException;
import br.com.trueaccess.TacNDJavaLib;
public class AToken {
public static void main(String[] args) {
try {
String ip = "127.0.0.1";
String user = "master";
String password = "12345678";
Dinamo dnIssueSession = new Dinamo();
dnIssueSession.openSession(ip, user, password, TacNDJavaLib.DEFAULT_PORT,
false, false, true);
TacAccessToken newAToken = dnIssueSession.issueAToken(TacNDJavaLib.DN_A_TOKEN_INFINITE);
TacAccessToken[] atokenList = dnIssueSession.listAToken();
System.out.println("ATokens List:");
for(int i=0; i<atokenList.length; i++)
{
System.out.println(i + " : " + atokenList[i].getStrUserName());
System.out.println(" Expiration: " + atokenList[i].getExpiration());
System.out.println(" Key: " + new String(Base64.getEncoder().encode(atokenList[i].getKey())));
System.out.println(" atoken: " + new String(Base64.getEncoder().encode(atokenList[i].getAToken())));
System.out.println(" atoken full: " + new String(Base64.getEncoder().encode(atokenList[i].getFullAToken())));
}
Dinamo atokenSession = new Dinamo();
atokenSession.openSession(ip, newAToken, TacNDJavaLib.DEFAULT_PORT,
false, false, true);
atokenSession.closeSession();
int totalAtokens = dnIssueSession.getATokenCounter();
System.out.println("Atokens Count: " + totalAtokens);
System.out.println("Running AToken GC...");
dnIssueSession.runATokenGC();
System.out.println("Revoking AToken...");
dnIssueSession.revokeAToken(newAToken);
dnIssueSession.closeSession();
} catch (TacException e) {
e.printStackTrace();
}
}
}