WO2020135583A1 - 处理前端页面的权限控制方法及装置 - Google Patents
处理前端页面的权限控制方法及装置 Download PDFInfo
- Publication number
- WO2020135583A1 WO2020135583A1 PCT/CN2019/128695 CN2019128695W WO2020135583A1 WO 2020135583 A1 WO2020135583 A1 WO 2020135583A1 CN 2019128695 W CN2019128695 W CN 2019128695W WO 2020135583 A1 WO2020135583 A1 WO 2020135583A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- control
- page
- authority
- permission
- latest
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/38—Creation or generation of source code for implementing user interfaces
Definitions
- the invention relates to the technical field of authority control, and in particular to an authority control method and device for processing front-end pages.
- page permission control technologies are divided into two categories, including:
- permission control is generally controlled on the server side.
- the common scheme of permission control is RBAC role-based access control.
- the basic idea is that the various permissions involved are not directly granted to specific users, but are in the user set and permission set. Establish a role set. Each role corresponds to a corresponding set of permissions. After a user is assigned an appropriate role, the user has all operation rights for this role.
- the advantage of this is that it is not necessary to perform the operation of assigning permissions every time a user is created, as long as the corresponding role of the user is assigned, and the role permission changes are much less than the user permission changes, which will simplify the user's permissions Management, reduce system overhead.
- the present invention aims to solve one of the technical problems in the related art at least to a certain extent.
- an object of the present invention is to propose a permission control method for processing front-end pages, which effectively improves the intuitiveness, versatility and compatibility of control, and is simple and easy to implement.
- Another object of the present invention is to propose a permission control device for processing front-end pages.
- an embodiment of the present invention provides a permission control method for processing front-end pages, including the following steps: parsing the original HTML document, and parsing the custom tag according to the preset control logic HTML pages perform page rendering and determine whether JavaScript logic code needs to be called; if the JavaScript logic code needs to be called, the calling method of the JavaScript logic code is intercepted; the annotations are parsed according to the calling method to judge based on the parsed annotations Whether the current user has control authority, and is allowed to call when having the control authority.
- the permission control method for processing front-end pages according to an embodiment of the present invention can easily implement permission control of page elements and logic codes according to the keywords of permissions and roles, and permission control of page elements can also meet intuitive requirements and achieve front-end permissions
- the goal of zero control code writing which effectively improves the intuitiveness, versatility and compatibility of control, and is simple and easy to implement.
- the permission control method for processing front-end pages according to the above embodiments of the present invention may also have the following additional technical features:
- the latest permission data before performing page rendering on the original HTML page, it further includes: detecting whether the latest permission data is synchronized; if the latest permission data is not synchronized, then reading After the latest authority data is described, it is parsed and stored in the cache device.
- the method further includes: when the non-page is initialized and the JavaScript logic code needs to be called, the calling method of the JavaScript logic code is intercepted.
- the original HTML page before performing page rendering on the original HTML page, it further includes: detecting whether access to the page requires the control authority; if the control authority is not required, displaying the rendered page; If the control authority is required and the current user logs in, the original HTML document is parsed, otherwise jump to the login interface.
- before performing page rendering on the original HTML page it further includes: determining whether to synchronize the latest permission data; if the latest permission data is synchronized, parsing the original HTML document, Otherwise, read the new permission data.
- another embodiment of the present invention provides a permission control device for processing a front-end page, including: a parsing module for parsing an original HTML document and parsing a custom tag according to preset control logic , To perform page rendering on the original HTML page and determine whether the JavaScript logic code needs to be called; the first interception module is used to intercept the calling method of the JavaScript logic code when the JavaScript logic code needs to be called; the control module, uses Yu parses the annotation according to the calling method to determine whether the current user has control authority according to the parsed annotation, and allows calling when the control authority is owned.
- the permission control device for processing front-end pages can easily implement the permission control of page elements and logic codes according to the keywords of permissions and roles, and the page element permission control can also meet intuitive requirements and realize front-end permissions
- the goal of zero control code writing which effectively improves the intuitiveness, versatility and compatibility of control, and is simple and easy to implement.
- the authority control apparatus for processing front-end pages may also have the following additional technical features:
- it further includes: a detection module for detecting whether to synchronize the latest authority data, and after not synchronizing the latest authority data, and after reading the latest authority data , Parse and store to cache device.
- a second interception module configured to intercept the calling method of the JavaScript logic code when the non-page is initialized and the JavaScript logic code needs to be called.
- a second detection module configured to detect whether the control authority is required for accessing the page, and when the control authority is not required, display the rendered page, and If the current user logs in, the original HTML document is parsed, otherwise jump to the login interface.
- it further includes: a judgment module for judging whether to synchronize the latest authority data, and parsing the original HTML document when synchronizing the latest authority data, otherwise reading the new authority data.
- FIG. 1 is a flowchart of a permission control method for processing a front-end page according to an embodiment of the present invention
- FIG. 2 is a flowchart of a permission control method for processing a front-end page according to a specific embodiment of the present invention
- FIG. 3 is a schematic structural diagram of a permission control device for processing a front-end page according to an embodiment of the present invention.
- FIG. 1 is a flowchart of a permission control method for processing a front-end page according to an embodiment of the present invention.
- the permission control method for processing front-end pages includes the following steps:
- step S101 the original HTML document is parsed, and the custom tags are parsed according to the preset control logic to perform page rendering on the original HTML page and determine whether JavaScript logic code needs to be called.
- the HTML code after the custom tag parser will parse the ⁇ button> tag from the original Dom structure, so that the rendered page will not [Delete] button to achieve the purpose of front-end authority control.
- HTML custom tags implement permission control on HTML elements.
- HTML custom tags use the conventional identifier as the tag name.
- the value of name is the name of the role or permission in the permission data.
- gsauth is a custom HTML tag
- xmlns is the abbreviation of xml namespace, which is the namespace attribute of HTML tags, which is generally declared at the beginning of the element Marked place.
- the parser will recognize the label and assign the defined attributes, as shown in the following example:
- the original HTML page before performing page rendering on the original HTML page, it further includes: detecting whether access control is required for accessing the page; if control permission is not required, displaying the rendered page; if control permission is required, and When the current user logs in, the original HTML document is parsed, otherwise jump to the login interface.
- the original HTML page before rendering the original HTML page, it further includes: detecting whether the latest permission data is synchronized; if the latest permission data is not synchronized, after reading the latest permission data , Parse and store to cache device.
- the method before rendering the original HTML page, the method further includes: determining whether to synchronize the latest permission data; if the latest permission data is synchronized, the original HTML document is parsed; otherwise, the new permission is read data.
- step S102 if the JavaScript logic code needs to be called, the calling method of the JavaScript logic code is intercepted.
- the embodiment of the present invention intercepts the calling method through the permission control interceptor.
- the permission control interceptor intercepts the calling method.
- it further includes: when the non-page is initialized and the JavaScript logic code needs to be called, the calling method of the JavaScript logic code is intercepted.
- step S103 the annotation is parsed according to the calling method to determine whether the current user has control authority according to the parsed annotation, and when the control authority has control authority, call is allowed.
- the embodiment of the present invention uses the annotation parser to control the permission of the calling method.
- the annotation analysis is implemented based on AOP for the method. Analyze the comments to determine whether the current user has the corresponding permissions to determine whether to allow the method to be called, and finally achieve the permission control goal when calling the method.
- the embodiment of the present invention implements permission control on JavaScript logic through annotations and coding methods, and specifically includes:
- the "@hasRole("administrator")” part in the above sample code is a complete permission control annotation, where "hasRole” is the authorization meaning identifier (see the table above for authorization meaning identifier), which represents whether it has the specified role.
- the final meaning of this note is that users with the administrator role have the authority to perform delete operations.
- the business logic code is intercepted by the interceptor in the permission control device, and it is judged whether this method is annotated. If it is marked, it must be performed by the permission control device before calling this method. Judging that only the user with the role of "administrator" can call the method of this annotation.
- the permission control based on the coding method is easy to understand, that is, it is sufficient to directly call the permission method provided in the permission control device. Examples are as follows:
- the “hasRole(“administrator”)” part in the above sample code is a method already built into the permission control device, where “hasRole” is the method name, and all the authorization method names provided in this device are identified with the authorization meanings listed above.
- a unified permission control logic is processed through a permission control device, and an intuitive permission control on page elements is implemented through HTML custom tags, and is fully compatible with mainstream technical frameworks .
- FIG. 3 is a schematic structural diagram of an authority control apparatus for processing front-end pages according to an embodiment of the present invention.
- the authority control device 10 for processing front-end pages includes: a parsing module 100, a first intercepting module 200, and a control module 300.
- the parsing module 100 is used to parse the original HTML document and parse the custom tags according to the preset control logic to perform page rendering on the original HTML page and determine whether JavaScript logic code needs to be called.
- the first intercepting module 200 is used to intercept the calling method of the JavaScript logic code when the JavaScript logic code needs to be called.
- the control module 300 is used to parse the annotation according to the calling method, to determine whether the current user has control authority according to the parsed annotation, and to allow the call when the control authority has the control authority.
- the device 10 according to the embodiment of the present invention can easily implement the permission control of page elements and logic codes according to the keywords of permissions and roles, and the page element permission control can also meet intuitive requirements, and achieve the goal of zero writing of front-end permission control codes In order to effectively improve the intuitiveness, versatility and compatibility of the control, it is simple and easy to implement.
- the apparatus 10 of the embodiment of the present invention further includes: a detection module.
- the detection module is used to detect whether the latest authority data is synchronized, and the latest authority data is not synchronized, and after reading the latest authority data, it is parsed and stored in the cache device.
- the apparatus 10 of the embodiment of the present invention further includes: a second interception module.
- the second interception module is used to intercept the calling method of the JavaScript logic code when the non-page is initialized and the JavaScript logic code needs to be called.
- the device 10 of the embodiment of the present invention further includes: a second detection module.
- the second detection module is used to detect whether the access permission is required for accessing the page. When the control permission is not required, the rendered page is displayed, and when the control permission is required and the current user logs in, the original HTML document is parsed, otherwise jump Go to the login interface.
- the apparatus 10 of the embodiment of the present invention further includes: a judgment module.
- the judgment module is used to judge whether to synchronize the latest authority data.
- the original HTML document is parsed, otherwise the new authority data is read.
- unified permission control logic processing is realized through the permission control device, and intuitive permission control on page elements is realized through HTML custom tags, and it is fully compatible with mainstream technical frameworks.
- No additional development, and no need to write permission control logic in the development phase only need to maintain permissions and role names, no need to maintain code, which has the advantages of consistency, intuitiveness, universality, easy to use, maintainability, etc. .
- first and second are used for description purposes only, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features.
- the features defined as “first” and “second” may include at least one of the features explicitly or implicitly.
- the meaning of “plurality” is at least two, such as two, three, etc., unless specifically defined otherwise.
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Human Computer Interaction (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Storage Device Security (AREA)
- Document Processing Apparatus (AREA)
- Information Transfer Between Computers (AREA)
Abstract
一种处理前端页面的权限控制方法及装置,其中,方法包括:对原始HTML文档进行解析,并根据预设控制逻辑进行自定义标签的解析,以对原始HTML页面进行页面渲染,并判断是否需要调用JavaScript逻辑代码(S101);如果需要调用JavaScript逻辑代码,则拦截JavaScript逻辑代码的调用方法(S102);根据调用方法对注解进行解析,以根据解析注释判断当前用户是否拥有控制权限,并在拥有控制权限时,允许调用(S103)。该方法根据权限与角色的关键字就可轻松实现页面元素和逻辑代码的权限控制,页面元素权限控制还能满足直观性的要求,并实现前端权限控制代码零编写的目标,有效提高控制的直观性、通用性和兼容性,简单易实现。
Description
相关申请的交叉引用
本申请要求北京辰安科技股份有限公司与清华大学于2018年12月29日提交的、发明名称为“处理前端页面的权限控制方法及装置”的、中国专利申请号“201811645607.X”的优先权。
本发明涉及权限控制技术领域,特别涉及一种处理前端页面的权限控制方法及装置。
相关技术,页面权限控制的技术分为两类,具体包括:
(1)基于后端渲染页面技术,比如类似JSP技术,其页面元素的权限控制可以通过JSTL自定义标签进行控制。但是,基于JavaScript的业务逻辑的权限控制就需要通过编写判断性的逻辑代码来实现,从而导致权限控制的维护性较差,而且容易出现页面元素和业务逻辑权限控制不一致的问题。
(2)纯前端页面逻辑的控制,这种权限控制是通过AJAX技术,每次请求时将限控制数据获取后,通过代码进行业务逻辑的权限控制,并同时对页面元素进行控制,此种实现方案虽然确保了权限控制逻辑的一致性,但通过代码对页面元素进行控制,导致了大量的重复代码的不可维护性。
综上,相关技术的两类的页面的权限控制技术,主要存在以下缺点:
1、权限控制逻辑的重复,容易导致逻辑的不一致,同时也不利于后期维护;
2、页面元素控制靠代码进行逻辑判断,不够清晰直观,且因代码量大量导致不易于维护的问题。
发明内容
本申请是基于发明人对以下问题的认识和发现做出的:
通常权限控制一般在服务端进行控制,权限控制常用的方案就是RBAC基于角色的访问控制,其基本思路就是,对涉及的各种权限不是直接授予具体的用户,而是在用户集合与权限集合之间建立一个角色集合。每一种角色对应一组相应的权限。用户被分配了适当的角色后,该用户就拥有此角色的所有操作权限。这样做的好处是,不必在每次创建用户 时都进行分配权限的操作,只要分配用户相应的角色即可,而且角色的权限变更比用户的权限变更要少得多,这样将简化用户的权限管理,减少系统的开销。
随着软件业的不断发展,B/S架构的系统逐渐趋向于服务客户端,对于前端的交互体验要求也越来越高,采用前后端分离的技术实现成为一种趋势,因此,为实现前端更好的交互体验,前端的权限控制就非常有必要,而前端又没有成熟的权限控制方案,使用的基于JavaScript编码方式解决前端业务逻辑和视图的统一权限控制,需要大量重复性的代码来实现,导致了系统越来越难易维护,长期将造成软件系统的维护成本不断的增长。
在前后端分离的大背景下,替代方案就是通过编写自己的JavaScript代码对HTML中的元素进行控制,同时在JavaScript代码中,通过大量重复的业务逻辑代码来判断,导致了重复代码的不可维护性,尤其在当下比较重视前端应用的情况下,前端业务本来就是越来越复杂,如果权限控制不能很好的解决,一方面会影响交互,影响应用的效果,如果通过硬编码的方式来解决,就势必导致代码的不可维护性,造成前端维护的工作量越来越大,不利于以前端为主的产品发展。
本发明旨在至少在一定程度上解决相关技术中的技术问题之一。
为此,本发明的一个目的在于提出一种处理前端页面的权限控制方法,该方法有效提高控制的直观性、通用性和兼容性,简单易实现。
本发明的另一个目的在于提出一种处理前端页面的权限控制装置。
为达到上述目的,本发明一方面实施例提出了一种处理前端页面的权限控制方法,包括以下步骤:对原始HTML文档进行解析,并根据预设控制逻辑进行自定义标签的解析,以对原始HTML页面进行页面渲染,并判断是否需要调用JavaScript逻辑代码;如果需要调用所述JavaScript逻辑代码,则拦截所述JavaScript逻辑代码的调用方法;根据所述调用方法对注解进行解析,以根据解析注释判断当前用户是否拥有控制权限,并在拥有所述控制权限时,允许调用。
本发明实施例的处理前端页面的权限控制方法,根据权限与角色的关键字就可轻松实现页面元素和逻辑代码的权限控制,而且页面元素权限控制还能满足直观性的要求,并实现前端权限控制代码零编写的目标,从而有效提高控制的直观性、通用性和兼容性,简单易实现。
另外,根据本发明上述实施例的处理前端页面的权限控制方法还可以具有以下附加的技术特征:
进一步地,在本发明的一个实施例中,在对所述原始HTML页面进行页面渲染之前,还包括:检测是否同步最新的权限数据;如果未同步所述最新的权限数据,则在读取所述最新的权限数据后,解析并存储至缓存装置。
进一步地,在本发明的一个实施例中,还包括:在非页面初始化,且需要调用所述JavaScript逻辑代码时,拦截所述JavaScript逻辑代码的调用方法。
进一步地,在本发明的一个实施例中,在对所述原始HTML页面进行页面渲染之前,还包括:检测访问页面是否需要所述控制权限;如果不需要所述控制权限,则显示渲染页面;如果需要所述控制权限,且所述当前用户登录,则对原始HTML文档进行解析,否则跳转至登录界面。
进一步地,在本发明的一个实施例中,在对所述原始HTML页面进行页面渲染之前,还包括:判断是否同步最新权限数据;如果同步所述最新权限数据,则对原始HTML文档进行解析,否则读取所述新权限数据。
为达到上述目的,本发明另一方面实施例提出了一种处理前端页面的权限控制装置,包括:解析模块,用于对原始HTML文档进行解析,并根据预设控制逻辑进行自定义标签的解析,以对原始HTML页面进行页面渲染,并判断是否需要调用JavaScript逻辑代码;第一拦截模块,用于在需要调用所述JavaScript逻辑代码时,拦截所述JavaScript逻辑代码的调用方法;控制模块,用于根据所述调用方法对注解进行解析,以根据解析注释判断当前用户是否拥有控制权限,并在拥有所述控制权限时,允许调用。
本发明实施例的处理前端页面的权限控制装置,根据权限与角色的关键字就可轻松实现页面元素和逻辑代码的权限控制,而且页面元素权限控制还能满足直观性的要求,并实现前端权限控制代码零编写的目标,从而有效提高控制的直观性、通用性和兼容性,简单易实现。
另外,根据本发明上述实施例的处理前端页面的权限控制装置还可以具有以下附加的技术特征:
进一步地,在本发明的一个实施例中,还包括:检测模块,用于检测是否同步最新的权限数据,并在未同步所述最新的权限数据,且在读取所述最新的权限数据后,解析并存储至缓存装置。
进一步地,在本发明的一个实施例中,还包括:第二拦截模块,用于在非页面初始化,且需要调用所述JavaScript逻辑代码时,拦截所述JavaScript逻辑代码的调用方法。
进一步地,在本发明的一个实施例中,还包括:第二检测模块,用于检测访问页面是否需要所述控制权限,在不需要所述控制权限时,则显示渲染页面,并在需要所述控制权限,且所述当前用户登录,则对原始HTML文档进行解析,否则跳转至登录界面。
进一步地,在本发明的一个实施例中,还包括:判断模块,用于判断是否同步最新权限数据,在同步所述最新权限数据时,对原始HTML文档进行解析,否则读取所述新权限数据。
本发明附加的方面和优点将在下面的描述中部分给出,部分将从下面的描述中变得明显,或通过本发明的实践了解到。
本发明上述的和/或附加的方面和优点从下面结合附图对实施例的描述中将变得明显和容易理解,其中:
图1为根据本发明一个实施例的处理前端页面的权限控制方法的流程图;
图2为根据本发明一个具体实施例的处理前端页面的权限控制方法的流程图;
图3为根据本发明一个实施例的处理前端页面的权限控制装置的结构示意图。
下面详细描述本发明的实施例,所述实施例的示例在附图中示出,其中自始至终相同或类似的标号表示相同或类似的元件或具有相同或类似功能的元件。下面通过参考附图描述的实施例是示例性的,旨在用于解释本发明,而不能理解为对本发明的限制。
下面参照附图描述根据本发明实施例提出的处理前端页面的权限控制方法及装置,首先将参照附图描述根据本发明实施例提出的处理前端页面的权限控制方法。
图1是本发明一个实施例的处理前端页面的权限控制方法的流程图。
如图1所示,该处理前端页面的权限控制方法包括以下步骤:
在步骤S101中,对原始HTML文档进行解析,并根据预设控制逻辑进行自定义标签的解析,以对原始HTML页面进行页面渲染,并判断是否需要调用JavaScript逻辑代码。
可以理解的是,如图2所示,当权限已获取或同步更新到前端缓存装置中后,就开始通过自定义标签解析器对原始HTML文档进行解析,并根据权限装置中的控制逻辑,进行自定义标签的解析,如原始HTML代码:
<buttontype="button"onclick="delete()"hasRole="administrator">删除</button>。
假设当前登录用户是普通身份用户,没有"administrator"角色,那么经过自定义标签解析器解析之后的HTML代码,会将该<button>标签从原始Dom结构中进行删除,这样渲染出来的页面将没有【删除】按钮,达到实现前端的权限控制的目的。
具体而言,HTML自定义标签实现对HTML元素的权限控制,HTML自定义标签是以约定的标识作为标签名称,name的值为权限数据中角色或权限的名称,要使用自定义HTML标签,首先需要在<HTML>标签中进行这样的申明:<HTML xmlns:gsauth>,其中gsauth便是自定义HTML标签,xmlns即xml name space的缩写,是HTML标记的命名空间属性,一般其声明在元素开始标记的地方。只要在这里申明了要使用的gsauth这一自定 义标签,语法分析器就会认识这个标签,并赋予定义的属性了,如下例:
HTML代码:
<gsauth:hasRole name="administrator">
<buttontype="button"onclick="delete()">删除</button>
</gsauth:hasRole>
上述示例代码中“<gsauth:hasRole name="administrator"></gsauth:hasRole>”部分就是完整的自定义标签,其中“gsauth”为HTML自定义标签名称,hasRole为自定标签的授权含义标识,代表是否拥有指定的角色。该自定义标签最终代表的含义就是拥有administrator角色的用户,才有【删除】按钮的操作权限。在页面初始化时,通过权限控制装置处理后,只有拥有角色为“administrator”用户,才能看得到【删除】按钮。
如果仅是控制页面的单一元素,还可以采用一种简约写法,将原自定义标签的中的授权含义标识,作为该标签的属性。如将上述按简约写法如下:
HTML代码:
<buttontype="button"onclick="delete()"hasRole="administrator">删除</button>
基于上述定义,本发明实施例中提供多种授权含义标识供灵活使用,具体参见表1。
表1
上述为本发明实施例通过自定义标签解析器处理HTML文件,在此之前,本发明实施例获取服务器端权限数据并解析后进行前端缓存,下面将结合实施例进行详细阐述。
进一步地,在本发明的一个实施例中,在对原始HTML页面进行页面渲染之前,还包括:检测访问页面是否需要控制权限;如果不需要控制权限,则显示渲染页面;如果需要控制权限,且当前用户登录,则对原始HTML文档进行解析,否则跳转至登录界面。
可以理解的是,如图2所示,当在访问页面时,首先判断当前页面是否需要权限控制,如果不需要进行页面权限控制,则直接渲染页面进行显示,如果需要进行页面权限控制, 则需要判断用户是否已登录,若用户未登录,则直接调转到登录界面。
进一步地,在本发明的一个实施例中,在对原始HTML页面进行页面渲染之前,还包括:检测是否同步最新的权限数据;如果未同步最新的权限数据,则在读取最新的权限数据后,解析并存储至缓存装置。
其中,在本发明的一个实施例中,在对原始HTML页面进行页面渲染之前,还包括:判断是否同步最新权限数据;如果同步最新权限数据,则对原始HTML文档进行解析,否则读取新权限数据。
可以理解的是,如图2所示,若已登录,则进入权限控制装置,并根据用户信息首先判断是否同步到了最新的权限数据,如果已是最新权限数据,则直接通过自定义标签解析器处理HTML文件,如果未获取到权限数据或者权限数据不是最新的,需要先读取服务器端权限数据,并进行解析之后,统一存入前端权限数据缓存装置中。
在步骤S102中,如果需要调用JavaScript逻辑代码,则拦截JavaScript逻辑代码的调用方法。
可以理解的是,如图2所示,本发明实施例通过权限控制拦截器对调用方法的拦截,当原始HTML页面已经过自定义标签解析器处理之后,进行页面渲染时,如果页面初始化过程中,需要调用JavaScript逻辑代码时,权限控制拦截器对调用方法进行拦截。
进一步地,在本发明的一个实施例中,还包括:在非页面初始化,且需要调用JavaScript逻辑代码时,拦截JavaScript逻辑代码的调用方法。
可以理解的是,非页面初始化时,当调用JavaScript的方法时,也同样会通过权限控制拦截器对调用的方法进行拦截。
在步骤S103中,根据调用方法对注解进行解析,以根据解析注释判断当前用户是否拥有控制权限,并在拥有控制权限时,允许调用。
可以理解的是,如图2所示,本发明实施例通过注解解析器对进行调用方法的权限控制,当权限控制拦截器对调用的方法进行拦截之后,针对该方法基于AOP实现注解的解析,通过解析注释来判断当前用户是否拥有相应的权限,来决定是否允许调用该方法,最终实现调用方法时的权限控制目标。
具体而言,本发明实施例通过注解和编码方式实现对JavaScript逻辑进行权限控制,具体包括:
当要控制JavaScrip代码的权限时,需通过注解或编码方式来实现,其中注解是一种以@开头的特殊标识,此种标识只能用于方法上,不能用于方法内,如果需要在方法中间控制权限,需通过编码方式调用由权限控制装置提供权限控制方法来实现。
基于注释控制方法的示例如下:
JavaScript代码:
class Person{
@hasRole("administrator")
delete(this.children.id);}
上述示例代码中“@hasRole("administrator")”部分就是一个完整的权限控制注解,其中“hasRole”为授权含义标识(授权含义标识参见上表),代表是否拥有指定的角色。该注解最终代表的含义就是拥有administrator角色的用户,才有执行删除操作权限。当业务逻辑代码在调用此方法前,先由权限控制装置中的拦截器进行拦截,并判断此方法是否进行了注解标注,如果标注了,则在调用该方法前,先要通过权限控制装置进行判断,只有拥有角色为“administrator”用户,才能调用此注解标识的方法。
基于编码方式实现的权限控制就很容易理解了,就是直接通过调用权限控制装置中已提供判断的权限方法即可,示例如下:
if(hasRole(“administrator”)){
//有删除权限的代码
}else{//无删除权限的代码}
上述示例代码中“hasRole(“administrator”)”部分就是权限控制装置中已内置的方法,其中“hasRole”为方法名称,此装置中提供的所有授权方法名称同上述中所列授权含义标识。
根据本发明实施例提出的处理前端页面的权限控制方法,通过权限控制装置实现统一的权限控制逻辑的处理,并通过HTML自定义标签实现对页面元素直观的权限控制,且全面兼容主流的技术框架,不需额外开,而且发开发阶段不需编写权限控制逻辑,只需维护权限和角色名称,不需维护代码,从而具有一致性、直观性、通用性、简单易用、可维护性等优点。
其次参照附图描述根据本发明实施例提出的处理前端页面的权限控制装置。
图3是本发明一个实施例的处理前端页面的权限控制装置的结构示意图。
如图3所示,该处理前端页面的权限控制装置10包括:解析模块100、第一拦截模块200和控制模块300。
其中,解析模块100用于对原始HTML文档进行解析,并根据预设控制逻辑进行自定义标签的解析,以对原始HTML页面进行页面渲染,并判断是否需要调用JavaScript逻辑代码。第一拦截模块200用于在需要调用JavaScript逻辑代码时,拦截JavaScript逻辑代码的调用方法。控制模块300用于根据调用方法对注解进行解析,以根据解析注释判断当前用户是否拥有控制权限,并在拥有控制权限时,允许调用。本发明实施例的装置10根据权 限与角色的关键字就可轻松实现页面元素和逻辑代码的权限控制,而且页面元素权限控制还能满足直观性的要求,并实现前端权限控制代码零编写的目标,从而有效提高控制的直观性、通用性和兼容性,简单易实现。
进一步地,在本发明的一个实施例中,本发明实施例的装置10还包括:检测模块。其中,检测模块用于检测是否同步最新的权限数据,并在未同步最新的权限数据,且在读取最新的权限数据后,解析并存储至缓存装置。
进一步地,在本发明的一个实施例中,本发明实施例的装置10还包括:第二拦截模块。其中,第二拦截模块用于在非页面初始化,且需要调用JavaScript逻辑代码时,拦截JavaScript逻辑代码的调用方法。
进一步地,在本发明的一个实施例中,本发明实施例的装置10还包括:第二检测模块。其中,第二检测模块用于检测访问页面是否需要控制权限,在不需要控制权限时,则显示渲染页面,并在需要控制权限,且当前用户登录,则对原始HTML文档进行解析,否则跳转至登录界面。
进一步地,在本发明的一个实施例中,本发明实施例的装置10还包括:判断模块。其中,判断模块用于判断是否同步最新权限数据,在同步最新权限数据时,对原始HTML文档进行解析,否则读取新权限数据。
需要说明的是,前述对处理前端页面的权限控制方法实施例的解释说明也适用于该实施例的处理前端页面的权限控制装置,此处不再赘述。
根据本发明实施例提出的处理前端页面的权限控制装置,通过权限控制装置实现统一的权限控制逻辑的处理,并通过HTML自定义标签实现对页面元素直观的权限控制,且全面兼容主流的技术框架,不需额外开,而且发开发阶段不需编写权限控制逻辑,只需维护权限和角色名称,不需维护代码,从而具有一致性、直观性、通用性、简单易用、可维护性等优点。
此外,术语“第一”、“第二”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐含地包括至少一个该特征。在本发明的描述中,“多个”的含义是至少两个,例如两个,三个等,除非另有明确具体的限定。
在本说明书的描述中,参考术语“一个实施例”、“一些实施例”、“示例”、“具体示例”、或“一些示例”等的描述意指结合该实施例或示例描述的具体特征、结构、材料或者特点包含于本发明的至少一个实施例或示例中。在本说明书中,对上述术语的示意性表述不必须针对的是相同的实施例或示例。而且,描述的具体特征、结构、材料或者特点可以在任一个或多个实施例或示例中以合适的方式结合。此外,在不相互矛盾的情况下,本领域的技 术人员可以将本说明书中描述的不同实施例或示例以及不同实施例或示例的特征进行结合和组合。
尽管上面已经示出和描述了本发明的实施例,可以理解的是,上述实施例是示例性的,不能理解为对本发明的限制,本领域的普通技术人员在本发明的范围内可以对上述实施例进行变化、修改、替换和变型。
Claims (10)
- 一种处理前端页面的权限控制方法,其特征在于,包括以下步骤:对原始HTML文档进行解析,并根据预设控制逻辑进行自定义标签的解析,以对原始HTML页面进行页面渲染,并判断是否需要调用JavaScript逻辑代码;如果需要调用所述JavaScript逻辑代码,则拦截所述JavaScript逻辑代码的调用方法;以及根据所述调用方法对注解进行解析,以根据解析注释判断当前用户是否拥有控制权限,并在拥有所述控制权限时,允许调用。
- 根据权利要求1所述的处理前端页面的权限控制方法,其特征在于,在对所述原始HTML页面进行页面渲染之前,还包括:检测是否同步最新的权限数据;如果未同步所述最新的权限数据,则在读取所述最新的权限数据后,解析并存储至缓存装置。
- 根据权利要求1所述的处理前端页面的权限控制方法,其特征在于,还包括:在非页面初始化,且需要调用所述JavaScript逻辑代码时,拦截所述JavaScript逻辑代码的调用方法。
- 根据权利要求1所述的处理前端页面的权限控制方法,其特征在于,在对所述原始HTML页面进行页面渲染之前,还包括:检测访问页面是否需要所述控制权限;如果不需要所述控制权限,则显示渲染页面;如果需要所述控制权限,且所述当前用户登录,则对原始HTML文档进行解析,否则跳转至登录界面。
- 根据权利要求1或4所述的处理前端页面的权限控制方法,其特征在于,在对所述原始HTML页面进行页面渲染之前,还包括:判断是否同步最新权限数据;如果同步所述最新权限数据,则对原始HTML文档进行解析,否则读取所述新权限数据。
- 一种处理前端页面的权限控制装置,其特征在于,包括:解析模块,用于对原始HTML文档进行解析,并根据预设控制逻辑进行自定义标签的解析,以对原始HTML页面进行页面渲染,并判断是否需要调用JavaScript逻辑代码;第一拦截模块,用于在需要调用所述JavaScript逻辑代码时,拦截所述JavaScript逻辑 代码的调用方法;以及控制模块,用于根据所述调用方法对注解进行解析,以根据解析注释判断当前用户是否拥有控制权限,并在拥有所述控制权限时,允许调用。
- 根据权利要求6所述的处理前端页面的权限控制装置,其特征在于,还包括:检测模块,用于检测是否同步最新的权限数据,并在未同步所述最新的权限数据,且在读取所述最新的权限数据后,解析并存储至缓存装置。
- 根据权利要求6所述的处理前端页面的权限控制装置,其特征在于,还包括:第二拦截模块,用于在非页面初始化,且需要调用所述JavaScript逻辑代码时,拦截所述JavaScript逻辑代码的调用方法。
- 根据权利要求6所述的处理前端页面的权限控制装置,其特征在于,还包括:第二检测模块,用于检测访问页面是否需要所述控制权限,在不需要所述控制权限时,则显示渲染页面,并在需要所述控制权限,且所述当前用户登录,则对原始HTML文档进行解析,否则跳转至登录界面。
- 根据权利要求6或9所述的处理前端页面的权限控制装置,其特征在于,还包括:判断模块,用于判断是否同步最新权限数据,在同步所述最新权限数据时,对原始HTML文档进行解析,否则读取所述新权限数据。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201811645607.X | 2018-12-29 | ||
| CN201811645607.XA CN109753283B (zh) | 2018-12-29 | 2018-12-29 | 处理前端页面的权限控制方法及装置 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2020135583A1 true WO2020135583A1 (zh) | 2020-07-02 |
Family
ID=66405061
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2019/128695 Ceased WO2020135583A1 (zh) | 2018-12-29 | 2019-12-26 | 处理前端页面的权限控制方法及装置 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN109753283B (zh) |
| WO (1) | WO2020135583A1 (zh) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115580433A (zh) * | 2022-09-06 | 2023-01-06 | 武汉船舶通信研究所(中国船舶重工集团公司第七二二研究所) | 一种动态权限系统、装置及其权限管理方法 |
Families Citing this family (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109753283B (zh) * | 2018-12-29 | 2021-03-19 | 北京辰安科技股份有限公司 | 处理前端页面的权限控制方法及装置 |
| CN110290212B (zh) * | 2019-06-28 | 2020-06-23 | 浙江大搜车软件技术有限公司 | 服务调用记录方法、装置、计算机设备和存储介质 |
| CN110334490A (zh) * | 2019-07-16 | 2019-10-15 | 山东浪潮通软信息科技有限公司 | 一种基于React的前端权限控制方法 |
| CN112241266B (zh) * | 2019-07-17 | 2024-12-31 | 腾讯科技(北京)有限公司 | 前端渲染场景下的权限控制方法、装置、设备及存储介质 |
| CN114065068A (zh) * | 2020-07-31 | 2022-02-18 | 中移(苏州)软件技术有限公司 | 一种页面访问控制方法及装置、设备、存储介质 |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20050262549A1 (en) * | 2004-05-10 | 2005-11-24 | Markus Ritt | Method and system for authorizing user interfaces |
| CN101546261A (zh) * | 2008-10-10 | 2009-09-30 | 华中科技大学 | 多策略支持的安全网页标签库系统 |
| CN104461519A (zh) * | 2014-11-23 | 2015-03-25 | 国云科技股份有限公司 | 一种流程表单动态生成和权限控制的方法 |
| CN107341388A (zh) * | 2017-06-19 | 2017-11-10 | 东软集团股份有限公司 | 访问权限控制方法和装置 |
| CN109753283A (zh) * | 2018-12-29 | 2019-05-14 | 北京辰安科技股份有限公司 | 处理前端页面的权限控制方法及装置 |
Family Cites Families (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101026647A (zh) * | 2007-04-09 | 2007-08-29 | 中国网络通信集团公司 | 电信收入稽核动态分级管理系统及方法 |
| US9710243B2 (en) * | 2013-11-07 | 2017-07-18 | Eagle Legacy Modernization, LLC | Parser that uses a reflection technique to build a program semantic tree |
| CN107632869B (zh) * | 2017-09-15 | 2021-01-26 | 百富计算机技术(深圳)有限公司 | 一种加载pos应用的用户界面的方法与设备 |
| CN108319861A (zh) * | 2018-04-13 | 2018-07-24 | 珠海横琴盛达兆业科技投资有限公司 | 一种基于js平台判断权限与角色的方法 |
-
2018
- 2018-12-29 CN CN201811645607.XA patent/CN109753283B/zh active Active
-
2019
- 2019-12-26 WO PCT/CN2019/128695 patent/WO2020135583A1/zh not_active Ceased
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20050262549A1 (en) * | 2004-05-10 | 2005-11-24 | Markus Ritt | Method and system for authorizing user interfaces |
| CN101546261A (zh) * | 2008-10-10 | 2009-09-30 | 华中科技大学 | 多策略支持的安全网页标签库系统 |
| CN104461519A (zh) * | 2014-11-23 | 2015-03-25 | 国云科技股份有限公司 | 一种流程表单动态生成和权限控制的方法 |
| CN107341388A (zh) * | 2017-06-19 | 2017-11-10 | 东软集团股份有限公司 | 访问权限控制方法和装置 |
| CN109753283A (zh) * | 2018-12-29 | 2019-05-14 | 北京辰安科技股份有限公司 | 处理前端页面的权限控制方法及装置 |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115580433A (zh) * | 2022-09-06 | 2023-01-06 | 武汉船舶通信研究所(中国船舶重工集团公司第七二二研究所) | 一种动态权限系统、装置及其权限管理方法 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN109753283A (zh) | 2019-05-14 |
| CN109753283B (zh) | 2021-03-19 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US9235636B2 (en) | Presenting data in response to an incomplete query | |
| US8707451B2 (en) | Search hit URL modification for secure application integration | |
| US8433712B2 (en) | Link analysis for enterprise environment | |
| US8595255B2 (en) | Propagating user identities in a secure federated search system | |
| KR101623223B1 (ko) | 하나의 인터넷 호스팅 시스템 집합에 의해 제공되는 다수의 병렬 사용자 경험 | |
| US11687703B2 (en) | Shortcut to move a selection into a new document | |
| CN111767303A (zh) | 一种数据查询方法、装置、服务器及可读存储介质 | |
| US20140195514A1 (en) | Unified interface for querying data in legacy databases and current databases | |
| US12566775B2 (en) | Managing content across discrete systems | |
| CN109753283B (zh) | 处理前端页面的权限控制方法及装置 | |
| US10261996B2 (en) | Content localization using fallback translations | |
| US12339813B2 (en) | Embedded folder views | |
| JP2020500343A (ja) | 協働コンテンツアイテムにおけるイメージ注釈 | |
| EP3017368A1 (en) | Syncing content clipboard | |
| US20140129920A1 (en) | Enhanced Document and Event Mirroring for Accessing Internet Content | |
| US9740874B2 (en) | Content preview including sharable information | |
| US8365069B1 (en) | Web content management based on timeliness metadata | |
| US9646048B2 (en) | Declarative partitioning for data collection queries | |
| US10198449B2 (en) | Creating unique content item identifiers | |
| US10552517B2 (en) | Aggregating content from one or more documents | |
| US10623491B2 (en) | Namespace translation |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 19904037 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 19904037 Country of ref document: EP Kind code of ref document: A1 |
