public void deleteUser(String username, String userca) throws RemoteException, VOMSException {

    log.info("deleteUser(" + StringUtils.join(new Object[] {username, userca}, ',') + ");");

    try {

      DeleteUserOperation.instance(username, userca).execute();
      HibernateFactory.commitTransaction();

    } catch (RuntimeException e) {
      ServiceExceptionHelper.handleServiceException(log, e);
      throw e;
    }
  }
  public void deleteRole(String rolename) throws RemoteException, VOMSException {

    log.info("deleteRole(" + StringUtils.join(new Object[] {rolename}, ',') + ");");

    try {
      if (PathNamingScheme.isRole(rolename)) rolename = PathNamingScheme.getRoleName(rolename);

      DeleteRoleOperation.instance(rolename).execute();
      HibernateFactory.commitTransaction();

    } catch (RuntimeException e) {

      ServiceExceptionHelper.handleServiceException(log, e);
      throw e;
    }
  }
  public String[] listCAs() throws RemoteException, VOMSException {

    log.info("listCAs();");

    try {

      List cas = (List) ListCaOperation.instance().execute();

      HibernateFactory.commitTransaction();
      return ServiceUtils.casToStringArray(cas);

    } catch (RuntimeException e) {

      ServiceExceptionHelper.handleServiceException(log, e);
      throw e;
    }
  }
  public String[] listRoles(String username, String userca) throws RemoteException, VOMSException {

    log.info("listRoles(" + StringUtils.join(new Object[] {username, userca}, ',') + ");");
    try {

      Set roles = (Set) ListUserRolesOperation.instance(username, userca).execute();

      HibernateFactory.commitTransaction();

      return ServiceUtils.toStringArray(roles);

    } catch (RuntimeException e) {

      ServiceExceptionHelper.handleServiceException(log, e);
      throw e;
    }
  }
  public void deleteGroup(String groupname) throws RemoteException, VOMSException {

    log.info("deleteGroup(" + StringUtils.join(new Object[] {groupname}, ',') + ");");

    try {

      if (!groupname.startsWith("/")) groupname = "/" + groupname;

      DeleteGroupOperation.instance(groupname).execute();
      HibernateFactory.commitTransaction();

    } catch (RuntimeException e) {

      ServiceExceptionHelper.handleServiceException(log, e);
      throw e;
    }
  }
  public void createUser(User user) throws RemoteException, VOMSException {

    log.info(
        "createUser(" + StringUtils.join(new Object[] {user.getDN(), user.getCA()}, ',') + ");");

    try {

      Validator.validateUser(user);
      CreateUserOperation.instance(
              user.getDN(), user.getCA(), user.getCN(), user.getCertUri(), user.getMail())
          .execute();

      HibernateFactory.commitTransaction();

    } catch (RuntimeException e) {

      ServiceExceptionHelper.handleServiceException(log, e);
      throw e;
    }
  }
  public User[] listMembers(String groupname) throws RemoteException, VOMSException {

    log.info("listMembers(" + StringUtils.join(new Object[] {groupname}, ',') + ");");

    if (groupname == null || groupname.equals(""))
      groupname = "/" + VOMSConfiguration.instance().getVOName();

    try {

      List<VOMSUser> members = (List<VOMSUser>) ListMembersOperation.instance(groupname).execute();

      HibernateFactory.commitTransaction();

      return VOMSUser.collectionAsUsers(members);

    } catch (RuntimeException e) {

      ServiceExceptionHelper.handleServiceException(log, e);
      throw e;
    }
  }
  public User[] listUsersWithRole(String groupname, String rolename)
      throws RemoteException, VOMSException {

    log.info(
        "listUsersWithRole(" + StringUtils.join(new Object[] {groupname, rolename}, ',') + ");");
    try {

      if (!PathNamingScheme.isRole(rolename)) rolename = "Role=" + rolename;

      String contextString = groupname + "/" + rolename;

      List members = (List) ListMembersOperation.instance(contextString).execute();

      HibernateFactory.commitTransaction();
      return VOMSUser.collectionAsUsers(members);

    } catch (RuntimeException e) {

      ServiceExceptionHelper.handleServiceException(log, e);
      throw e;
    }
  }
  public void assignRole(String groupname, String rolename, String username, String userca)
      throws RemoteException, VOMSException {

    log.info(
        "assignRole("
            + StringUtils.join(new Object[] {groupname, rolename, username, userca}, ',')
            + ");");

    if (PathNamingScheme.isRole(rolename)) rolename = PathNamingScheme.getRoleName(rolename);

    try {

      AssignRoleOperation.instance(groupname, rolename, username, userca).execute();

      HibernateFactory.commitTransaction();

    } catch (RuntimeException e) {

      ServiceExceptionHelper.handleServiceException(log, e);
      throw e;
    }
  }
  public String[] listSubGroups(String groupname) throws RemoteException, VOMSException {

    log.info("listSubGroups(" + StringUtils.join(new Object[] {groupname}, ',') + ");");

    try {

      List childrenGroups;

      if (groupname == null) {

        VOMSContext ctxt = VOMSContext.getVoContext();
        childrenGroups = (List) ListChildrenGroupsOperation.instance(ctxt.getGroup()).execute();
      } else childrenGroups = (List) ListChildrenGroupsOperation.instance(groupname).execute();

      HibernateFactory.commitTransaction();
      return ServiceUtils.groupsToStringArray(childrenGroups);

    } catch (RuntimeException e) {

      ServiceExceptionHelper.handleServiceException(log, e);
      throw e;
    }
  }