Package co.cubicode.rbacframework.models

Examples of co.cubicode.rbacframework.models.User


public class RBACTest extends ApiTest {

  @Test
  public void rbacTest() throws ObjectNotFoundException {
    User user = UserBiz.findByPrimaryKey(1L);
    Role role = RoleBiz.findByPrimaryKey(user.getRole().getId());
    List<RolePermission> ids = RolePermissionBiz.findByRoleAndApplication(role, ApplicationConstants.ADMIN);
    List<Permission> permissions = new ArrayList<Permission>();
    for (RolePermission rolePermission : ids) {
      Permission permission = PermissionBiz.findByPrimaryKey(rolePermission.getApplicationId(), rolePermission.getObjectTypeId(),
          rolePermission.getOperationTypeId());
      permissions.add(permission);
    }
    role.setPermissions(permissions);
    user.setRole(role);
    System.out.println(user);

    if (user.hasRole("administrator")) {
      System.out.println("Es administrador");
    } else if (user.hasRole("operator")) {
      System.out.println("Es operador");
      Assert.fail();
    } else if (user.hasRole("guest")) {
      System.out.println("Es invitado");
      Assert.fail();
    } else {
      System.out.println("No tiene rol");
      Assert.fail();
    }
   
    Action action = Catalog.getElement(Action.class, "2");
    Permission permission = new Permission(action.getApplication(), action.getObjectType(), action.getOperationType());
    if (user.hasPermission(permission)) {
      Assert.fail();
    } else {
      System.out.println("No tiene permisos en web");
    }
  }
View Full Code Here


public class UserTest extends ApiTest {

  @Test
  public void findByPrimaryKeyTest() {
    User user = null;
    try {
      user = UserBiz.findByPrimaryKey(1L);
    } catch (ObjectNotFoundException e) {
      e.printStackTrace();
      Assert.fail();
View Full Code Here

    }
  }

  @Test
  public void createTest() {
    User user = new User();
    user.setEmail("email");
    user.setFirstName("primer nombre");
    user.setLastName("apellido");
    user.setPassword("admin");
    user.setCreateDate(Calendar.getInstance().getTime());
    user.setUpdateDate(Calendar.getInstance().getTime());
    user.setLastLogin(Calendar.getInstance().getTime());
    user.setStatus(Status.getElement(Status.class, Status.ACTIVE));
    Role role = new Role();
    role.setId(1);
    user.setRole(role);
    try {
      user = UserBiz.create(user);
    } catch (ObjectUpdateException e) {
      e.printStackTrace();
      Assert.fail();
View Full Code Here

    System.out.println(user);
  }

  @Test
  public void createSuperUserTest() {
    User user = new User();
    user.setEmail("email");
    user.setFirstName("Sin nombre");
    user.setLastName("Sin apellido");
    String password = "Jfsebe4tbGvr";
    user.setPassword(PasswordUtils.hashPassword(password));
    user.setCreateDate(Calendar.getInstance().getTime());
    user.setStatus(Status.getElement(Status.class, Status.ACTIVE));
    Role role = new Role();
    role.setId(1);
    user.setRole(role);
    try {
      user = UserBiz.create(user);
    } catch (ObjectUpdateException e) {
      e.printStackTrace();
      Assert.fail();
View Full Code Here

TOP

Related Classes of co.cubicode.rbacframework.models.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.