As the development of the information network, cloud computing, big data, virtualization technology pushing several of new applications emerged. As a novel network architecture, Software defined network (SDN) provided the separation of control plane and data plane, thus controlling the hardware by the software platform which in the central controller, to realize the flexible deployment of network resource. In the process of SDN developing and application, its open architecture exposed more and more security problem, how to build a secure SDN becomes the focus of attention. Based on the hierarchical SDN architecture and characteristics, this paper analyzes the security threats that may face the SDN application layer, control layer, resource layer and interface layer. In order to solve these security threats, this paper presents the corresponding defense ability, and forms a whole SDN security architecture. Adopting an attribute-based encryption method, the paper also puts forward an enhanced access control strategy.