大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要讲解了“怎么用web过滤器增加solr后台登录验证”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么用web过滤器增加solr后台登录验证”吧!
为北票等地区用户提供了全套网页设计制作服务,及北票网站建设行业解决方案。主营业务为成都网站设计、网站制作、外贸营销网站建设、北票网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
solr后台自带是没有登录功能的,默认访问地址是:http://localhost:8983/solr/#/(内置jetty运行)。
要给sorl后台增加登录验证方法:
1、使用web服务器的登录验证(例如jetty、tomcat)
这种方式好处是不需要另外写代码,只需配置一下对应的web服务器就行了。
2、使用web过滤器过滤地址验证
这种方法是更加灵活,缺点是需要点代码开发。
本文介绍的是第二种方法:
SolrLoginFilter.java package 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" + "\n" + "\n" + ""; return page; } }
在原来的web.xml中增加过滤器配置
SolrLoginFilter com.penngo.solr.SolrLoginFilter SolrLoginFilter / SolrRequestFilter org.apache.solr.servlet.SolrDispatchFilter excludePatterns /partials/.+,/libs/.+,/css/.+,/js/.+,/img/.+,/templates/.+ SolrRequestFilter /* LoadAdminUI org.apache.solr.servlet.LoadAdminUiServlet SolrRestApi org.restlet.ext.servlet.ServerServlet org.restlet.application org.apache.solr.rest.SolrSchemaRestApi LoadAdminUI /index.html SolrRestApi /schema/* .xsl application/xslt+xml index.html Disable TRACE / TRACE Enable everything but TRACE / TRACE
运行结果:
感谢各位的阅读,以上就是“怎么用web过滤器增加solr后台登录验证”的内容了,经过本文的学习后,相信大家对怎么用web过滤器增加solr后台登录验证这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!