solr 增加账号密码,solr 6.5 配置用户名密码

solr没有在管理界面增加修改用户名和密码的操作,那么我们在服务器配置完成后,总不能暴露在外吧!所以博主整理了下资料,可以通过配置文件增加用户名和密码。

进入这个文件下,/Users/sun/Documents/d/solr-6.5.1/server/etc,创建一个role.properties文件。

内容如下:

#    
# 这个文件定义用户名,密码和角色  
#    
# 格式如下    
#  <username>: <password>[,<rolename> ...]    
#    
#userName: password,role    
xxxxx: xxxxxx,xxxxxx   #例如:test:admin123,admin
然后进入 /Users/sun/Documents/d/solr-6.5.1/server/contexts 这个文件,修改下边的 solr-jetty-context.xml

<?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>
  <!-- 配置账号密码 -->
  <Get name="securityHandler">
         <Set name="loginService">
                 <New class="org.eclipse.jetty.security.HashLoginService">
                         <Set name="name">TestRealm</Set>  <!-- 这仅仅是一个名字而已-->
                        <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/role.properties</Set>
                 </New>
         </Set>
  </Get>
</Configure>

进入:/Users/sun/Documents/d/solr-6.5.1/server/solr-webapp/webapp/WEB-INF 修改 web.xml

Solr在5.0版本后,不再提供war包部署的方式,所以直接找上边这个目录即可。

<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>   <!-- 验证的角色,别写成用户名,如有多个角色可以写多个role-name 标签-->
       </auth-constraint>
   </security-constraint>
   <login-config>
          <auth-method>BASIC</auth-method>            <!-- 关键-->
          <realm-name>TestRealm</realm-name>
  </login-config>
  #在文件最后 </web-app> 之前增加即可

配置完成,重启服务!再访问的时候浏览器就会提示需要账号密码才能进入,如下图所示:


那么在程序中使用的时候,如何输入账号和密码呢? 看下边

url 格式修改成下边这种:

http://test:admin123@localhost:8983/solr/my_core 

引入必备依赖:

<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
<dependency> 
  <groupId>commons-codec</groupId>
  <artifactId>commons-codec</artifactId>
  <version>1.7</version>
</dependency>

相关阅读:

linux 系统安装 solr,以及各版本的下载地址

solr 6.5 配置中文分词 IK Analyzer

Java 对 solr 的增删改查,java源码


版权属于: 技术客

原文地址: https://www.sunjs.com/article/detail/17856d155b8b40c8b24cc214902aa6fd.html

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。




  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值