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;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.security.pacl.checker.Checker;
020    import com.liferay.portal.security.pacl.checker.JNDIChecker;
021    import com.liferay.portal.security.pacl.checker.SQLChecker;
022    
023    import java.security.Permission;
024    
025    import java.util.Properties;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     * @author Raymond Augé
030     */
031    public class ActivePACLPolicy extends BasePACLPolicy {
032    
033            public ActivePACLPolicy(
034                    String servletContextName, ClassLoader classLoader,
035                    Properties properties) {
036    
037                    super(servletContextName, classLoader, properties);
038    
039                    try {
040                            initJNDIChecker();
041                            initSQLChecker();
042                    }
043                    catch (Exception e) {
044                            _log.error(e, e);
045                    }
046            }
047    
048            public JNDIChecker getJndiChecker() {
049                    return _jndiChecker;
050            }
051    
052            public SQLChecker getSqlChecker() {
053                    return _sqlChecker;
054            }
055    
056            public boolean hasJNDI(String name) {
057                    return _jndiChecker.hasJNDI(name);
058            }
059    
060            public boolean hasSQL(String sql) {
061                    return _sqlChecker.hasSQL(sql);
062            }
063    
064            public boolean implies(Permission permission) {
065                    Checker checker = getChecker(permission.getClass());
066    
067                    return checker.implies(permission);
068            }
069    
070            public boolean isActive() {
071                    return true;
072            }
073    
074            protected void initJNDIChecker() {
075                    _jndiChecker = new JNDIChecker();
076    
077                    initChecker(_jndiChecker);
078            }
079    
080            protected void initSQLChecker() {
081                    _sqlChecker = new SQLChecker();
082    
083                    initChecker(_sqlChecker);
084            }
085    
086            private static Log _log = LogFactoryUtil.getLog(ActivePACLPolicy.class);
087    
088            private JNDIChecker _jndiChecker;
089            private SQLChecker _sqlChecker;
090    
091    }