001    /**
002     * Copyright (c) 2000-2013 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.auth;
016    
017    import com.liferay.portal.kernel.exception.SystemException;
018    import com.liferay.portal.kernel.util.PropsKeys;
019    import com.liferay.portal.util.PortalUtil;
020    import com.liferay.portal.util.PrefsPropsUtil;
021    import com.liferay.portal.util.PropsValues;
022    
023    import java.util.Set;
024    
025    import javax.servlet.http.HttpServletRequest;
026    
027    /**
028     * @author Michael C. Han
029     */
030    public class AuthSettingsUtil {
031    
032            public static boolean isAccessAllowed(
033                    HttpServletRequest request, Set<String> hostsAllowed) {
034    
035                    if (hostsAllowed.isEmpty()) {
036                            return true;
037                    }
038    
039                    String remoteAddr = request.getRemoteAddr();
040    
041                    if (hostsAllowed.contains(remoteAddr)) {
042                            return true;
043                    }
044    
045                    String computerAddress = PortalUtil.getComputerAddress();
046    
047                    if (computerAddress.equals(remoteAddr) &&
048                            hostsAllowed.contains(_SERVER_IP)) {
049    
050                            return true;
051                    }
052    
053                    return false;
054            }
055    
056            public static boolean isLDAPAuthEnabled(long companyId)
057                    throws SystemException {
058    
059                    if (PrefsPropsUtil.getBoolean(
060                                    companyId, PropsKeys.LDAP_AUTH_ENABLED,
061                                    PropsValues.LDAP_AUTH_ENABLED)) {
062    
063                            return true;
064                    }
065                    else {
066                            return false;
067                    }
068            }
069    
070            public static boolean isNtlmEnabled(long companyId) throws SystemException {
071                    if (PrefsPropsUtil.getBoolean(
072                                    companyId, PropsKeys.NTLM_AUTH_ENABLED,
073                                    PropsValues.NTLM_AUTH_ENABLED)) {
074    
075                            return true;
076                    }
077                    else {
078                            return false;
079                    }
080            }
081    
082            public static boolean isSiteMinderEnabled(long companyId)
083                    throws SystemException {
084    
085                    if (PrefsPropsUtil.getBoolean(
086                                    companyId, PropsKeys.SITEMINDER_AUTH_ENABLED,
087                                    PropsValues.SITEMINDER_AUTH_ENABLED)) {
088    
089                            return true;
090                    }
091                    else {
092                            return false;
093                    }
094            }
095    
096            private static final String _SERVER_IP = "SERVER_IP";
097    
098    }