
package org.tio.sitexxx.server.auth;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.List;

/**
 * 
 * @author tanyaowu
 */
public class AccessCtrlService {
	private static Logger log = LoggerFactory.getLogger(AccessCtrlService.class);

	/**
	 * 指定的用户是否可以访问 指定的servletpath
	 * @param accessCtrlConfig
	 * @param servletPath1
	 * @return
	 * @throws IOException
	 */
	public static boolean canAccess(AccessCtrlConfig accessCtrlConfig, String servletPath1) {
		if (accessCtrlConfig == null) {
			log.error("没有配置权限控制，说明不需要进行权限控制");
			return true;
		}

		Object neededRolecodes = accessCtrlConfig.getNeededRolecodes(servletPath1);
		if (neededRolecodes != null) {
			boolean b = false;
			if (neededRolecodes instanceof List) {
				List<String> _neededRolecodes = (List<String>) neededRolecodes;

				for (String neededRolecode : _neededRolecodes) {
					if ("".equals(neededRolecode)) {
						break;
					}
				}
			} else {
				b = "".equals(neededRolecodes);
			}
			return b;
		} else {
			return true;
		}

	}
}
