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     * @author Raymond Augé
034     */
035    public class ActivePACLPolicy extends BasePACLPolicy {
036    
037            public ActivePACLPolicy(
038                    String servletContextName, ClassLoader classLoader,
039                    Properties properties) {
040    
041                    super(servletContextName, classLoader, properties);
042    
043                    try {
044                            initJNDIChecker();
045                            initPortalServiceChecker();
046                            initSQLChecker();
047                    }
048                    catch (Exception e) {
049                            _log.error(e, e);
050                    }
051            }
052    
053            public void checkPermission(Permission permission) {
054                    Checker checker = getChecker(permission.getClass());
055    
056                    checker.checkPermission(permission);
057            }
058    
059            public JNDIChecker getJndiChecker() {
060                    return _jndiChecker;
061            }
062    
063            public PortalServiceChecker getPortalServiceChecker() {
064                    return _portalServiceChecker;
065            }
066    
067            public SQLChecker getSqlChecker() {
068                    return _sqlChecker;
069            }
070    
071            public boolean hasJNDI(String name) {
072                    return _jndiChecker.hasJNDI(name);
073            }
074    
075            public boolean hasPortalService(
076                    Object object, Method method, Object[] arguments) {
077    
078                    return _portalServiceChecker.hasService(object, method, arguments);
079            }
080    
081            public boolean hasSQL(String sql) {
082                    return _sqlChecker.hasSQL(sql);
083            }
084    
085            public boolean isActive() {
086                    return true;
087            }
088    
089            protected void initJNDIChecker() {
090                    _jndiChecker = new JNDIChecker();
091    
092                    initChecker(_jndiChecker);
093            }
094    
095            protected void initPortalServiceChecker() {
096                    _portalServiceChecker = (PortalServiceChecker)getChecker(
097                            PortalServicePermission.class);
098    
099                    if (_portalServiceChecker == null) {
100                            _portalServiceChecker = new PortalServiceChecker();
101    
102                            initChecker(_portalServiceChecker);
103                    }
104            }
105    
106            protected void initSQLChecker() {
107                    _sqlChecker = new SQLChecker();
108    
109                    initChecker(_sqlChecker);
110            }
111    
112            private static Log _log = LogFactoryUtil.getLog(ActivePACLPolicy.class);
113    
114            private JNDIChecker _jndiChecker;
115            private PortalServiceChecker _portalServiceChecker;
116            private SQLChecker _sqlChecker;
117    
118    }