]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
aa03956af5db82d343d7666571616cb000d8907f
[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 org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50 import java.util.ArrayList;
51 import java.util.List;
52 import org.collectionspace.services.authorization.ActionType;
53 import org.collectionspace.services.authorization.Permission;
54 import org.collectionspace.services.authorization.EffectType;
55 import org.collectionspace.services.authorization.PermissionAction;
56 import org.collectionspace.services.authorization.PermissionRole;
57 import org.collectionspace.services.authorization.PermissionValue;
58 import org.collectionspace.services.authorization.PermissionsList;
59 import org.collectionspace.services.authorization.PermissionsRolesList;
60 import org.collectionspace.services.authorization.RoleValue;
61 import org.collectionspace.services.authorization.SubjectType;
62
63 /**
64  *
65  * @author 
66  */
67 public class AuthorizationGen {
68
69     final Logger logger = LoggerFactory.getLogger(AuthorizationGen.class);
70
71     public void genPermissions() {
72         PermissionsList pcList = new PermissionsList();
73         ArrayList<Permission> apcList = new ArrayList<Permission>();
74         pcList.setPermissions(apcList);
75
76         Permission accPerm = buildCommonPermission("1", "accounts");
77         apcList.add(accPerm);
78         Permission coPerm = buildCommonPermission("2", "collectionobjects");
79         apcList.add(coPerm);
80         AbstractAuthorizationTestImpl.toFile(pcList, PermissionsList.class,
81                 AbstractAuthorizationTestImpl.testDataDir + "test-permissions.xml");
82         logger.info("generated permissions to "
83                 + AbstractAuthorizationTestImpl.testDataDir + "test-permissions.xml");
84
85     }
86
87     private Permission buildCommonPermission(String id, String resourceName) {
88         Permission perm = new Permission();
89         perm.setCsid(id);
90         perm.setResourceName(resourceName);
91         perm.setEffect(EffectType.PERMIT);
92         perm.setTenantId("1");
93         ArrayList<PermissionAction> pas = new ArrayList<PermissionAction>();
94         perm.setActions(pas);
95
96         PermissionAction pa = new PermissionAction();
97         pa.setName(ActionType.CREATE);
98         pas.add(pa);
99         PermissionAction pa1 = new PermissionAction();
100         pa1.setName(ActionType.READ);
101         pas.add(pa1);
102         PermissionAction pa2 = new PermissionAction();
103         pa2.setName(ActionType.UPDATE);
104         pas.add(pa2);
105         PermissionAction pa3 = new PermissionAction();
106         pa3.setName(ActionType.DELETE);
107         pas.add(pa3);
108         return perm;
109     }
110
111     public void genPermissionsRoles() {
112         PermissionsRolesList psrsl = new PermissionsRolesList();
113         ArrayList<PermissionRole> prl = new ArrayList<PermissionRole>();
114         prl.add(buildCommonPermissionRoles("1", "accounts"));
115         prl.add(buildCommonPermissionRoles("2", "collectionobjects"));
116         psrsl.setPermissionRoles(prl);
117         AbstractAuthorizationTestImpl.toFile(psrsl, PermissionsRolesList.class,
118                 AbstractAuthorizationTestImpl.testDataDir + "test-permissions-roles.xml");
119         logger.info("generated permissions-roles to "
120                 + AbstractAuthorizationTestImpl.testDataDir + "test-permissions-roles.xml");
121     }
122
123     private PermissionRole buildCommonPermissionRoles(String id, String resName) {
124
125         PermissionRole pr = new PermissionRole();
126         pr.setSubject(SubjectType.ROLE);
127
128         List<PermissionValue> permValues = new ArrayList<PermissionValue>();
129         pr.setPermissions(permValues);
130         PermissionValue permValue = new PermissionValue();
131         permValue.setPermissionId(id);
132         permValue.setResourceName(resName);
133         permValues.add(permValue);
134
135         List<RoleValue> roleValues = new ArrayList<RoleValue>();
136         RoleValue rv1 = new RoleValue();
137         rv1.setRoleName("ROLE_USERS");
138         rv1.setRoleId("1");
139         roleValues.add(rv1);
140         RoleValue rv2 = new RoleValue();
141         rv2.setRoleName("ROLE_ADMINISTRATOR");
142         rv2.setRoleId("2");
143         roleValues.add(rv2);
144         pr.setRoles(roleValues);
145
146         return pr;
147
148     }
149 }