Context-Aware Hierarchical Learning: A Two-Step Paradigm towards Safer LLMs