Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use web filter to add solr background login authentication

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use web filter to increase solr background login authentication", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use web filter to increase solr background login authentication" bar!

Solr backend comes with no login function, and the default access address is: http://localhost:8983/solr/#/( built-in jetty operation).

To add a login authentication method to the sorl background:

1. Login authentication using web server (e.g. jetty, tomcat)

The advantage of this approach is that you don't need to write additional code, you just need to configure the corresponding web server.

2. Use web filter to filter address verification

This approach is more flexible, but the disadvantage is that it requires a bit of code development.

This article introduces the second method:

SolrLoginFilter.javapackage com.penngo.solr;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.commons.lang3.StringUtils Public class SolrLoginFilter implements Filter {public void init (FilterConfig config) throws ServletException {} public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; HttpSession session = httpRequest.getSession (); String url = httpRequest.getRequestURL (). ToString (); String userAgent = httpRequest.getHeader ("user-agent"); String query = httpRequest.getQueryString (); String servletPath = httpRequest.getServletPath () String contextPath = httpRequest.getContextPath (); System.out.println ("url=" + ", url:" + url + ", servletPath:" + servletPath + ", contextPath:" + contextPath + ", query:" + query + ", userAgent:" + userAgent "); Object isLogin = session.getAttribute (" isLogin "); if (isLogin = = null | (boolean) isLogin)! = true) {String user = StringUtils.isEmpty (request.getParameter (" user ")) = false? Request.getParameter ("user"): "; String password = StringUtils.isEmpty (request.getParameter (" password ")) = = false? Request.getParameter ("password"): "; if (user.equals (" admin ") = = true & & password.equals (" 123") = = true) {session.setAttribute ("isLogin", true); httpResponse.sendRedirect (contextPath); return;} else {httpRequest.setCharacterEncoding ("UTF-8"); response.setContentType ("text/html;charset=UTF-8"); PrintWriter out = response.getWriter () Out.println (loginPage ()); out.close (); return;}} chain.doFilter (request, response) } public void destroy () {} private String loginPage () {String page = "\ n" + "\ n" + "user name:\ n" + "secret & nbsp code:\ n" + "login\ n" + "\ n" + "

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report