[MANUAL] English:
[zend.git] / documentation / manual / ko / module_specs / Zend_Acl.xml
blob43ddfe603765ab04830415ca8de5332973c37cf8
1 <sect1 id="zend.acl.introduction">
2     <title>소개</title>
4     <para>
5         Zend_Acl는 가볍고 유연한 접근 제어 리스트(ACL : Access Control List) 기능과 권한 관리 기능을
6         제공합니다. 일반적으로 애플리케이션에서는 다른 요구 객체에 의해 보호된 객체에의 접근을
7         제어하기 위해서 이러한 기능을 사용합니다.
8     </para>
10     <para>
11         이 문서에 대해,
13         <itemizedlist>
14             <listitem>
15                 <para>
16                     <emphasis role="strong">자원(Resource)</emphasis> 은 접근 제어의
17                     대상이 되는 객체입니다.
18                 </para>
19             </listitem>
20             <listitem>
21                 <para>
22                     <emphasis role="strong">롤(Role)</emphasis> 은 자원에 접근을 요구하는 객체입니다.
23                 </para>
24             </listitem>
25         </itemizedlist>
27         간단하게 말하면, <emphasis role="strong">롤은 자원에 접근을 요구하는 것</emphasis>입니다.
28         예를 들어, 어떤 사람이 자동차를 탈려고 요청을 한다면, "요청한 사람"이 롤이고 "자동차"가 자원이 되고,
29         자동차에 탄 후에는 제어가 가능해집니다.
30     </para>
32     <para>
33         애플리케이션은 접근 제어 리스트(ACL)의 설정과 사용을 통해, 요청한 객체(롤)를 보호된
34         객체(자원)로의 접근을 허가할 지 제어합니다.
35     </para>
37     <sect2 id="zend.acl.introduction.resources">
38         <title>자원(Resources)에 대해</title>
39         <para>
40             Zend_Acl에서 자원을 작성하는 것은 간단합니다. Zend_Acl은 개발자가 자원을 작성하기 쉽도록
41             <code>Zend_Acl_Resource_Interface</code>를 제공합니다. 자원 클래스는 단지
42             이 인터페이스를 구현하는 것만으로 작성할 수 있습니다. 이 인터페이스에는
43             <code>getResourceId()</code>라는 단 하나의 메소드만 포함되어 있습니다.
44             이 메소드에 의해, Zend_Acl는 그 객체가 자원인지 아닌지 여부를 판단합니다.
45             게다가, Zend_Acl는 개발자가 필요한 부분을 확장하여 자원을 작성하기 위한
46             기본 자원 도구로써 <code>Zend_Acl_Resource</code>를 포함하고 있습니다.
47         </para>
48         <para>
49             Zend_Acl 은 복수의 자원(혹은 "접근이 제어되고 있는 영역들")을 추가할 수 있는
50             트리 구조를 제공하고 있습니다. 자원은 이와 같이 트리 구조로 저장되기 때문에,
51             상위(루트에 가까운 편)에서 하위(말단에 가까운 편)까지 조직될 수 있습니다.
52             특정 자원에 대해 질의를 행하면, 조상 자원들에 할당된 룰들을 살피며 자동적으로
53             자원들의 계층을 검색할 것입니다. 이것에 의해, 규칙을 계층화해서 관리할 수 있습니다.
54         </para>
55         <para>
56             또한, Zend_Acl는 자원에 대한 권한(예. "create","read","update","delete")도 지원하고 있어,
57             개발자는 자원에 대해 모든 권한 혹은 일부의 권한으로 영향을 미치는 규칙들을 부여할 수 있습니다.
58         </para>
59     </sect2>
61     <sect2 id="zend.acl.introduction.roles">
62         <title>롤(Roles)에 대해</title>
63         <para>
64             자원과 같이, 롤을 작성하는 것도 간단합니다. Zend_Acl는 개발자가 롤을 작성하기 쉽게
65             <code>Zend_Acl_Role_Interface</code>를 제공합니다. 롤 클래스는 단지 이 인터페이스를
66             구현하는 것만으로 작성할 수 있습니다. 이 인터페이스에는 <code>getRoleId()</code>라는
67             단 하나의 메소드만 포함되어 있습니다. 이 메소드에 의해, Zend_Acl는 그 객체가 롤인지
68             아닌지 여부를 판단합니다. 게다가, Zend_Acl는 개발자가 필요한 부분을 확장하여
69             롤을 작성하기 위한 기본 롤 도구로써 <code>Zend_Acl_Role</code>를 포함하고 있습니다.
70         </para>
71         <para>
72             Zend_Acl 에서 롤은 하나 혹은 그 이상의 롤들로부터 상속받을 수 있습니다.
73             이것은 각각의 롤들이 가지고 있는 규칙들을 상속받기 위한 것입니다.
74             예를 들어, "sally"와 같은 사용자 롤은, "editor" 및 "administrator"와 같이 복수의 부모 롤에
75             속하는 일도 있을 수 있습니다. 이 경우, 개발자는 "editor" 및 "administrator"에
76             각각 규칙을 정의하고, "sally"에 규칙을 직접 정의할 필요없이 "sally"가 그 양쪽으로부터
77             규칙들을 상속받습니다.
78         </para>
79         <para>
80             다중 롤로부터 상속받는 능력은 매우 유용하지만, 다중 상속은 다소 복잡성의 정도를
81             증가시키는 경우도 있습니다. 다음 예제는 애매한 조건에서 Zend_Acl로 처리하는 방법을
82             설명합니다.
83         </para>
84         <example id="zend.acl.introduction.roles.example.multiple_inheritance">
85             <title>롤들 간의 다중 상속</title>
86             <para>
87                 다음 코드는 세 개의 기본 롤들 "<code>guest</code>", "<code>member</code>" 그리고
88                 "<code>admin</code>"을 정의하고 있습니다. 다른 롤들은 이 기본 롤들로부터 상속받습니다.
89                 다음으로, "<code>someUser</code>"라는 롤을 만들고, 세 개의 기본 롤들로부터
90                 상속받습니다. 이들 롤이 $parent 배열에 선언된 순서가 중요합니다. 필요할 때,
91                 Zenc_Acl은 질의된 롤 (여기에서는 "<code>someUser</code>")뿐만 아니라,
92                 질의된 롤이 상속받은 롤들 (여기에서는, "<code>guest</code>",
93                 "<code>member</code>", 그리고 "<code>admin</code>")로 정의된
94                 접근 규칙들을 검색합니다.
95             </para>
96             <programlisting role="php"><![CDATA[<?php
97 require_once 'Zend/Acl.php';
98 $acl = new Zend_Acl();
100 require_once 'Zend/Acl/Role.php';
101 $acl->addRole(new Zend_Acl_Role('guest'))
102     ->addRole(new Zend_Acl_Role('member'))
103     ->addRole(new Zend_Acl_Role('admin'));
105 $parents = array('guest', 'member', 'admin');
106 $acl->addRole(new Zend_Acl_Role('someUser'), $parents);
108 require_once 'Zend/Acl/Resource.php';
109 $acl->add(new Zend_Acl_Resource('someResource'));
111 $acl->deny('guest', 'someResource');
112 $acl->allow('member', 'someResource');
114 echo $acl->isAllowed('someUser', 'someResource') ? 'allowed' : 'denied';]]>
115             </programlisting>
116             <para>
117                 "<code>someUser</code>"와 "<code>someResource</code>"에 특별히 정의된
118                 규칙이 없기 때문에, Zend_Acl은 "<code>someUser</code>"가 상속받은 롤들에 대해
119                 정의되었을 지도 모르는 규칙들을 검색해야만 합니다. 먼저, "<code>admin</code>"롤을
120                 방문하지만, "<code>someResource</code>"를 위해 정의된 접근 규칙이 없습니다.
121                 다음으로 "<code>member</code>"롤을 방문합니다. Zend_Acl은 "<code>member</code>"
122                 가 "<code>someResource</code>"에 접근이 허가되어 있는 규칙이 있다는 것을 발견합니다.
123             </para>
124             <para>
125                 그러나, 만약 Zend_Acl이 다른 부모 롤들에 정의된 규칙들을 계속해서 검사한다면,
126                 "<code>guest</code>"는 "<code>someResource</code>"에 접근이 거부되었다는
127                 것을 알 수 있습니다. 이 사실이 모호성을 나타냅니다. 왜냐하면, 서로 다른 부모로부터
128                 상속받은 롤들의 충돌로 인해, "<code>someUser</code>"는 현재
129                 "<code>someResource</code>"에 대한 접근 권한이 허가와 거부 둘 다 가지고 있습니다.
130             </para>
131             <para>
132                 Zend_Acl은 직접적으로 질의에 적용가능한 첫번째 규칙을 발견했을 때, 질의를
133                 완료함으로써 이러한 모호성을 해결합니다. 이 경우에는 "<code>member</code>"
134                 롤이 "<code>guest</code>" 롤보다 먼저 검색되기 때문에, 이 예제 코드는
135                 "allowed"를 출력합니다.
136             </para>
137         </example>
138         <note>
139             <para>
140                 롤에 대해 다중 부모를 지정할 때, 배열 목록의 마지막 부모가 인증 질의에 유용한 규칙을 찾기 위한 첫번째 부모 롤이 된다는 것을 명심하시기 바랍니다.
141             </para>
142         </note>
143     </sect2>
145     <sect2 id="zend.acl.introduction.creating">
146         <title>접근 제어 목록(ACL)의 생성</title>
148         <para>
149             ACL 은 여러분이 원하는대로 물리적 또는 가상의 객체들의 어떠한 집합이라도 표현할 수
150             있습니다. 그러나 여기에서는, 설명용으로서 기본적인 컨텐츠 관리 시스템(CMS)의 ACL를
151             생각합니다. 이것은, 다양한 영역에서 복수 계층의 그룹을 관리하는 것입니다. 새로운
152             ACL 객체를 생성하려면, 매개변수를 지정하지 않고 ACL의 인스턴스를 생성합니다:
153         </para>
155         <programlisting role="php"><![CDATA[<?php
156 require_once 'Zend/Acl.php';
158 $acl = new Zend_Acl();]]>
159         </programlisting>
161         <note>
162             <para>
163                 개발자가 "allow" 규칙을 지정하기 전까지, Zend_Acl은 모든 롤에 준거해 모든 자원상의
164                 권한으로의 접근을 거부합니다.
165             </para>
166         </note>
167     </sect2>
169     <sect2 id="zend.acl.introduction.role_registry">
170         <title>롤의 등록</title>
172         <para>
173             콘텐츠 관리 시스템(CMS)에서는 사용자들의 편집 권한을 부여하기 위해 대개는 권한에 대한
174             계층적인 관리가 필요합니다. 예를 들어, 'Guest'그룹에 대해서는 데모용으로 제한적인
175             접근 권한만을 허가하고, 'Staff'그룹은 통상의 작업을 하는 대부분의 CMS 유저용으로
176             권한을 부여하고, 'Editor'그룹에는 콘텐츠의 공개, 리뷰, 보존, 삭제의 권한을 주고,
177             마지막으로 'Administrator'그룹에는 다른 그룹들의 모든 권한을 포함하고 기밀 정보의
178             관리, 유저 관리, 백엔드 환경설정 데이터, 데이터의 백업/내보내기 권한을 부여할 수 있습니다.
179             이러한 권한을 롤 레지스트리로 나타낼 수 있습니다. 각 그룹의 권한을 '부모'그룹으로부터
180             상속받고, 거기에 더해 그 그룹에 고유의 권한을 추가로 정의합니다. 이러한 권한을
181             다음과 같이 나타낼 수 있습니다.
182         </para>
184         <table id="zend.acl.introduction.role_registry.table.example_cms_access_controls">
185           <title>Access Controls for an Example CMS</title>
186           <tgroup cols="3">
187             <thead>
188               <row>
189                 <entry>Name</entry>
190                 <entry>Unique permissions</entry>
191                 <entry>Inherit permissions from</entry>
192               </row>
193             </thead>
194             <tbody>
195               <row>
196                 <entry>Guest</entry>
197                 <entry>View</entry>
198                 <entry>N/A</entry>
199               </row>
200               <row>
201                 <entry>Staff</entry>
202                 <entry>Edit, Submit, Revise</entry>
203                 <entry>Guest</entry>
204               </row>
205               <row>
206                 <entry>Editor</entry>
207                 <entry>Publish, Archive, Delete</entry>
208                 <entry>Staff</entry>
209               </row>
210               <row>
211                 <entry>Administrator</entry>
212                 <entry>(Granted all access)</entry>
213                 <entry>N/A</entry>
214               </row>
215             </tbody>
216           </tgroup>
217         </table>
219         <para>
220             이 예에서는, <code>Zend_Acl_Role</code>을 이용하고 있지만,
221             <code>Zend_Acl_Role_Interface</code>를 구현하고 있는 객체라면 뭐든지 사용 가능합니다.
222             이러한 그룹들은 다음과 같이 롤 레지스트리에 추가합니다.:
223         </para>
225         <programlisting role="php"><![CDATA[<?php
226 require_once 'Zend/Acl.php';
228 $acl = new Zend_Acl();
230 // Zend_Acl_Role를 사용하여 그룹을 롤 레지스트리에 추가합니다
231 require_once 'Zend/Acl/Role.php';
233 // guest는 접근 제어를 상속받지 않습니다
234 $roleGuest = new Zend_Acl_Role('guest');
235 $acl->addRole($roleGuest);
237 // Staff는 guest부터 상속받습니다
238 $acl->addRole(new Zend_Acl_Role('staff'), $roleGuest);
240 /* 또는, 위의 내용은 다음과 같이 쓸 수도 있습니다:
241 $acl->addRole(new Zend_Acl_Role('staff'), 'guest');
242 //*/
244 // Editor는 staff로부터 상속받습니다
245 $acl->addRole(new Zend_Acl_Role('editor'), 'staff');
247 // Administrator는 접근 제어를 상속받지 않습니다
248 $acl->addRole(new Zend_Acl_Role('administrator'));]]>
249         </programlisting>
251     </sect2>
253     <sect2 id="zend.acl.introduction.defining">
254         <title>접근 제어의 정의</title>
256         <para>
257             이 제 ACL에 적절한 롤이 포함되어, 어떻게 자원에 접근할 것인지에 대해 정의하는
258             규칙들을 설정할 수 있습니다. 이 예에서는 어떠한 특정의 자원도 정의하지 않았다는
259             것을 알아차렸을 지도 모릅니다. 이 경우, 모든 자원에 대해서 규칙은 적용됩니다.
260             Zend_Acl를 사용하면, 상위에서 하위까지 규칙을 적용하는 것만으로 정의할 수 있게 됩니다.
261             왜냐하면, 자원과 롤은 그들의 조상으로부터 정의된 규칙들을 상속받기 때문입니다.
262         </para>
264         <para>
265             따라서, 상당히 복잡한 규칙의 집합도 최소한의 코드로 정의할 수 있습니다. 위에서 정의한 기본적인 권한을 적용하려면, 다음과 같이 합니다:
266         </para>
268         <programlisting role="php"><![CDATA[<?php
269 require_once 'Zend/Acl.php';
271 $acl = new Zend_Acl();
273 require_once 'Zend/Acl/Role.php';
275 $roleGuest = new Zend_Acl_Role('guest');
276 $acl->addRole($roleGuest);
277 $acl->addRole(new Zend_Acl_Role('staff'), $roleGuest);
278 $acl->addRole(new Zend_Acl_Role('editor'), 'staff');
279 $acl->addRole(new Zend_Acl_Role('administrator'));
281 // Guest는, 콘텐츠를 보는 것만 가능합니다
282 $acl->allow($roleGuest, null, 'view');
284 /* 위와 같은 내용을 다음과 같이 쓸 수도 있습니다:
285 $acl->allow('guest', null, 'view');
286 //*/
288 // Staff는 guest의 권한을 모두 상속받고, 거기에 더해 추가의 권한을 필요로 합니다
289 $acl->allow('staff', null, array('edit', 'submit', 'revise'));
291 // Editor는, staff의 권한(보기, 편집, 제출(submit) 및 수정)을 상속받고,
292 // 게다가 추가의 권한을 필요로 합니다
293 $acl->allow('editor', null, array('publish', 'archive', 'delete'));
295 // Administrator는 아무것도 상속받지 않지만, 모든 권한이 허용됩니다
296 $acl->allow('administrator');]]>
297         </programlisting>
299         <para>
300             위의 <code>allow()</code>의 콜에서 <code>null</code>은, 규칙들을 모든 자원에
301             대해 적용하는 것을 의미합니다.
302         </para>
304     </sect2>
306     <sect2 id="zend.acl.introduction.querying">
307         <title>ACL에의 질의</title>
309         <para>
310             이제 웹애플리케이션의 사용자가 어떤 기능을 사용하기 위해 필요한 권한을 가지고 있는지를 조사할 수 있는 ACL를 가지고 있습니다. 질의를 실행하는 것은 아주 간단합니다. 다음과 같이 <code>isAllowed()</code> 메소드를 사용하면 됩니다:
311         </para>
313         <programlisting role="php"><![CDATA[<?php
314 echo $acl->isAllowed('guest', null, 'view') ?
315      "allowed" : "denied"; // allowed
317 echo $acl->isAllowed('staff', null, 'publish') ?
318      "allowed" : "denied"; // denied
320 echo $acl->isAllowed('staff', null, 'revise') ?
321      "allowed" : "denied"; // allowed
323 echo $acl->isAllowed('editor', null, 'view') ?
324      "allowed" : "denied"; // guest로부터 상속받고 있으므로 allowed
326 echo $acl->isAllowed('editor', null, 'update') ?
327      "allowed" : "denied"; // 'update' 규칙이 허가 되지 않았으므로 denied
329 echo $acl->isAllowed('administrator', null, 'view') ?
330      "allowed" : "denied"; // administrator는 모든 권한이 허가되고 있으므로 allowed
332 echo $acl->isAllowed('administrator') ?
333      "allowed" : "denied"; // administrator는 모든 권한이 허가되고 있으므로 allowed
335 echo $acl->isAllowed('administrator', null, 'update') ?
336      "allowed" : "denied"; // administrator는 모든 권한이 허가되고 있으므로 allowed]]>
337         </programlisting>
339     </sect2>
340 </sect1>