Пример #1
0
  public String getroles(String userName) {
    System.out.println("checkrole");

    String qry =
        "SELECT ur FROM UserRole ur "
            + "JOIN FETCH ur.role "
            + "WHERE "
            + "ur.user.userName = '******'";

    System.out.println("query = " + qry);

    List<UserRole> userroles = em.createQuery(qry, UserRole.class).getResultList();

    System.out.println("Query uitgevoerd");

    String roles = "";
    int i = 0;
    for (UserRole ur : userroles) {
      roles = roles + ur.getRole().getName();
      i++;
      if (i < userroles.size()) {
        roles = roles + ",";
      }
    }
    System.out.println("roles = " + roles);
    return roles;
  }
Пример #2
0
  public ReturnStatus checkrole(String userName, String roleName) {
    System.out.println("checkrole");
    boolean rolefound = false;

    String qry =
        "SELECT ur FROM UserRole ur "
            + "JOIN FETCH ur.user "
            + "JOIN FETCH ur.role "
            + "WHERE "
            + "ur.user.userName = '******' AND "
            + "ur.role.name = '"
            + roleName
            + "'";

    System.out.println("query = " + qry);

    List<UserRole> userroles = em.createQuery(qry, UserRole.class).getResultList();

    System.out.println("Query uitgevoerd");

    for (UserRole ur : userroles) {
      String foundRole = ur.getRole().getName();
      System.out.println(
          " User = "******" Role = "
              + foundRole
              + " UserRoleId = "
              + ur.getUserRoleId());
      if (foundRole.equalsIgnoreCase(roleName)) {
        rolefound = true;
      }
    }

    if (rolefound) {
      return new ReturnStatus(true);
    } else {
      return new ReturnStatus(false);
    }
  }