001/*
002 * Copyright (c) 2006-2013 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Anahide Tchertchian
011 *     Florent Guillaume
012 */
013
014package org.nuxeo.ecm.core.security;
015
016import org.nuxeo.ecm.core.query.sql.model.SQLQuery.Transformer;
017
018/**
019 * Abstract security policy
020 *
021 * @author Anahide Tchertchian
022 * @author Florent Guillaume
023 */
024public abstract class AbstractSecurityPolicy implements SecurityPolicy {
025
026    @Override
027    public boolean isRestrictingPermission(String permission) {
028        // by default, we don't know, so yes
029        return true;
030    }
031
032    @Override
033    public Transformer getQueryTransformer(String repositoryName) {
034        return getQueryTransformer();
035    }
036
037    /**
038     * Legacy method for compatibility, use {@link #getQueryTransformer(String)} instead
039     */
040    @Deprecated
041    public Transformer getQueryTransformer() {
042        // implement this if isExpressibleInQuery is true
043        throw new UnsupportedOperationException();
044    }
045
046    @Override
047    public QueryTransformer getQueryTransformer(String repositoryName, String queryLanguage) {
048        /*
049         * By default in this abstract class: If we're expressible in NXQL and the query transformer is IDENTITY, then
050         * express as QueryTransformer.IDENTITY in any language.
051         */
052        if (isExpressibleInQuery(repositoryName) && getQueryTransformer(repositoryName) == Transformer.IDENTITY) {
053            return QueryTransformer.IDENTITY;
054        }
055        // else we don't know how to transform
056        throw new UnsupportedOperationException(queryLanguage);
057    }
058
059    @Override
060    public boolean isExpressibleInQuery(String repositoryName) {
061        return isExpressibleInQuery();
062    }
063
064    /**
065     * Legacy method for compatibility, use {@link #isExpressibleInQuery(String)} instead
066     */
067    @Deprecated
068    public boolean isExpressibleInQuery() {
069        // by default, we don't know, so no
070        return false;
071    }
072
073    @Override
074    public boolean isExpressibleInQuery(String repositoryName, String queryLanguage) {
075        /*
076         * By default in this abstract class: If we're expressible in NXQL and the query transformer is IDENTITY, then
077         * we're expressible (as QueryTransformer.IDENTITY) in any language.
078         */
079        return isExpressibleInQuery(repositoryName) && getQueryTransformer(repositoryName) == Transformer.IDENTITY;
080    }
081
082}