01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: /* $Id: PolicyManagerTest.java 483573 2006-12-07 17:57:48Z andreas $ */
20:
21: package org.apache.lenya.ac.impl;
22:
23: import java.util.Arrays;
24: import java.util.List;
25:
26: import org.apache.lenya.ac.AccessControlException;
27: import org.apache.lenya.ac.Policy;
28: import org.apache.lenya.ac.PolicyManager;
29: import org.apache.lenya.ac.Role;
30: import org.apache.lenya.ac.User;
31: import org.apache.lenya.ac.UserManager;
32: import org.apache.lenya.cms.ac.PolicyUtil;
33:
34: /**
35: * Test for the Policy Manager
36: */
37: public class PolicyManagerTest extends AbstractAccessControlTest {
38:
39: private static String[] URLS = { "/default/authoring/index.html" };
40:
41: /**
42: * The test.
43: * @throws AccessControlException when something went wrong.
44: */
45: public void testPolicyManager() throws AccessControlException {
46:
47: DefaultAccessController controller = getAccessController();
48: PolicyManager policyManager = controller.getPolicyManager();
49: assertNotNull(policyManager);
50:
51: for (int i = 0; i < URLS.length; i++) {
52: Policy policy = policyManager.getPolicy(controller
53: .getAccreditableManager(), URLS[i]);
54: assertNotNull(policy);
55:
56: Role[] roles = policyManager.getGrantedRoles(controller
57: .getAccreditableManager(), getIdentity(), URLS[i]);
58: assertTrue(roles.length > 0);
59:
60: User[] users = PolicyUtil.getUsersWithRole(getManager(),
61: URLS[i], "review", getLogger());
62:
63: UserManager userManager = controller
64: .getAccreditableManager().getUserManager();
65: User lenya = userManager.getUser("lenya");
66: User alice = userManager.getUser("alice");
67:
68: List usersList = Arrays.asList(users);
69: assertFalse(usersList.contains(lenya));
70: assertTrue(usersList.contains(alice));
71: }
72: }
73:
74: }
|