User authentication based on JSP custom tags

Source: Internet
Author: User

The total is divided into 4 parts:

1. Custom Label Permissiontaghandler application scenario

2, the realization of Permissiontaghandler class

3, Configuration Permissiontaghandler

4. Using Permissiontaghandler

1. Custom Label Permissiontaghandler application scenario

User list userlist.do required, view permissions UserList

2, the realization of Permissiontaghandler class

Import Com.cicc.admin.adminconstant;import Com.cicc.enums.permission;import Java.io.ioexception;import Java.util.arrays;import Java.util.set;import Java.util.list;import Java.util.stream.collectors;import Javax.servlet.jsp.jspcontext;import Javax.servlet.jsp.jspexception;import Javax.servlet.jsp.pagecontext;import javax.servlet.jsp.tagext.simpletagsupport;/** * * @author SUPERXG */public class Permissiontaghandler extends    Simpletagsupport {private String permissions; @Override public void Dotag () throws Jspexception, IOException {set<permission> granted = Getgrantedpermi        Ssions (); if (permissions = null && granted! = null) {list<permission> permissionlist = arrays.aslist (per            Missions.split (",")). Stream (). Map (X-permission.valueof (x)). Collect (Collectors.tolist ());            if (Permissionlist.stream (). AnyMatch (x, Granted.contains (x))) {Getjspbody (). Invoke (null); }}} public void SEtpermissions (String permissions) {this.permissions = permissions; /** * Get permission to the currently logged in employee * * @return */private set<permission> getgrantedpermissions () {Em        Ployeebeansession session = GetSession ();        if (session! = NULL) {return session.getpermissions ();        } else {return null;  }}/** * Gets the current session * * @return */private Employeebeansession getsession () {Jspcontext        context = Getjspcontext ();        Object session = Context.getattribute (Adminconstant.session_key, Pagecontext.session_scope);        if (session! = NULL && session instanceof Employeebeansession) {return (employeebeansession) session;    } return null; }}

  

3, Configuration Permissiontaghandler

<?xml version= "1.0" encoding= "UTF-8"? ><taglib version= "2.1" xmlns= "Http://java.sun.com/xml/ns/javaee" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http ://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd ">    <tlib-version>1.0</tlib-version>    <short-name>gg</short-name>    <uri>/WEB-INF/tld/platform</uri>    <tag>        <name>permission</name>        <tag-class>com.cicc.admin.web.permissiontaghandler</ tag-class>        <body-content>scriptless</body-content>        <attribute>            <name> permissions</name>            <required>false</required>            <type>java.lang.string</type >        </attribute>    </tag></taglib>

  

4. Using Permissiontaghandler

<gg:permissionPermissions= "User_list">                        <LiID= "Li_users_list"<c:if Test= "${modeltype== ' userlist '}">Class= "Active"</c:if>><ahref= "User/list.do"><spanclass= "Glyphicons glyphicons-group"></span>User List</a>                        </Li> </gg:permission>

User authentication based on JSP custom tags

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.