• OA 权限控制


    对于加入删除 初始化password等操作的权限 控制

    第一种方法就是在每一个超链接前加 推断 如

    <s:if test="#session.user.hasPrivilegeByName(name)">
    				<td><s:a action="department_delete?

    id=%{id}&parentId=%{parent.id}" onClick="return window.confirm('这将删除全部的下级部门,您确定要删除吗?')">删除</s:a> <s:a action="department_editUI?id=%{id}">改动</s:a> </td>




    这样的方法须要在每一个a 标签前加推断  太过麻烦

    另一种就是通过改动struts2 <a/>标签的源代码实现  首先在/META-INF/struts-tags.tld文件里找到a 标签

       <name>a</name>
        <tag-class>org.apache.struts2.views.jsp.ui.AnchorTag</tag-class>
        <body-content>JSP</body-content>
        <attribute>
          <description><![CDATA[Set the html accesskey attribute on rendered html element]]></description>
          <name>accesskey</name>
          <required>false</required>
          <rtexprvalue>false</rtexprvalue>
        </attribute>
        <attribute>
          <description><![CDATA[The action to generate the URL for, if not using value]]></description>
          <name>action</name>
          <required>false</required>
          <rtexprvalue>false</rtexprvalue>
        </attribute>......................................................

    .....................................

    第二行有它的实现类找到  copy到自己的src以下 包名什么的都要一样 反复没事,由于它会先去找自己的class再去找jar文件里的

    源代码例如以下:

    public class AnchorTag extends AbstractClosingTag {
    
        private static final long serialVersionUID = -1034616578492431113L;
    
        protected String href;
        protected String includeParams;
        protected String scheme;
        protected String action;
        protected String namespace;
        protected String method;
        protected String encode;
        protected String includeContext;
        protected String escapeAmp;
        protected String portletMode;
        protected String windowState;
        protected String portletUrlType;
        protected String anchor;
        protected String forceAddSchemeHostAndPort;
        
        public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
            return new Anchor(stack, req, res);
        }
        
        protected void populateParams() {
            super.populateParams();
    
            Anchor tag = (Anchor) component;
            tag.setHref(href);
            tag.setIncludeParams(includeParams);
            tag.setScheme(scheme);
            tag.setValue(value);
            tag.setMethod(method);
            tag.setNamespace(namespace);
            tag.setAction(action);
            tag.setPortletMode(portletMode);
            tag.setPortletUrlType(portletUrlType);
            tag.setWindowState(windowState);
            tag.setAnchor(anchor);
    
            if (encode != null) {
                tag.setEncode(Boolean.valueOf(encode).booleanValue());
            }
            if (includeContext != null) {
                tag.setIncludeContext(Boolean.valueOf(includeContext).booleanValue());
            }
            if (escapeAmp != null) {
                tag.setEscapeAmp(Boolean.valueOf(escapeAmp).booleanValue());
            }
    	    if (forceAddSchemeHostAndPort != null) {
                tag.setForceAddSchemeHostAndPort(Boolean.valueOf(forceAddSchemeHostAndPort).booleanValue());
            }
        }
        
        public void setHref(String href) {
            this.href = href;
        }
    
        public void setEncode(String encode) {
            this.encode = encode;
        }    //这里省略好多get set 方法
    然后在自己copy过来的源代码中增加 doEndTag()方法。

    。。

    能够操作s:a标签中的属性,推断权限 等等   增加后代码例如以下

      @Override
    	public int doEndTag() throws JspException {
            //当前用户
            User user=(User) pageContext.getSession().getAttribute("user");     
             
            //当前要显示的权限的相应的url
            String  privUrl=action; //  注意edit 和editUI 都相应edit
        	//去掉后面的參数
            int pos=privUrl.indexOf("?");
        	 if(pos>-1){
        		 privUrl=	privUrl.substring(0, pos); 
        		 
        	 }
        	 //去掉UI
        	 if(privUrl.endsWith("UI")){
        		 
        		privUrl= privUrl.substring(0, privUrl.length()-2);
        	 }
    		if(user.hasPrivilegeByUrl("/"+privUrl)/*有权限吗*/){
    			return super.doEndTag();//正常的生成并显示超链接标签 并继续运行后面的代码
    		}
    		else
    		{
    			
    			return EVAL_PAGE;//什么都不做 (不显示超链接)仅仅是继续运行后面页面的代码
    		}
    		
    	}
        


  • 相关阅读:
    1012 The Best Rank (25 分)(排序)
    1011. World Cup Betting (20)(查找元素)
    1009 Product of Polynomials (25 分)(模拟)
    1008 Elevator (20 分)(数学问题)
    1006 Sign In and Sign Out (25 分)(查找元素)
    1005 Spell It Right (20 分)(字符串处理)
    Kafka Connect 出现ERROR Failed to flush WorkerSourceTask{id=local-file-source-0}, timed out while wait
    flume、kafka、avro组成的消息系统
    Java23种设计模式总结【转载】
    Java编程 思维导图
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/5216703.html
Copyright © 2020-2023  润新知