]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
63781455c1c3b0bb3db1f89f1858ebbf1aa11374
[tmp/jakarta-migration.git] /
1 /**
2  *  This document is a part of the source code and related artifacts
3  *  for CollectionSpace, an open source collections management system
4  *  for museums and related institutions:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
18  *  Unless required by applicable law or agreed to in writing, software
19  *  distributed under the License is distributed on an "AS IS" BASIS,
20  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  *  See the License for the specific language governing permissions and
22  *  limitations under the License.
23  *//**
24  *  This document is a part of the source code and related artifacts
25  *  for CollectionSpace, an open source collections management system
26  *  for museums and related institutions:
27
28  *  http://www.collectionspace.org
29  *  http://wiki.collectionspace.org
30
31  *  Copyright 2009 University of California at Berkeley
32
33  *  Licensed under the Educational Community License (ECL), Version 2.0.
34  *  You may not use this file except in compliance with this License.
35
36  *  You may obtain a copy of the ECL 2.0 License at
37
38  *  https://source.collectionspace.org/collection-space/LICENSE.txt
39
40  *  Unless required by applicable law or agreed to in writing, software
41  *  distributed under the License is distributed on an "AS IS" BASIS,
42  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43  *  See the License for the specific language governing permissions and
44  *  limitations under the License.
45  */
46
47 package org.collectionspace.services.authorization.test;
48
49 import java.util.ArrayList;
50 import java.util.List;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53 import org.collectionspace.services.authorization.AuthZ;
54 import org.collectionspace.services.authorization.Permission;
55 import org.collectionspace.services.authorization.PermissionRole;
56 import org.collectionspace.services.authorization.PermissionsList;
57 import org.collectionspace.services.authorization.PermissionsRolesList;
58 import org.springframework.transaction.TransactionStatus;
59 import org.testng.annotations.BeforeClass;
60
61 /**
62  *
63  * @author 
64  */
65 public class AuthorizationSeedTest extends AbstractAuthorizationTestImpl {
66
67     final Logger logger = LoggerFactory.getLogger(AuthorizationSeedTest.class);
68
69     @BeforeClass(alwaysRun = true)
70     public void seedData() {
71         setup();
72         TransactionStatus status = beginTransaction("seedData");
73         try {
74             seedRoles();
75             seedPermissions();
76         } catch (Exception ex) {
77             rollbackTransaction(status);
78             ex.printStackTrace();
79             throw new RuntimeException(ex);
80         }
81         commitTransaction(status);
82     }
83
84     public void seedRoles() throws Exception {
85     }
86
87     public void seedPermissions() throws Exception {
88
89         PermissionsList pcList =
90                 (PermissionsList) fromFile(PermissionsList.class,
91                 "./test-data/test-permissions.xml");
92
93         PermissionsRolesList pcrList =
94                 (PermissionsRolesList) fromFile(PermissionsRolesList.class,
95                 "./test-data/test-permissions-roles.xml");
96
97         AuthZ authZ = AuthZ.get();
98         for (Permission p : pcList.getPermissions()) {
99             if (logger.isDebugEnabled()) {
100                 logger.debug("adding permission for res=" + p.getResourceName());
101             }
102             List<PermissionRole> prl = getPermissionRoles(pcrList, p.getCsid());
103             authZ.addPermissions(p, prl);
104         }
105     }
106
107     private List<PermissionRole> getPermissionRoles(PermissionsRolesList pcrList, String permId) {
108         List<PermissionRole> prList = new ArrayList<PermissionRole>();
109         for (PermissionRole pr : pcrList.getPermissionRoles()) {
110             if (pr.getPermissionId().equals(permId)) {
111                 prList.add(pr);
112             }
113         }
114         return prList;
115     }
116 }