Recent years have seen the growth of interest for middleware (MW) approaches in resource-constrained systems like Wireless Sensor Networks (WSNs). In this context, available MW platforms usually provide an Application Layer with different basic services, but do not provide security services such as secure links management or intrusion detection. Nevertheless, since WSN applications normally require the collection of reliable data from the sensing units, secure communications should be guaranteed even in the presence of resource constraints. So, this paper present a novel MW approach directly tailored to an IEEE 802.15.4-based WSN. The security-related components of the proposed MW include a light yet powerful cryptographic scheme (TAKS) and an Intrusion Detection System (WIDS). According to the performance and overhead assessment, we may argue that the proposed architecture has potentials to be exploited in realistic application scenarios that rely on the IEEE 802.15.4.