001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.security.pacl.checker;
016    
017    import java.security.Permission;
018    
019    import java.util.ArrayList;
020    import java.util.List;
021    import java.util.Set;
022    import java.util.regex.Matcher;
023    import java.util.regex.Pattern;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class JNDIChecker extends BaseChecker {
029    
030            public void afterPropertiesSet() {
031                    initNames();
032            }
033    
034            public void checkPermission(Permission permission) {
035                    throw new UnsupportedOperationException();
036            }
037    
038            public boolean hasJNDI(String name) {
039                    for (Pattern pattern : _patterns) {
040                            Matcher matcher = pattern.matcher(name);
041    
042                            if (matcher.matches()) {
043                                    return true;
044                            }
045                    }
046    
047                    return false;
048            }
049    
050            protected void initNames() {
051                    Set<String> names = getPropertySet("security-manager-jndi-names");
052    
053                    _patterns = new ArrayList<Pattern>(names.size());
054    
055                    for (String name : names) {
056                            Pattern pattern = Pattern.compile(name);
057    
058                            _patterns.add(pattern);
059                    }
060            }
061    
062            private List<Pattern> _patterns;
063    
064    }