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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
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:
28 * http://www.collectionspace.org
29 * http://wiki.collectionspace.org
31 * Copyright 2009 University of California at Berkeley
33 * Licensed under the Educational Community License (ECL), Version 2.0.
34 * You may not use this file except in compliance with this License.
36 * You may obtain a copy of the ECL 2.0 License at
38 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
46 package org.collectionspace.services.authorization.test;
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;
67 public class AuthorizationGen {
69 final Logger logger = LoggerFactory.getLogger(AuthorizationGen.class);
71 public void genPermissions() {
72 PermissionsList pcList = new PermissionsList();
73 ArrayList<Permission> apcList = new ArrayList<Permission>();
74 pcList.setPermissions(apcList);
76 Permission accPerm = buildCommonPermission("1", "accounts");
78 Permission coPerm = buildCommonPermission("2", "collectionobjects");
80 AbstractAuthorizationTestImpl.toFile(pcList, PermissionsList.class,
81 AbstractAuthorizationTestImpl.testDataDir + "test-permissions.xml");
82 logger.info("generated permissions to "
83 + AbstractAuthorizationTestImpl.testDataDir + "test-permissions.xml");
87 private Permission buildCommonPermission(String id, String resourceName) {
88 Permission perm = new Permission();
90 perm.setResourceName(resourceName);
91 perm.setEffect(EffectType.PERMIT);
93 ArrayList<PermissionAction> pas = new ArrayList<PermissionAction>();
96 PermissionAction pa = new PermissionAction();
97 pa.setName(ActionType.CREATE);
99 PermissionAction pa1 = new PermissionAction();
100 pa1.setName(ActionType.READ);
102 PermissionAction pa2 = new PermissionAction();
103 pa2.setName(ActionType.UPDATE);
105 PermissionAction pa3 = new PermissionAction();
106 pa3.setName(ActionType.DELETE);
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");
123 private PermissionRole buildCommonPermissionRoles(String id, String resName) {
125 PermissionRole pr = new PermissionRole();
126 pr.setSubject(SubjectType.ROLE);
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);
135 List<RoleValue> roleValues = new ArrayList<RoleValue>();
136 RoleValue rv1 = new RoleValue();
137 rv1.setRoleName("ROLE_USERS");
140 RoleValue rv2 = new RoleValue();
141 rv2.setRoleName("ROLE_ADMINISTRATOR");
144 pr.setRoles(roleValues);