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.log.LogFactoryUtil;
019    
020    import java.security.Permission;
021    
022    import javax.management.MBeanPermission;
023    import javax.management.MBeanTrustPermission;
024    
025    /**
026     * @author Raymond Augé
027     */
028    public class MBeanChecker extends BaseChecker {
029    
030            public void afterPropertiesSet() {
031            }
032    
033            public boolean implies(Permission permission) {
034                    String name = permission.getName();
035                    String actions = permission.getActions();
036    
037                    if ((permission instanceof MBeanPermission) &&
038                            (actions.equals(MBEAN_PERMISSION_IS_INSTANCE_OF) ||
039                             actions.equals(MBEAN_PERMISSION_REGISTER_MBEAN) ||
040                             actions.equals(MBEAN_PERMISSION_UNREGISTER_MBEAN))) {
041    
042                            return true;
043                    }
044                    else if ((permission instanceof MBeanTrustPermission) &&
045                                     name.equals(MBEAN_TRUST_PERMISSION_REGISTER)) {
046    
047                            return true;
048                    }
049    
050                    logSecurityException(
051                            _log, "Attempted to perform MBean operation " + permission);
052    
053                    return false;
054            }
055    
056            private static Log _log = LogFactoryUtil.getLog(MBeanChecker.class);
057    
058    }