Method for realizing single sign-on and automatic switching of subsystem login based on es6

Automatically judge and set the Flag value through the proxy proxy method of ES6, which solves the problem that traditional methods require manual modification of Flag value, realizes automatic switching between single sign-on and subsystem login, and improves the scalability and maintenance of the system.

CN114065186BActive Publication Date: 2024-11-05四川启睿克科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111363961.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-17
Publication Date
2024-11-05
Estimated Expiration
2041-11-17

AI Technical Summary

Technical Problem

In enterprise business systems, traditional methods require manual modification of Flag values ​​to distinguish single sign-on and subsystem log-on, which is not conducive to expansion and maintenance.

Method used

Using ES6's proxy method, configure the global identification isClient object in GlobalData.js, and intercept the property changes through the refactoring object's get method. Use the Reflect API to automatically judge and set the Flag value to realize automatic switching between single sign-in and subsystem login .

Benefits of technology

It realizes automatic switching of single sign-on and subsystem login without manually modifying the Flag value, improving the scalability and maintenance of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114065186B_ABST
    Figure CN114065186B_ABST
Patent Text Reader

Abstract

The invention discloses a method for realizing automatic switching between single sign-on and subsystem sign-on based on es6. By adopting the proxy method of ECMAScript 6 version of javascript, the problem of manually modifying the value of Flag each time a service is started is solved so as to determine whether it is single sign-on or subsystem sign-on.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of front-end development, and in particular to a method for realizing single sign-on and automatic switching of subsystem login based on es6. Background Art

[0002] In the process of developing business subsystems for enterprises, as the number of enterprise business systems gradually increases, single sign-on has become one of the solutions for enterprise business integration. The so-called single sign-on means that in multiple application systems, you only need to log in once to access other mutually trusted application systems. However, in some scenarios, it is still necessary to start the business subsystem separately to meet the needs of the enterprise. This means that the system we develop needs to meet the startup method of single sign-on at the same time, and also be able to start the subsystem separately. The traditional approach is to set a default global Flag of false for the subsystem, indicating subsystem login, and true for single sign-on. After determining the Flag, when starting the service, you need to manually modify the Flag value and then jump to different login pages. This can certainly meet business needs, but it is not conducive to expansion and maintenance because you need to manually modify the Flag value every time you start the service. Summary of the invention

[0003] The purpose of the present invention is to provide a method for realizing automatic switching between single sign-on and subsystem login based on es6 in order to solve the above problems. The present invention adopts the proxy method of the ECMAScript 6 version of javascript to solve the problem that the value of Flag needs to be manually modified every time the service is started in order to determine whether it is single sign-on or subsystem login.

[0004] The present invention achieves the above-mentioned purpose through the following technical solutions:

[0005] A method for implementing single sign-on and automatic switching of subsystem login based on es6, comprising the following steps:

[0006] Step 1: Configure the global default identifier isClient object in GlobalData.js. The flag attribute in this object is the identifier of single sign-on and subsystem login. The default value is false (false means subsystem login, true means single sign-on).

[0007] Step 2: Instantiate the proxy in GlobalData.js, use the proxy feature of ES6, and reconstruct the get method of the object to intercept and automatically process attribute changes:

[0008] a. The proxy is created using the Proxy constructor, which receives two parameters: the target object and the handler object, and generates a proxy instance using the new keyword;

[0009] b. Define traps. Traps are "interceptors of basic operations" defined in handler objects. Each handler object contains zero or more traps. Each trap corresponds to a basic operation, which is called directly or indirectly on the proxy object. Each time these basic operations are called on the proxy object, the proxy calls the trap function before these operations are propagated to the target object, thereby intercepting and modifying the corresponding behavior.

[0010] c. Set the capturer parameters. All capturers access the corresponding parameters and reconstruct the original behavior of the captured method based on these parameters. For example, the get() capturer will receive three parameters: the target object trapTarget, the property to be queried, and the proxy object receiver;

[0011] d. Call the reflection API corresponding to the capturer; all captured methods in the handler object have corresponding reflection API methods. These methods have the same name and function signature as the methods intercepted by the capturer, and also have the same behavior as the intercepted methods.

[0012] A further solution is that in step 1, during the proxy isClient process, when isClient on the proxy object is accessed, it is determined whether the current url path contains a token field. If the token field is contained, the get method is redefined and returned to true.

[0013] A further solution is that in step 1, during the proxy isClient process, when isClient on the proxy object is accessed, it is determined whether the current url path contains a token field. If the token field does not exist, the reflection API is used in the get method to return the Reflect.get(...arguments) method and map it to the flag attribute of the isClient object.

[0014] A further solution is that in step 2, the proxy object is exported through the module export mechanism in es6 for main.js to import, and in main.js, the global routing navigation guard is used to access GlobalData.proxy.isClient to intercept the current URL; if the current URL has a token field, the proxy object will automatically set the flag field in the isClient object to true and automatically jump to single sign-on, otherwise it will be set to false and automatically jump to subsystem login. Automatic switching between single sign-on and subsystem login is achieved.

[0015] A further solution is that in step 2, when entering the single sign-on state, and then clicking on logout, you will enter the subsystem login state. When you click on logout, the token field no longer exists on the url, and the proxy will set the flag field in the isClient object to false again, automatically jumping to the subsystem login state. You need to write isClient into sessionStorage, and get the isClient tag in sessionStorage when you click on logout.

[0016] The beneficial effects of the present invention are:

[0017] The present invention provides a method for realizing single sign-on and automatic switching of subsystem login based on es6, which utilizes the characteristic of es6 proxy for modifying the default behavior of certain operations to achieve the purpose of automatically processing attributes of objects in JavaScript language. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0019] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION

