前言:请各大网友尊重本人原创知识分享,谨记本人博客:南国以南i

背景solr默认安装没带权限控制,每次进入页面直接操作都有点裸奔的感觉。

一、SolrCloud集群模式

说明:要使用基本身份验证您必须先创建一个security.json文件,对于基本身份验证,security.json文件必须有一个authentication部分,它定义用于身份验证的类。可以在创建文件时添加用户名和密码(例如:sha256(password+salt) hash),或者可以稍后使用基本验证API添加。

1.示例security.json显示了如下所示的显示两个部分:

{
"authentication":{ 【1】
"blockUnknown": true, 【2】
"class":"solr.BasicAuthPlugin",
"credentials":{"solr":"IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c="} 【3】
},
"authorization":{
"class":"solr.RuleBasedAuthorizationPlugin",
"permissions":[{"name":"security-edit",
"role":"admin"}], 【4】
"user-role":{"solr":"admin"} 【5】
}
} 以下的解释对应于上述的序号:
1.启用基本身份验证和基于规则的授权插件。
2.参数 "blockUnknown": true 表示不允许未经身份验证的请求通过。
3.已定义了一个名为 "solr" 的用户,其中有密码 "SolrRocks"。
4."admin" 角色已定义,并且具有编辑安全设置的权限。
5."solr" 用户已被定义为 "admin" 角色。

SolrCloud模式必须上传security.json到ZooKeeper。首先登入ZooKeeper终端,输入示例命令(内json字段已在上述说明)

#进入ZooKeeper终端
./zkCli.sh

#修改ZooKeeper内security.josn节点文件
set /security.json '{"authentication":{"blockUnknown":true,"class":"solr.BasicAuthPlugin","credentials":{"solr":"IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c="}},"authorization":{"class":"solr.RuleBasedAuthorizationPlugin","permissions":[{"name":"security-edit","role":"admin"}],"user-role":{"solr":"admin"}}}'

2.重启solr访问,此时solr必须输入用户名和密码进行登入验证,这里配置了用户名密码是:solr:SolrRocks

3.solr用户管理Api

#新增或修改密码(如果用户名存在,就修改密码,否则就创建用户)
curl --user solr:SolrRocks http://localhost:8983/api/cluster/security/authentication -H 'Content-type:application/json' -d '{"set-user": {"solr":"solr","tom":"tom"}}' #删除用户
curl --user solr:SolrRocks http://localhost:8983/api/cluster/security/authentication -H 'Content-type:application/json' -d '{"delete-user": ["tom"]}'

二、Solr单机部署模式

1.修改tomcat/conf/tomcat-user.xml配置,添加用户名、密码

<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<tomcat-users>
<!--
NOTE: By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application. If you wish to use this app,
you must define such a user - the username and password are arbitrary.
-->
<!--
NOTE: The sample user and role entries below are wrapped in a comment
and thus are ignored when reading this file. Do not forget to remove
<!.. ..> that surrounds them. <role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
-->
<!-- 用户名:solr、密码:solr、roles:用户级别-->
<user username="solr" password="solr" roles="admin,manager"/>
</tomcat-users>

2.修改tomcat/webapps/solr/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>

3.重启solr访问,此时solr必须输入用户名和密码进行登入验证,这里配置了用户名密码是:solr:solr

参考链接一参考链接二参考链接三、

我是南国以南i记录点滴每天成长一点点,学习是永无止境的!转载请附原文链接!!!

