package com.palmnest.webapp.taglib;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.Arrays;
import java.util.List;

/**
 * 权限校验标签
 *
 * @Author HIAPAD
 * @Description TODO
 * @Date 2018/10/24 16:58
 **/
@Slf4j
public class PermissionTag extends TagSupport {

	private static final long serialVersionUID = -4269847072894077529L;


	// 权限字符串
	private String permCode;

	@Override
	public int doStartTag() throws JspException {

		// 获取用户权限字符串
		String userPerms = (String) pageContext.getSession().getAttribute("UserPerms");

		List<String> permArr = Arrays.asList(userPerms.split(","));

		if (permArr.contains(permCode)) {
			return EVAL_PAGE;
		}

		return SKIP_BODY;
	}

	public String getPermCode() {
		return permCode;
	}

	public void setPermCode(String permCode) {
		this.permCode = permCode;
	}
}
