Solr 配置用户登录验证

作者: 宇宙小神特别萌 | 来源:发表于2019-08-23 14:49 被阅读0次
Solr 配置用户登录验证目录.png

首先下载最新版solr应用服务器压缩包,

1、下载 .zip 为windows版

我下载的最新版本地址:内嵌jeety服务器,solr5之前的版本都需要放到自己的tomcat里
下载:solr-8.2.0.zip
下载完成之后放在的D:\solr-8.2.0目录下,然后解压到当前目录

Solr解压目录结构.png

2、配置用户、密码、权限

配置的是Basic安全性验证:

Solr在5.0版本后,不再提供war包部署的方式,取而代之的是内置了jetty服务。但是我们发现其中并没有内置任何安全性相关检查,任何人如果知道了我们的外网地址就能直接访问并修改其中的索引。经过查找可以使用jetty的方式来限制web访问。

  1. 打开路径:solr-8.2.0\server\etc,在此目录下新建verify.properties 配置文件(名字随意),如图:
    配置权限认证.png

打开文件进行编辑 , 内容如下:格式为-用户名:密码,权限

# 用户名 密码 权限
user: pass,admin

也可配置多用户,内容如下:

# 用户名 密码 权限
user: pass,admin
user1: pass,admin
user3: pass,admin
  1. 接着找到目录:solr-8.1\server\contexts,文件列表如图:
    配置权限认证2.png

打开文件进行编辑,在文件configure中添加(添加配置权限认证)获取用户文件的配置:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath"><Property name="hostContext" default="/solr"/></Set>
  <Set name="war"><Property name="jetty.base"/>/solr-webapp/webapp</Set>
  <Set name="defaultsDescriptor"><Property name="jetty.base"/>/etc/webdefault.xml</Set>
  <Set name="extractWAR">false</Set>
    
    <!--添加配置权限认证:在文件configure中添加获取用户文件的配置,内容如下:-->
  <Get name="securityHandler">    
         <Set name="loginService">    
                 <New class="org.eclipse.jetty.security.HashLoginService">    
                        <Set name="name">verify—name</Set> 
                        <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/verify.properties</Set>    
                 </New>    
         </Set>    
  </Get>
    
</Configure>
  1. 第三处需要修改的地方为web.xml,如图:
    配置权限认证3.png

在文件中找到security-constraint的配置,内容如下:

  <!-- Get rid of error message -->
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Disable TRACE</web-resource-name>
      <url-pattern>/</url-pattern>
      <http-method>TRACE</http-method>
    </web-resource-collection>
    <auth-constraint/>
  </security-constraint>
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Enable everything but TRACE</web-resource-name>
      <url-pattern>/</url-pattern>
      <http-method-omission>TRACE</http-method-omission>
    </web-resource-collection>
  </security-constraint>

重新配置 security-resource-collection (删除之前的security-constraint,会导致登录的配置无效)
在auth-constraint节点添加角色 admin,并添加登录配置,如图:

 <!--重新配置 security-resource-collection (删除之前的security-constraint,会导致登录的配置无效)-->
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Solr</web-resource-name>
      <url-pattern>/</url-pattern>
    </web-resource-collection>   
     <auth-constraint>      
        <role-name>admin</role-name> 
     </auth-constraint> 
  </security-constraint>

    <login-config>      
            <auth-method>BASIC</auth-method> 
            <realm-name>verify-name</realm-name>   
    </login-config>

效果:


配置权限认证5.png

之后启动solr,访问solr地址:
http://localhost:8983/solr/#/

配置权限认证6.png

输入:user/pass
登录成功!

springboot通过solr地址中加入用户名密码的方式连接,地址如下:

spring:
  data:
      solr:  # 全文检索
        # solr加上了用户名密码访问条件,参数中并没有地方设置username和password,那应该怎么办?
        host: http://user:pass@127.0.0.1:8983/solr

相关文章

  • Solr 配置用户登录验证

    首先下载最新版solr应用服务器压缩包, 1、下载 .zip 为windows版 我下载的最新版本地址:内嵌jee...

  • Apache安全--用户登录验证

    用户登录验证登录验证介绍登录验证实现一、登录验证当用户访问网站或者网站某个目录时,如果希望用户提供授权才能登录,那...

  • shareSDK短信验证

    用户登录 短信验证步骤 用户登录模块采用短信验证的方式,登录用户,所以采用sharesdk进行短信验证 1 短信注...

  • 杨鑫

    《2.5登录用户验证功能设计》 (1)登录用户的验证功能的效果图: (2)登录用户的验证功能的描述: (3)后台数...

  • 白日梦APP接口示例

    常规APP接口示例 已添加接口 发送登录验证码 手机号登录/注册 微信号登录/注册 获取用户详细信息 常规配置 每...

  • 7.登录验证和登出

    一、FBV 方式1.1 登录验证并加入 session用户登录时,使用 authenticate 验证用户名和密码...

  • 2018-11-09 Solr学习笔记(四)-Solr5.5.5

    2018-11-09 Solr5.5.5服务器配置账号登录 [TOC] Solr服务部署之后,无论是谁,都能直接访...

  • 使用WebAPI实现图形验证码的步骤

    一、登录腾讯验证码接入平台 腾讯验证码接入平台接入与帮助->快速开始->登录... 二、新建验证码配置 根据配置文...

  • 2018-05-25

    2.6登录用户验证功能设计 1、验证过程 1.1主要功能 验证用户的登录信息 1.2数据表结构 收银员用户表(编辑...

  • API

    对外API系统接口用户接口: 用户登录类用户登录忘记密码 用户注册类请求获取验证码校验验证码设置密码 首页 首页-...

网友评论

    本文标题:Solr 配置用户登录验证

    本文链接:https://www.haomeiwen.com/subject/hkqtectx.html