API Java
HSM Dinamo
Carregando...
Procurando...
Nenhuma entrada encontrado
SystemPermission.java

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

Veja Nota sobre os exemplos.
package doxy.examples;
import java.util.concurrent.TimeUnit;
import com.dinamonetworks.Dinamo;
import br.com.trueaccess.TacException;
import br.com.trueaccess.TacNDJavaLib;
public class SystemPermission {
static String ip = "127.0.0.1";
static String operatorId = "master";
static String operatorPwd = "12345678";
static String userId = "user01";
static String userPwd = "12345678";
public static void main(String[] args) throws TacException, InterruptedException {
/*
* Cria usuário comum utilizando um usuário operador.
*
* */
Dinamo opUserSession = new Dinamo();
int authMask = 0;
opUserSession.openSession(ip, operatorId, operatorPwd, TacNDJavaLib.DEFAULT_PORT, false, false, true);
opUserSession.createUser(userId, userPwd, authMask);
/*
* Conecta com o usuário criado e dá permissão para o usuário
* operador.
*
* */
Dinamo userSession = new Dinamo();
userSession.openSession(ip,
userId,
userPwd,
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_INFO == (userSysPermissions & TacNDJavaLib.ACL_USR_REMOTE_INFO)));
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_INFO == (userSysPermissions & TacNDJavaLib.ACL_USR_REMOTE_INFO)));
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_INFO == (userSysPermissions & TacNDJavaLib.ACL_USR_REMOTE_INFO)));
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);
/*
* Espera para um pouco para a sessão ser fechada completamente.
*/
TimeUnit.SECONDS.sleep(1);
/*
* Remove usuário de teste.
* */
opUserSession.deleteUser(userId);
opUserSession.closeSession();
}
}