Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The method of automatic login of Druid

Shulou Source: shulou.com Published: 2022-06-02 08:27:56 10月02日 Update

This article mainly introduces "the method of automatic login of Druid". In the daily operation, I believe that many people have doubts about the method of automatic login of Druid. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "the method of automatic login of Druid". Next, please follow the editor to study!

How to log in automatically by Druid

First of all, explain why you should log in automatically.

You must have a password, otherwise others can access the project address + "/ druid" directly, which is not secure.

Do not want to have a second login (do not explain)

Realization idea

Menu configuration path toDruid

After the page is redirected, ajax triggers a doDruid.json request

After writing Filter in the background and determining that the path is doDruid, change the address to the login address.

How to confirm the login address

Directly on the Druid login page, press F12 to see the relevant code

Form form:

The username or password you entered is incorrect. Sign in Reset

Ajax submission Code:

$.ajax ({type: 'POST', url: "submitLogin", data: $("# loginForm"). Serialize (), success: function (data) {if ("success" = = data) location.href = "index.html"; else {$("# alertInfo"). Show (); $("# loginForm") [0] .reset () $("input [name=loginUsername]") .focus ();}}, dataType: "text"}); can be found

Login API: "/ submitLogin" request method: post request data type: text request parameter: loginUsername=druid&loginPassword=druid

How to realize it through Filter

Menu configuration toDruid, jump to a page of the system, this page calls the doDruid.json API. The page Ajax requests / doDruid, and Filter gets / doDruid to change the path to / submitLogin, and add the parameter account and password.

Filter Filter:

HttpServletRequest request = (HttpServletRequest) servletRequest;HttpServletResponse response = ((HttpServletResponse) servletResponse); String requestUrl = request.getRequestURL () .toString (); / / automatic login if for druid (requestUrl.contains ("moni/druid/doDruid.json")) {String queryString = "loginUsername=druid&loginPassword=druid"; / / get the full path StringBuffer url = new StringBuffer (requestUrl) / / get the path plus the project name String tempContextUrl = url.delete (url.length ()-request.getRequestURI (). Length (), url.length ()) .append (request.getServletContext (). GetContextPath ()) .append ("/"). ToString (); / * * construct a new address, which is actually the login address of druid * / URL newUrl = new URL (tempContextUrl + "druid/submitLogin?" + queryString); response.setStatus Response.setHeader ("Location", newUrl.toString ()); response.setHeader ("Connection", "close"); / / allow all cross-domain requests response.addHeader ("Access-Control-Allow-Origin", "*");}

Front-end page:

$(function () {autoLogin ();}) / * * automatic login @ author gaoyuan * / function autoLogin () {var loadingLayer = layer.load (1, {shade: [0.1) / / loading $.ajax ({type: 'get', url:' ${ctx} / moni/druid/doDruid.json?timeStamp='+new Date (). GetTime (), dataType: "text", data: {}, success: function (data) {layer.close (loadingLayer) If (data = = "success") {location.href = "${contextPath} / druid";} else {layer.msg ('automatic login error, please log in manually!' , {icon: 2}, function () {location.href = "${contextPath} / druid";});}, error:function () {layer.close (loadingLayer);}});}

There is not much about the setting of Druid. It is everywhere on the Internet.

At this point, visit the front-end page, trigger Ajax, and log in automatically. After the login is successful, you will jump to the druid page and you are done!

At this point, the study of "Druid automatic login method" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Login page address method path learning code front-end parameters password interface more menu project help configuration practical security success done Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Xiaomi MySQL Shulou Tech Info vpn