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.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    }