Solr安全控制,开启基本身份验证的更多相关文章

  1. 使用 OpenSSL 为 Nginx 创建自签名证书 并开启客户端身份验证

    本文章默认读者了解Openssl,CA,网站证书相关知识,直接实战!配置完成后,浏览器会显示"安全的HTTPS"连接.不会像其他文章那样,是红色警告的证书提示. 准备环境 笔者使用 ...

  2. 证明你是你——快速开启Windows Azure多重身份验证

    中国版Windows Azure的多重身份验证(Multi-Factor Authentication)功能已经开放.这个功能说白了就是要“证明你是你”.目前可以支持以下几种验证方式: 手机,短信验证 ...

  3. 部署开启了Kerberos身份验证的大数据平台集群外客户端

    转载请注明出处 :http://www.cnblogs.com/xiaodf/ 本文档主要用于说明,如何在集群外节点上,部署大数据平台的客户端,此大数据平台已经开启了Kerberos身份验证.通过客户 ...

  4. 关于WEB Service&WCF&WebApi实现身份验证之WebApi篇

    之前先后总结并发表了关于WEB Service.WCF身份验证相关文章,如下: 关于WEB Service&WCF&WebApi实现身份验证之WEB Service篇. 关于WEB S ...

  5. MVC启动windows身份验证时初次访问特别慢

    最近做了一个关于MVC的项目,刚开始往服务器上面部署时,没有开启windows身份验证,等开发基本收尾时候,将验证开启时,第一次打开的时候需要将近15s的访问时间,别说用户受不了,自己都受不了了. 对 ...

  6. C# 实现身份验证之WebApi篇

    今天再来总结关于如何实现WebApi的身份验证,以完成该系列所有文章,WebApi常见的实现方式有:FORM身份验证.集成WINDOWS验证.Basic基础认证.Digest摘要认证  第一种:FOR ...

  7. vs如何在Windows身份验证下调试Web项目

    vs做的Web项目发布到IIS站点后,通常我们还希望利用vs来调试代码.如果Web在IIS中设置成了Windows身份验证,那么我们如何在vs调试的时候,也同样采用Windows身份认证进行调试呢? ...

  8. 利用SharePoint项目改造的Web项目问题——Windows身份验证

    最近领导交给一个项目:改造现有的SharePoint项目.UI层是做好的,只需要把实现的所有接口方法重新实现一遍,改造成Web版的实现方式. 现在要做基于Windows身份认证的登陆: 配置IIS—— ...

  9. windows版本 MongoDB副本集搭建及开启身份验证

    ------------恢复内容开始------------ ------------恢复内容开始------------ MongoDB副本集搭建 我搭建的是一个主节点,两个副节点 构建目录结构如下 ...

  10. SQLSERVER误删除了Windows登录用户验证方式使用Windows身份验证的解决方法

    SQLSERVER误删Windows登录用户验证方式使用Windows身份验证的解决方法 今天看到这篇文章:没有了SA密码,无法Windows集成身份登录,DBA怎么办? 想起来之前着急哥问我的一个问 ...

随机推荐

  1. Dockerfile和docker-compose详解

    Dockerfile镜像制作 docker/podman中, 镜像是容器的基础,每次执行docker run的时候都会指定哪个基本镜像作为容器运行的基础.我们之前的docker的操作都是使用来自doc ...

  2. ubantu18.04使用APT安装go环境指令报错解决方案

    在ubantu下使用sudo apt install golang-go指令安装go环境,安装过程没有报错,在使用时无法识别指令,报错如下: root@sh001:~# go env -w GOPRO ...

  3. Oracle触发器联合唯一约束

    Oracle支持可为空字端的唯一约束呢?下面就是用触发器作出的限制语句,仅供参考: CREATE OR REPLACE TRIGGER Tg_Completion_Test BEFORE INSERT ...

  4. 【Azure 环境】 介绍两种常规的方法来监视Window系统的CPU高时的进程信息: Performance Monitor 和 Powershell Get-Counter

    问题描述 部署在Azure上的VM资源,偶尔CPU飙高,但是发现的时候已经恢复,无法判断当时High CPU原因. 在Windows系统中,有什么方式能记录CPU被进程占用情况,查找出当时是排名前列的 ...

  5. TCP 中的 Delay ACK 和 Nagle 算法

    哈喽大家好,我是咸鱼. 今天分享一篇大佬的文章,作者:卡瓦邦噶! 文章链接:https://www.kawabangga.com/posts/5845 教科书介绍的 TCP 内容通常比较基础:包括三次 ...

  6. 16 Educational Codeforces Round 142 (Rated for Div. 2)C. Min Max Sort(递归、思维、dp)

    C. Min Max Sort 很不错的一道题目,不过脑电波和出题人每对上,\(qwq.\) 正难则反. 我们考虑最后一步是怎么操作的. 最后一步一定是对\(1\)和\(n\)进行操作 那么上一步呢? ...

  7. MDC实现微服务链路追踪

    一.问题背景 在微服务架构中,我们没办法快速定位用户在一次请求中对应的所有日志,在排查生产问题的时候会非常困难,那是因为我们在输出的日志的时候没把请求的唯一标示输出到我们的日志中,导致我们没办法根据一 ...

  8. matting tool by cs - 视频扣绿幕 1.4 - 软件推荐

    本地软件,还没用,先留个档,试试 第一个下载还套了个广告壳,醉了,但是能用 https://www.123pan.com/s/X3jA-POMQv 这个装了,是原版,没套壳 https://pan.b ...

  9. day05-Lombok、SpringInitializer

    Lombok.Spring-Initializer 1.Lombok 1.1Lombok介绍 Lombok的作用是: 简化Javabean的开发,可以使用Lombok的注解让代码更加简洁 Java项目 ...

  10. python学习笔记(4):面向对象

    面向对象 定义 class Student(被继承类): def __init__(self, xx, xxx): #构造函数 类方法的第一个参数一定是self.除此之外和普通函数并没有区别.同样可以 ...