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.kernel.security.pacl.permission;
016    
017    import com.liferay.portal.kernel.security.pacl.PACLConstants;
018    
019    import java.security.BasicPermission;
020    import java.security.Permission;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class PortalRuntimePermission extends BasicPermission {
026    
027            public static void checkExpandoBridge(String className) {
028                    SecurityManager securityManager = System.getSecurityManager();
029    
030                    if (securityManager == null) {
031                            return;
032                    }
033    
034                    Permission permission = new PortalRuntimePermission(
035                            PACLConstants.PORTAL_RUNTIME_PERMISSION_EXPANDO_BRIDGE, className);
036    
037                    securityManager.checkPermission(permission);
038            }
039    
040            public static void checkGetBeanProperty(Class<?> clazz) {
041                    checkGetBeanProperty(clazz, null);
042            }
043    
044            public static void checkGetBeanProperty(Class<?> clazz, String property) {
045                    SecurityManager securityManager = System.getSecurityManager();
046    
047                    if (securityManager == null) {
048                            return;
049                    }
050    
051                    Permission permission = new PortalRuntimePermission(
052                            PACLConstants.PORTAL_RUNTIME_PERMISSION_GET_BEAN_PROPERTY, clazz,
053                            property);
054    
055                    securityManager.checkPermission(permission);
056            }
057    
058            public static void checkSearchEngine(String searchEngineId) {
059                    SecurityManager securityManager = System.getSecurityManager();
060    
061                    if (securityManager == null) {
062                            return;
063                    }
064    
065                    Permission permission = new PortalRuntimePermission(
066                            PACLConstants.PORTAL_RUNTIME_PERMISSION_SEARCH_ENGINE,
067                            searchEngineId);
068    
069                    securityManager.checkPermission(permission);
070            }
071    
072            public static void checkSetBeanProperty(Class<?> clazz) {
073                    checkSetBeanProperty(clazz, null);
074            }
075    
076            public static void checkSetBeanProperty(Class<?> clazz, String property) {
077                    SecurityManager securityManager = System.getSecurityManager();
078    
079                    if (securityManager == null) {
080                            return;
081                    }
082    
083                    Permission permission = new PortalRuntimePermission(
084                            PACLConstants.PORTAL_RUNTIME_PERMISSION_SET_BEAN_PROPERTY, clazz,
085                            property);
086    
087                    securityManager.checkPermission(permission);
088            }
089    
090            public PortalRuntimePermission(String name, Object subject) {
091                    this(name, subject, null);
092            }
093    
094            public PortalRuntimePermission(
095                    String name, Object subject, String property) {
096    
097                    super(name);
098    
099                    _property = property;
100                    _subject = subject;
101            }
102    
103            public String getProperty() {
104                    return _property;
105            }
106    
107            public Object getSubject() {
108                    return _subject;
109            }
110    
111            private String _property;
112            private Object _subject;
113    
114    }