PermissaoSistema.java

Exemplo de permissões de sistema para usuários do HSM.

Veja Nota sobre os exemplos.
package doxy.examples;
public class PermissaoSistema {
public static void main(String[] args) throws TacException {
/*
* Cria usuário comum utilizando um usuário operador.
*
* */
Dinamo opUserSession = new Dinamo();
String operatorId = "master";
String userId = "user01";
int authMask = 0;
opUserSession.openSession("10.0.62.47", operatorId, "12345678", TacNDJavaLib.DEFAULT_PORT, false, false, true);
opUserSession.createUser(userId, "12345678", authMask);
/*
* Conecta com o usuário criado e dá permissão para o usuário
* operador.
*
* */
Dinamo userSession = new Dinamo();
userSession.openSession("10.0.62.47",
userId,
"12345678",
TacNDJavaLib.DEFAULT_PORT,
false, false, true);
/*
* Define permissões de sistema.
* */
opUserSession.updateUserSysPermission(userId,
true,
true,
true,
true,
true);
/*
* Recupera permissões de sistema.
* */
System.out.println("System permissions: ");
int userSysPermissions = userSession.getUserACL(userId);
System.out.println("Create: " + (TacNDJavaLib.ACL_USR_CREATE == (userSysPermissions & TacNDJavaLib.ACL_USR_CREATE)));
System.out.println("List: " + (TacNDJavaLib.ACL_USR_LIST == (userSysPermissions & TacNDJavaLib.ACL_USR_LIST)));
System.out.println("Log: " + (TacNDJavaLib.ACL_USR_REMOTE_LOG == (userSysPermissions & TacNDJavaLib.ACL_USR_REMOTE_LOG)));
System.out.println("Backup: " + (TacNDJavaLib.ACL_SYS_BACKUP == (userSysPermissions & TacNDJavaLib.ACL_SYS_BACKUP)));
System.out.println("Firmware: " + (TacNDJavaLib.ACL_SYS_UDATE_HSM == (userSysPermissions & TacNDJavaLib.ACL_SYS_UDATE_HSM)));
/*
* Remove permissões de sistema.
* */
opUserSession.updateUserSysPermission( userId,
false,
false,
false,
false,
false);
/*
* Recupera permissões de sistema.
* */
userSysPermissions = userSession.getUserACL(userId);
System.out.println("System permissions(remove): ");
System.out.println("Create: " + (TacNDJavaLib.ACL_USR_CREATE == (userSysPermissions & TacNDJavaLib.ACL_USR_CREATE)));
System.out.println("List: " + (TacNDJavaLib.ACL_USR_LIST == (userSysPermissions & TacNDJavaLib.ACL_USR_LIST)));
System.out.println("Log: " + (TacNDJavaLib.ACL_USR_REMOTE_LOG == (userSysPermissions & TacNDJavaLib.ACL_USR_REMOTE_LOG)));
System.out.println("Backup: " + (TacNDJavaLib.ACL_SYS_BACKUP == (userSysPermissions & TacNDJavaLib.ACL_SYS_BACKUP)));
System.out.println("Firmware: " + (TacNDJavaLib.ACL_SYS_UDATE_HSM == (userSysPermissions & TacNDJavaLib.ACL_SYS_UDATE_HSM)));
/*
* Transforma um usuário em usuário operador.
* */
opUserSession.setUserOperator(userId);
/*
* Recupera permissões de sistema.
* */
userSysPermissions = userSession.getUserACL(userId);
System.out.println("System permissions(operator): ");
System.out.println("Operator: " + (TacNDJavaLib.ACL_SYS_OPERATOR == (userSysPermissions & TacNDJavaLib.ACL_SYS_OPERATOR)));
/*
* Remove permissões de sistema.
* */
opUserSession.updateUserSysPermission( userId,
false,
false,
false,
false,
false);
/*
* Recupera permissões de sistema.
* */
userSysPermissions = userSession.getUserACL(userId);
System.out.println("System permissions(remove): ");
System.out.println("Create: " + (TacNDJavaLib.ACL_USR_CREATE == (userSysPermissions & TacNDJavaLib.ACL_USR_CREATE)));
System.out.println("List: " + (TacNDJavaLib.ACL_USR_LIST == (userSysPermissions & TacNDJavaLib.ACL_USR_LIST)));
System.out.println("Log: " + (TacNDJavaLib.ACL_USR_REMOTE_LOG == (userSysPermissions & TacNDJavaLib.ACL_USR_REMOTE_LOG)));
System.out.println("Backup: " + (TacNDJavaLib.ACL_SYS_BACKUP == (userSysPermissions & TacNDJavaLib.ACL_SYS_BACKUP)));
System.out.println("Firmware: " + (TacNDJavaLib.ACL_SYS_UDATE_HSM == (userSysPermissions & TacNDJavaLib.ACL_SYS_UDATE_HSM)));
userSession.closeSession(true);
/*
* Remove usuário de teste.
* */
opUserSession.deleteUser(userId);
opUserSession.closeSession();
}
}