1   /* Copyright 2004 Acegi Technology Pty Limited
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  
16  package org.acegisecurity;
17  
18  import org.acegisecurity.acl.AclEntry;
19  import org.acegisecurity.acl.AclManager;
20  
21  
22  /***
23   * Returns the indicated collection of <code>AclEntry</code>s when the given
24   * <code>Authentication</code> principal is presented for the indicated domain
25   * <code>Object</code> instance.
26   *
27   * @author Ben Alex
28   * @version $Id: MockAclManager.java,v 1.2 2005/11/17 00:55:47 benalex Exp $
29   */
30  public class MockAclManager implements AclManager {
31      //~ Instance fields ========================================================
32  
33      private Object object;
34      private Object principal;
35      private AclEntry[] acls;
36  
37      //~ Constructors ===========================================================
38  
39      public MockAclManager(Object domainObject, Object principal, AclEntry[] acls) {
40          this.object = domainObject;
41          this.principal = principal;
42          this.acls = acls;
43      }
44  
45      private MockAclManager() {}
46  
47      //~ Methods ================================================================
48  
49      public AclEntry[] getAcls(Object domainInstance,
50          Authentication authentication) {
51          if (domainInstance.equals(object)
52              && authentication.getPrincipal().equals(principal)) {
53              return acls;
54          } else {
55              return null;
56          }
57      }
58  
59      public AclEntry[] getAcls(Object domainInstance) {
60          if (domainInstance.equals(object)) {
61              return acls;
62          } else {
63              return null;
64          }
65      }
66  }