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.
25 package org.collectionspace.services.authorization.storage;
27 import org.collectionspace.services.authorization.perms.Permission;
28 import org.collectionspace.services.common.ServiceMessages;
29 import org.collectionspace.services.common.context.ServiceContext;
30 import org.collectionspace.services.common.document.DocumentHandler.Action;
31 import org.collectionspace.services.common.document.InvalidDocumentException;
32 import org.collectionspace.services.common.document.ValidatorHandler;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * PermissionValidatorHandler executes validation rules for permission
40 public class PermissionValidatorHandler implements ValidatorHandler {
42 final Logger logger = LoggerFactory.getLogger(PermissionValidatorHandler.class);
45 public void validate(Action action, ServiceContext ctx)
46 throws InvalidDocumentException {
47 if (logger.isDebugEnabled()) {
48 logger.debug("validate() action=" + action.name());
51 Permission permission = (Permission) ctx.getInput();
52 StringBuilder msgBldr = new StringBuilder(ServiceMessages.VALIDATION_FAILURE);
53 boolean invalid = false;
55 if (action.equals(Action.CREATE)) {
57 //create specific validation here
58 if (permission.getResourceName() == null || permission.getResourceName().isEmpty()) {
60 msgBldr.append("\nresourceName : missing or empty");
62 } else if (action.equals(Action.UPDATE)) {
63 //update specific validation here
64 if (permission.getResourceName() == null || permission.getResourceName().isEmpty()) {
66 msgBldr.append("\nresourceName : cannot be missing or empty");
70 String msg = msgBldr.toString();
72 throw new InvalidDocumentException(msg);
74 } catch (InvalidDocumentException ide) {
76 } catch (Exception e) {
77 throw new InvalidDocumentException(e);