001/* 002 * (C) Copyright 2006-2013 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 */ 020 021package org.nuxeo.ecm.core.security; 022 023import org.nuxeo.ecm.core.query.sql.model.SQLQuery.Transformer; 024 025/** 026 * Abstract security policy 027 * 028 * @author Anahide Tchertchian 029 * @author Florent Guillaume 030 */ 031public abstract class AbstractSecurityPolicy implements SecurityPolicy { 032 033 @Override 034 public boolean isRestrictingPermission(String permission) { 035 // by default, we don't know, so yes 036 return true; 037 } 038 039 @Override 040 public Transformer getQueryTransformer(String repositoryName) { 041 return getQueryTransformer(); 042 } 043 044 /** 045 * Legacy method for compatibility, use {@link #getQueryTransformer(String)} instead 046 */ 047 @Deprecated 048 public Transformer getQueryTransformer() { 049 // implement this if isExpressibleInQuery is true 050 throw new UnsupportedOperationException(); 051 } 052 053 @Override 054 public QueryTransformer getQueryTransformer(String repositoryName, String queryLanguage) { 055 /* 056 * By default in this abstract class: If we're expressible in NXQL and the query transformer is IDENTITY, then 057 * express as QueryTransformer.IDENTITY in any language. 058 */ 059 if (isExpressibleInQuery(repositoryName) && getQueryTransformer(repositoryName) == Transformer.IDENTITY) { 060 return QueryTransformer.IDENTITY; 061 } 062 // else we don't know how to transform 063 throw new UnsupportedOperationException(queryLanguage); 064 } 065 066 @Override 067 public boolean isExpressibleInQuery(String repositoryName) { 068 return isExpressibleInQuery(); 069 } 070 071 /** 072 * Legacy method for compatibility, use {@link #isExpressibleInQuery(String)} instead 073 */ 074 @Deprecated 075 public boolean isExpressibleInQuery() { 076 // by default, we don't know, so no 077 return false; 078 } 079 080 @Override 081 public boolean isExpressibleInQuery(String repositoryName, String queryLanguage) { 082 /* 083 * By default in this abstract class: If we're expressible in NXQL and the query transformer is IDENTITY, then 084 * we're expressible (as QueryTransformer.IDENTITY) in any language. 085 */ 086 return isExpressibleInQuery(repositoryName) && getQueryTransformer(repositoryName) == Transformer.IDENTITY; 087 } 088 089}