[0020] To make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be described in detail below. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other implementation methods obtained by ordinary technicians in this field without creative work belong to the scope of protection of the present invention.

[0021] In any embodiment, if Figure 1 As shown, a method for realizing single sign-on and automatic switching of subsystem login based on es6 of the present invention includes:

[0022] Step 1: Configure the global default flag isClient object in GlobalData.js. The flag attribute in this object is the flag for single sign-on and subsystem login, and the default value is false. (false means subsystem login, true means single sign-on).

[0023] Step 2: Instantiate the proxy in GlobalData.js, use the proxy feature of ES6, and reconstruct the get method of the object to intercept and automatically process attribute changes:

[0024] The proxy is created using the Proxy constructor, which receives two parameters: the target object and the handler object. The proxy instance is generated using the new keyword.

[0025] Define traps, which are "interceptors of basic operations" defined in the handler object. Each handler object can contain zero or more traps, each of which corresponds to a basic operation that can be called directly or indirectly on the proxy object. Each time these basic operations are called on the proxy object, the proxy can call the trap function before these operations are propagated to the target object, thereby intercepting and modifying the corresponding behavior.

[0026] Set the trap parameters. All trappers can access the corresponding parameters, based on which the original behavior of the captured method can be reconstructed. For example, the get() trapper will receive three parameters: the target object trapTarget, the property to be queried, and the proxy object receiver.

[0027] Call the reflection API corresponding to the capturer. All methods that can be captured in the handler object have corresponding reflection API methods. These methods have the same name and function signature as the methods intercepted by the capturer, and also have the same behavior as the intercepted methods.

[0028] In the proxy isClient process, when accessing isClient on the proxy object, determine whether the current URL path contains the token field. If it contains the token field, you can redefine the get method and return it true.

[0029] In the proxy isClient process, when accessing isClient on the proxy object, determine whether the current url path contains the token field. If the token field does not exist, use the reflection API in the get method to return the Reflect.get(...arguments) method and map it to the flag attribute of the isClient object.

[0030] After that, the proxy object is exported through the module export mechanism in es6 for main.js to import. In main.js, the global routing navigation guard is used to access GlobalData.proxy.isClient to intercept the current URL. If the current URL has a token field, the proxy object will automatically set the flag field in the isClient object to true and automatically jump to single sign-on. Otherwise, it will be set to false and automatically jump to subsystem login. This realizes the automatic switching between single sign-on and subsystem login.

[0031] It should be noted that when entering the single sign-on state and then clicking on logout, you will enter the subsystem login state. This is because the token field no longer exists on the url when you click on logout. The proxy will set the flag field in the isClient object to false again and automatically jump to the subsystem login state. The solution is to write isClient to sessionStorage and get the isClient tag in sessionStorage when you click on logout.

[0032] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of changes or replacements within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims. It should also be noted that the various specific technical features described in the above-mentioned specific embodiments can be combined in any suitable manner without contradiction. In order to avoid unnecessary repetition, the present invention will not further explain various possible combinations. In addition, the various different embodiments of the present invention are also arbitrarily combined, as long as they do not violate the concept of the present invention, they should also be regarded as the contents disclosed by the present invention.

Claims

1. A method for implementing single sign-on and automatic switching of subsystem login based on es6, characterized in that: The following steps are involved: Step 1: Configure the global default identifier isClient object in GlobalData.js. The flag attribute in the object is the identifier of single sign-on and subsystem login, and the default is false; in the step 1, in the proxy isClient process, when accessing isClient on the proxy object, determine whether the current url path contains the token field. If the token field is contained, redefine the get method and return true; in the step 1, in the proxy isClient process, when accessing isClient on the proxy object, determine whether the current url path contains the token field. If the token field does not exist, use the reflection API in the get method to return the Reflect.get method and map it to the flag attribute of the isClient object; Step 2: Instantiate the proxy in GlobalData.js, use the proxy feature of ES6, and reconstruct the get method of the object to intercept and automatically process attribute changes: a. The proxy is created using the Proxy constructor, which receives two parameters: the target object and the handler object, and generates a proxy instance using the new keyword; b. Define the capturer. The capturer is the "interceptor of basic operations" defined in the handler object. Each handler object contains zero or more capturers. Each capturer corresponds to a basic operation and is called directly or indirectly on the proxy object. Each time these basic operations are called on the proxy object, the proxy calls the capture function before these operations are propagated to the target object, thereby intercepting and modifying the corresponding behavior; c. Set the capturer parameters. All capturers access the corresponding parameters and reconstruct the original behavior of the captured method based on these parameters. d. Call the reflection API corresponding to the capturer; all captured methods in the handler object have corresponding reflection API methods; These methods have the same name and function signature as the method intercepted by the capturer, and also have the same behavior as the intercepted method; In the step 2, the proxy object is exported through the module export mechanism in es6 for introduction by main.js, and the global routing navigation guard is used in main.js to access GlobalData.proxy.isClient to intercept the current url; if the current url has a token field, the proxy object will automatically set the flag field in the isClient object to true and automatically jump to single sign-on, otherwise it is set to false and automatically jump to subsystem login.

2. A method for realizing single sign-on and automatic switching of subsystem login based on es6 as claimed in claim 1, characterized in that: In step 2, when you enter the single sign-on state and then click to log out, you will enter the subsystem login state. When you click to log out, the token field no longer exists on the url. The proxy will set the flag field in the isClient object to false again and automatically jump to the subsystem login state. You need to write isClient into sessionStorage and get the isClient tag in sessionStorage when you click to log out.