solr -- 配置用户名和密码

Solr在5.0版本后,不再提供war包部署的方式:

  1: 在D:\apache-solr-4.0.0\apache-solr-4.0.0\example\etc目录下新建role.properties文件,名字可随便。

#  
# 这个文件定义用户名,密码和角色
#  
# 格式如下  
#  <username>: <password>[,<rolename> ...]  
#  
#userName: password,role  
test: 123,admin

2: 编辑D:\apache-solr-4.0.0\apache-solr-4.0.0\example\contexts\solr.xml文件如下,文件中插入安全处理程序设置标签

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/solr</Set>
  <Set name="war"><SystemProperty name="jetty.home"/>/webapps/solr.war</Set>
  <Set name="defaultsDescriptor"><SystemProperty name="jetty.home"/>/etc/webdefault.xml</Set>
  <Set name="tempDirectory"><Property name="jetty.home" default="."/>/solr-webapp</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/realm.properties</Set>  
                 </New>  
         </Set>  
  </Get> 
</Configure>

3: 编辑D:\apache-solr-4.0.0\apache-solr-4.0.0\example\solr-webapp\webapp\WEB-INF\web.xml文件,插入

<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>

4:重启服务就可以了。


相关链接:https://www.cnblogs.com/hihtml5/p/5775896.html

                http://www.mossle.com/docs/auth/html/ch109-preauth.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,对于在SSM项目中整合Solr配置用户名密码的问题,可以按照以下步骤进行操作: 1. 首先,需要在Solr配置文件中配置安全认证和授权信息。具体可以参考Solr的官方文档,例如在 solrconfig.xml 中添加如下配置: ```xml <security> <user> <username>solr</username> <password>password</password> <roles> <role>admin</role> </roles> </user> </security> ``` 其中,`<username>` 和 `<password>` 分别为Solr用户名密码,`<roles>` 可以配置该用户所拥有的角色,例如上面的配置中该用户拥有 `admin` 角色。 2. 在SSM项目中,需要引入 SolrJ 的相关依赖,例如: ```xml <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-solrj</artifactId> <version>8.9.0</version> </dependency> ``` 3. 在代码中,使用 SolrJ 进行连接 Solr 服务器,其中需要指定 Solr用户名密码,例如: ```java String solrUrl = "http://localhost:8983/solr/"; String username = "solr"; String password = "password"; SolrClient solrClient = new HttpSolrClient.Builder(solrUrl) .withBasicAuthCredentials(username, password) .build(); ``` 在以上代码中,`solrUrl` 为 Solr 服务器的地址,`username` 和 `password` 分别为配置Solr 用户名密码。使用 `HttpSolrClient.Builder` 进行创建 `SolrClient` 实例,通过 `withBasicAuthCredentials` 方法设置用户名密码即可实现访问 Solr 服务器。 希望这些能够对你有所帮助。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值