001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.security.pacl.checker;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.security.pacl.PACLConstants;
019    import com.liferay.portal.kernel.util.JavaDetector;
020    import com.liferay.portal.security.pacl.PACLPolicy;
021    import com.liferay.portal.security.pacl.PACLUtil;
022    
023    import java.security.Permission;
024    
025    import java.util.Properties;
026    import java.util.Set;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     * @author Raymond Augé
031     */
032    public abstract class BaseChecker implements Checker, PACLConstants {
033    
034            public AuthorizationProperty generateAuthorizationProperty(
035                    Object... arguments) {
036    
037                    throw new UnsupportedOperationException();
038            }
039    
040            public ClassLoader getClassLoader() {
041                    return _paclPolicy.getClassLoader();
042            }
043    
044            public PACLPolicy getPACLPolicy() {
045                    return _paclPolicy;
046            }
047    
048            public String getServletContextName() {
049                    return _paclPolicy.getServletContextName();
050            }
051    
052            public int getStackIndex(int oracle, int ibm) {
053                    return getStackIndex(oracle, ibm, ibm);
054            }
055    
056            public int getStackIndex(int oracle, int ibm, int ibm7) {
057                    if (JavaDetector.isIBM()) {
058                            if (JavaDetector.isJDK6()) {
059                                    return ibm;
060                            }
061    
062                            return ibm7;
063                    }
064    
065                    return oracle;
066            }
067    
068            public boolean isTrustedCaller(
069                    Class<?> callerClass, Permission permission) {
070    
071                    return PACLUtil.isTrustedCaller(
072                            callerClass, permission, getPACLPolicy());
073            }
074    
075            public void setPACLPolicy(PACLPolicy paclPolicy) {
076                    _paclPolicy = paclPolicy;
077            }
078    
079            protected Properties getProperties() {
080                    return _paclPolicy.getProperties();
081            }
082    
083            protected String getProperty(String key) {
084                    return _paclPolicy.getProperty(key);
085            }
086    
087            protected String[] getPropertyArray(String key) {
088                    return _paclPolicy.getPropertyArray(key);
089            }
090    
091            protected boolean getPropertyBoolean(String key) {
092                    return _paclPolicy.getPropertyBoolean(key);
093            }
094    
095            protected Set<String> getPropertySet(String key) {
096                    return _paclPolicy.getPropertySet(key);
097            }
098    
099            protected void logSecurityException(Log log, String message) {
100                    if (log.isWarnEnabled()) {
101                            log.warn(message);
102                    }
103            }
104    
105            private PACLPolicy _paclPolicy;
106    
107    }