/* * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Contributors: * Florent Guillaume */ package org.nuxeo.ecm.core.opencmis.impl; import java.security.Principal; import org.nuxeo.ecm.core.api.security.ACP; import org.nuxeo.ecm.core.api.security.Access; import org.nuxeo.ecm.core.api.security.SecurityConstants; import org.nuxeo.ecm.core.model.Document; import org.nuxeo.ecm.core.security.AbstractSecurityPolicy; /** * Test security policy that forbids titles starting with SECRET. * * @since 5.7.2 */ public class TitleFilteringSecurityPolicy extends AbstractSecurityPolicy { protected static final String PREFIX = "SECRET"; @Override public Access checkPermission(Document doc, ACP mergedAcp, Principal principal, String permission, String[] resolvedPermissions, String[] additionalPrincipals) { if (!isRestrictingPermission(permission)) { return Access.UNKNOWN; } String title = (String) doc.getPropertyValue("dc:title"); if (title != null && title.startsWith(PREFIX)) { return Access.DENY; } return Access.UNKNOWN; } @Override public boolean isRestrictingPermission(String permission) { return permission.equals(SecurityConstants.BROWSE); } @Override public boolean isExpressibleInQuery(String repositoryName) { return false; } }