solr7.5 登陆验证 solrj配置登陆

首先需要配置登陆的用户信息,将用户信息放在/solrs/solr-7.5.0/server/etc中,新建文件role.properties

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

即用户为test 密码123  权限为admin

接下来需要在文件中插入安全处理程序设置标签  /solrs/solr-7.5.0/server/contexts

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

最后需要在配置中 web-inf/web.xml

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Restrict access to Solr admin</web-resource-name>
        <url-pattern>/admin/*</url-pattern>
        <http-method>DELETE</http-method>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
        <http-method>PUT</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>manager</role-name>
    </auth-constraint>
    <user-data-constraint>
        <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
</security-constraint>
<login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>default</realm-name>
</login-config>

solrj 验证时候

http://test:123@localhost:8888/solr/collection1

猜你喜欢

转载自blog.csdn.net/pontuss/article/details/83178854
今日推荐