001    /**
002     * Copyright (c) 2000-2012 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.kernel.security.pacl.permission.PortalServicePermission;
020    import com.liferay.portal.security.pacl.checker.Checker;
021    import com.liferay.portal.security.pacl.checker.JNDIChecker;
022    import com.liferay.portal.security.pacl.checker.PortalServiceChecker;
023    import com.liferay.portal.security.pacl.checker.SQLChecker;
024    
025    import java.lang.reflect.Method;
026    
027    import java.security.Permission;
028    
029    import java.util.Properties;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     */
034    public class ActivePACLPolicy extends BasePACLPolicy {
035    
036            public ActivePACLPolicy(
037                    String servletContextName, ClassLoader classLoader,
038                    Properties properties) {
039    
040                    super(servletContextName, classLoader, properties);
041    
042                    try {
043                            initJNDIChecker();
044                            initPortalServiceChecker();
045                            initSQLChecker();
046                    }
047                    catch (Exception e) {
048                            _log.error(e, e);
049                    }
050            }
051    
052            public void checkPermission(Permission permission) {
053                    Checker checker = getChecker(permission.getClass());
054    
055                    checker.checkPermission(permission);
056            }
057    
058            public boolean hasJNDI(String name) {
059                    return _jndiChecker.hasJNDI(name);
060            }
061    
062            public boolean hasPortalService(
063                    Object object, Method method, Object[] arguments) {
064    
065                    return _portalServiceChecker.hasService(object, method, arguments);
066            }
067    
068            public boolean hasSQL(String sql) {
069                    return _sqlChecker.hasSQL(sql);
070            }
071    
072            public boolean isActive() {
073                    return true;
074            }
075    
076            protected void initJNDIChecker() {
077                    _jndiChecker = new JNDIChecker();
078    
079                    initChecker(_jndiChecker);
080            }
081    
082            protected void initPortalServiceChecker() {
083                    _portalServiceChecker = (PortalServiceChecker)getChecker(
084                            PortalServicePermission.class);
085    
086                    if (_portalServiceChecker == null) {
087                            _portalServiceChecker = new PortalServiceChecker();
088    
089                            initChecker(_portalServiceChecker);
090                    }
091            }
092    
093            protected void initSQLChecker() {
094                    _sqlChecker = new SQLChecker();
095    
096                    initChecker(_sqlChecker);
097            }
098    
099            private static Log _log = LogFactoryUtil.getLog(ActivePACLPolicy.class);
100    
101            private JNDIChecker _jndiChecker;
102            private PortalServiceChecker _portalServiceChecker;
103            private SQLChecker _sqlChecker;
104    
105    }