001/* 002 * (C) Copyright 2006-2016 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Anahide Tchertchian 018 * Florent Guillaume 019 */ 020package org.nuxeo.ecm.core.security; 021 022import org.nuxeo.ecm.core.query.sql.model.SQLQuery.Transformer; 023 024/** 025 * Abstract security policy 026 * 027 * @author Anahide Tchertchian 028 * @author Florent Guillaume 029 */ 030public abstract class AbstractSecurityPolicy implements SecurityPolicy { 031 032 @Override 033 public boolean isRestrictingPermission(String permission) { 034 // by default, we don't know, so yes 035 return true; 036 } 037 038 @Override 039 public Transformer getQueryTransformer(String repositoryName) { 040 // implement this if isExpressibleInQuery is true 041 throw new UnsupportedOperationException(); 042 } 043 044 @Override 045 public QueryTransformer getQueryTransformer(String repositoryName, String queryLanguage) { 046 /* 047 * By default in this abstract class: If we're expressible in NXQL and the query transformer is IDENTITY, then 048 * express as QueryTransformer.IDENTITY in any language. 049 */ 050 if (isExpressibleInQuery(repositoryName) && getQueryTransformer(repositoryName) == Transformer.IDENTITY) { 051 return QueryTransformer.IDENTITY; 052 } 053 // else we don't know how to transform 054 throw new UnsupportedOperationException(queryLanguage); 055 } 056 057 @Override 058 public boolean isExpressibleInQuery(String repositoryName) { 059 // by default, we don't know, so no 060 return false; 061 } 062 063 @Override 064 public boolean isExpressibleInQuery(String repositoryName, String queryLanguage) { 065 /* 066 * By default in this abstract class: If we're expressible in NXQL and the query transformer is IDENTITY, then 067 * we're expressible (as QueryTransformer.IDENTITY) in any language. 068 */ 069 return isExpressibleInQuery(repositoryName) && getQueryTransformer(repositoryName) == Transformer.IDENTITY; 070 } 071 072}