]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
8f5d285d59171d1ffc0c97a4ec12897df7647cd1
[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 package org.collectionspace.services.authorization.test;
47
48 import java.util.ArrayList;
49 import java.util.List;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
52 import org.collectionspace.services.authorization.AuthZ;
53 import org.collectionspace.services.authorization.Permission;
54 import org.collectionspace.services.authorization.PermissionRole;
55 import org.collectionspace.services.authorization.PermissionsList;
56 import org.collectionspace.services.authorization.PermissionsRolesList;
57 import org.springframework.transaction.TransactionStatus;
58 import org.testng.annotations.BeforeClass;
59
60 /**
61  *
62  * @author 
63  */
64 public class AuthorizationSeedTest extends AbstractAuthorizationTestImpl {
65
66     final Logger logger = LoggerFactory.getLogger(AuthorizationSeedTest.class);
67
68     @BeforeClass(alwaysRun = true)
69     public void seedData() {
70         setup();
71         TransactionStatus status = beginTransaction("seedData");
72         try {
73             AuthorizationGen authzGen = new AuthorizationGen();
74             authzGen.genPermissions();
75             authzGen.genPermissionsRoles();
76             seedRoles();
77             seedPermissions();
78         } catch (Exception ex) {
79             rollbackTransaction(status);
80             ex.printStackTrace();
81             throw new RuntimeException(ex);
82         }
83         commitTransaction(status);
84     }
85
86     public void seedRoles() throws Exception {
87     }
88
89     public void seedPermissions() throws Exception {
90
91         PermissionsList pcList =
92                 (PermissionsList) fromFile(PermissionsList.class,
93                 AbstractAuthorizationTestImpl.testDataDir + "test-permissions.xml");
94         logger.info("read permissions from "
95                 + AbstractAuthorizationTestImpl.testDataDir + "test-permissions.xml");
96         PermissionsRolesList pcrList =
97                 (PermissionsRolesList) fromFile(PermissionsRolesList.class,
98                 AbstractAuthorizationTestImpl.testDataDir + "test-permissions-roles.xml");
99         logger.info("read permissions-roles from "
100                 + AbstractAuthorizationTestImpl.testDataDir + "test-permissions.xml");
101         AuthZ authZ = AuthZ.get();
102         for (Permission p : pcList.getPermissions()) {
103             if (logger.isDebugEnabled()) {
104                 logger.debug("adding permission for res=" + p.getResourceName());
105             }
106             for (PermissionRole pr : pcrList.getPermissionRoles()) {
107                 if (pr.getPermissions().get(0).getPermissionId().equals(p.getCsid())) {
108                     authZ.addPermissions(p, pr);
109                 }
110             }
111         }
112     }
113 }