When the main cabin door is closed the cockpit door is then closed and locked. Typically the pilots are in the cockpit when this occurs which is the preferred technique. Though it's happened where the cockpit is very much secure with the pilots out of it. Makes it a real PITA to fly using the latter technique I understand.