public Integer getRegisterDeptOfic(String guid, String entidad) throws SecurityException {
    Transaction tran = null;
    Integer deptId = null;
    try {
      Session session = HibernateUtil.currentSession(entidad);
      // tran = session.beginTransaction();

      // Obtener el grupo ldap de la tabla de grupos
      List list = ISicresQueries.getUserLdapPgrp(session, guid);
      if (list != null && !list.isEmpty()) {
        Iuserldapgrphdr udeptGrpHdr = (Iuserldapgrphdr) list.get(0);
        if (log.isDebugEnabled()) {
          log.debug(" Iuserldapgrphdr [" + udeptGrpHdr + "] con el log [" + log + "]");
        }

        // Obtener el departamento invesdoc asociado al grupo ldap
        list = ISicresQueries.getUserDeptHdr(session, udeptGrpHdr.getId());
        if (list != null && !list.isEmpty()) {
          Iuserdepthdr udeptHdr = (Iuserdepthdr) list.get(0);
          if (log.isDebugEnabled()) {
            log.debug(" Iuserdepthdr [" + udeptHdr + "] con el log [" + log + "]");
          }
          deptId = udeptHdr.getId();
        }
      }
      // HibernateUtil.commitTransaction(tran);
    } catch (Exception e) {
      // HibernateUtil.rollbackTransaction(tran);
      log.error("Impossible to verify user with guid[" + guid + "]", e);
      throw new SecurityException(SecurityException.ERROR_USER_NOTFOUND);
    } /*
       * finally { HibernateUtil.closeSession(); }
       */
    return deptId;
  }
  public Integer userVerification(LDAPAuthenticationUser attributesUser, String entidad)
      throws SecurityException {

    Integer userId = null;
    try {
      Session session = HibernateUtil.currentSession(entidad);
      // tran = session.beginTransaction();

      // consulta si existe el usuario en ldap
      List list = ISicresQueries.getUserLdapUser(session, attributesUser.getGuidStringFormat());
      // si no existe el usuario lo inserta en el modelo de isicres
      if (list == null || list.isEmpty()) {
        userId =
            new Integer(
                DBEntityDAOFactory.getCurrentDBEntityDAO()
                    .getNextIdForUser(
                        attributesUser.getGuidStringFormat(),
                        attributesUser.getFullName(),
                        entidad));
        if (log.isDebugEnabled()) {
          log.debug("new userId [" + userId + "] con el log [" + log + "]");
        }
        list = ISicresQueries.getUserUserType(session, userId.intValue(), 5);
        Iuserusertype userType = null;
        if (list == null || list.isEmpty()) {
          userType = new Iuserusertype();
          userType.setUserid(userId.intValue());

          // producto sicres valor 5
          // seteamos usuario estandar (operador de registro)
          // IDocKeys
          // IUSER_USER_TYPE_NULL       (0)
          // IUSERUSERTYPE_USER_TYPE_OPERATOR = 1;
          // IUSERUSERTYPE_USER_TYPE_BOOK_ADMIN = 2;
          // IUSERUSERTYPE_USER_TYPE_ADMIN = 3;
          userType.setProdid(5);
          userType.setType(1);
          session.save(userType);

          // IUSER_PROD_ID_IUSER    (2) (q tipo de producto es este? para q es?)
          userType = new Iuserusertype();
          userType.setUserid(userId.intValue());
          userType.setProdid(2);
          userType.setType(0);
          session.save(userType);
          session.flush();
        }
      } else { // el usuario ya existe en el sistema de sicres
        Iuserldapuserhdr ldapUser = (Iuserldapuserhdr) list.get(0);
        if (log.isDebugEnabled()) {
          log.debug("exist userId Iuserldapuserhdr [" + ldapUser + "] con el log [" + log + "]");
        }
        // obtenemos el perfil del usuario
        userId = new Integer(ldapUser.getId());
        list = ISicresQueries.getUserUserType(session, ldapUser.getId(), 5);

        // Si no existen valores en iuserusertype, se lanzará una excepción de seguridad
        if (list == null || list.size() == 0) {
          throw new SecurityException(SecurityException.ERROR_IUSERUSERTYPE_NOT_FOUND);
        }

        Iuserusertype userType = (Iuserusertype) list.get(0);
        if (log.isDebugEnabled()) {
          log.debug("exist userId Iuserusertype [" + userType + "] con el log [" + log + "]");
        }
        // DBEntityDAOFactory.getCurrentDBEntityDAO().updateRole(userType.getUserid(),
        // userType.getProdid(), 1, entidad);
        DBEntityDAOFactory.getCurrentDBEntityDAO()
            .updateRole(userType.getUserid(), userType.getProdid(), userType.getType(), entidad);
        DBEntityDAOFactory.getCurrentDBEntityDAO()
            .updateLdapFullName(ldapUser.getId(), attributesUser.getFullName(), entidad);
      }

      // HibernateUtil.commitTransaction(tran);
    } catch (HibernateException e) {
      // HibernateUtil.rollbackTransaction(tran);
      log.error("Impossible to verify user [" + attributesUser + "] on LDAP", e);
      throw new SecurityException(SecurityException.ERROR_SQL);
    } catch (SecurityException e) {
      throw e;
    } catch (Exception e) {
      // HibernateUtil.rollbackTransaction(tran);
      log.error("Impossible to verify user [" + attributesUser + "] on LDAP", e);
      throw new SecurityException(SecurityException.ERROR_SQL);
    } /*
       * finally { HibernateUtil.closeSession(); }
       */
    return userId;
  }