Achieving Compositional Security and Privacy in IoT Environments