首页 \ 问答 \ 使用Spring Data Solr验证SolrCore(Authenticating SolrCore using Spring Data Solr)

使用Spring Data Solr验证SolrCore(Authenticating SolrCore using Spring Data Solr)

我有一个服务(API),它连接到solr以获取数据并作为响应发送。现在我们在Solr上没有任何类型的安全层,因此我的API工作正常。但事情发生了变化,并且所有核心都添加了有界性层进行认证。 我在API中连接到Core时遇到问题。 以下是我的Java连接类:

@Configuration
@EnableConfigurationProperties
public class SolrConfigs {

private static final Logger LOG = LoggerFactory.getLogger(SolrConfigs.class);

@Value("${solr.core.FirstCore}")
private String coreFirstCore;

@Value("${solr.core.SecondCore}")
private String coreSecondCore;

@Value("${solr.core.ThirdCore}")
private String coreThirdCore;

@Bean
@ConfigurationProperties(prefix = "solr.client")
public SolrClient solrClient(@Value("${solr.client.baseURL}") final String solrBaseUrl) {
    LOG.info("Connecting to solr : {}", solrBaseUrl);
    final HttpSolrClient client = new HttpSolrClient(solrBaseUrl);
    return client;
}

@Bean
public MulticoreSolrClientFactory multicoreSolrClientFactory(final SolrClient solrClient) {
    final MulticoreSolrClientFactory factory = new MulticoreSolrClientFactory(solrClient, Arrays.asList(coreFirstCore, coreSecondCore, coreThirdCore));
    return factory;
}

@Bean(name = "solrFirstCoreTemplate")
public SolrTemplate solrFirstCoreTemplate(MulticoreSolrClientFactory multicoreSolrClientFactory) {
    final SolrTemplate template = new SolrTemplate(multicoreSolrClientFactory);
    template.setSolrCore(coreFirstCore);
    return template;
}

@Bean(name = "solrSecondCoreTemplate")
public SolrTemplate solrSecondCoreTemplate(final MulticoreSolrClientFactory multicoreSolrClientFactory) {
    final SolrTemplate template = new SolrTemplate(multicoreSolrClientFactory);
    template.setSolrCore(coreSecondCore);
    return template;
}

@Bean(name = "solrThirdCoreTemplate")
public SolrTemplate solrThirdCoreTemplate(final MulticoreSolrClientFactory multicoreSolrClientFactory) {
    final SolrTemplate template = new SolrTemplate(multicoreSolrClientFactory);
    template.setSolrCore(coreThirdCore);
    return template;
}

}

有没有办法将凭据传递给每个核心? 我尝试过这样的东西

@Bean
@ConfigurationProperties(prefix = "solr.client")
public SolrClient solrClient(@Value("${solr.client.baseURL}") final String solrBaseUrl) {
    LOG.info("Connecting to solr : {}", solrBaseUrl);
    final HttpSolrClient client = new HttpSolrClient(solrBaseUrl);
    return client;
}

@Bean(name = "solrFirstCoreTemplate")
public SolrTemplate solrFirstCoreTemplate(SolrClient solrClient) {
    Credentials credentials = new UsernamePasswordCredentials(username, password);
    final SolrTemplate template = new SolrTemplate(new HttpSolrClientFactory(solrClient, coreFirstCore, credentials , "BASIC"));
    template.setSolrCore(coreFirstCore);
    return template;
}

@Bean(name = "solrSecondCoreTemplate")
public SolrTemplate solrSecondCoreTemplate(SolrClient solrClient) {
    Credentials credentials = new UsernamePasswordCredentials(username, password);
    final SolrTemplate template = new SolrTemplate(new HttpSolrClientFactory(solrClient, coreSecondCore, credentials , "BASIC"));
    template.setSolrCore(coreSecondCore);
    return template;
}

它没有工作。


I have an Service(API) which connects to solr to fetch data and sends as response.Till now we didn't had any type of security layer on Solr so my API was working fine.But things changed and all core's were added with sceurity layer for authentication. I am facing problem while connecting to Core in my API. Following is my Java class for connection :

@Configuration
@EnableConfigurationProperties
public class SolrConfigs {

private static final Logger LOG = LoggerFactory.getLogger(SolrConfigs.class);

@Value("${solr.core.FirstCore}")
private String coreFirstCore;

@Value("${solr.core.SecondCore}")
private String coreSecondCore;

@Value("${solr.core.ThirdCore}")
private String coreThirdCore;

@Bean
@ConfigurationProperties(prefix = "solr.client")
public SolrClient solrClient(@Value("${solr.client.baseURL}") final String solrBaseUrl) {
    LOG.info("Connecting to solr : {}", solrBaseUrl);
    final HttpSolrClient client = new HttpSolrClient(solrBaseUrl);
    return client;
}

@Bean
public MulticoreSolrClientFactory multicoreSolrClientFactory(final SolrClient solrClient) {
    final MulticoreSolrClientFactory factory = new MulticoreSolrClientFactory(solrClient, Arrays.asList(coreFirstCore, coreSecondCore, coreThirdCore));
    return factory;
}

@Bean(name = "solrFirstCoreTemplate")
public SolrTemplate solrFirstCoreTemplate(MulticoreSolrClientFactory multicoreSolrClientFactory) {
    final SolrTemplate template = new SolrTemplate(multicoreSolrClientFactory);
    template.setSolrCore(coreFirstCore);
    return template;
}

@Bean(name = "solrSecondCoreTemplate")
public SolrTemplate solrSecondCoreTemplate(final MulticoreSolrClientFactory multicoreSolrClientFactory) {
    final SolrTemplate template = new SolrTemplate(multicoreSolrClientFactory);
    template.setSolrCore(coreSecondCore);
    return template;
}

@Bean(name = "solrThirdCoreTemplate")
public SolrTemplate solrThirdCoreTemplate(final MulticoreSolrClientFactory multicoreSolrClientFactory) {
    final SolrTemplate template = new SolrTemplate(multicoreSolrClientFactory);
    template.setSolrCore(coreThirdCore);
    return template;
}

}

Is there any way to pass on credentials to each core ? I tried someting like this

@Bean
@ConfigurationProperties(prefix = "solr.client")
public SolrClient solrClient(@Value("${solr.client.baseURL}") final String solrBaseUrl) {
    LOG.info("Connecting to solr : {}", solrBaseUrl);
    final HttpSolrClient client = new HttpSolrClient(solrBaseUrl);
    return client;
}

@Bean(name = "solrFirstCoreTemplate")
public SolrTemplate solrFirstCoreTemplate(SolrClient solrClient) {
    Credentials credentials = new UsernamePasswordCredentials(username, password);
    final SolrTemplate template = new SolrTemplate(new HttpSolrClientFactory(solrClient, coreFirstCore, credentials , "BASIC"));
    template.setSolrCore(coreFirstCore);
    return template;
}

@Bean(name = "solrSecondCoreTemplate")
public SolrTemplate solrSecondCoreTemplate(SolrClient solrClient) {
    Credentials credentials = new UsernamePasswordCredentials(username, password);
    final SolrTemplate template = new SolrTemplate(new HttpSolrClientFactory(solrClient, coreSecondCore, credentials , "BASIC"));
    template.setSolrCore(coreSecondCore);
    return template;
}

It didnt work out.


原文:https://stackoverflow.com/questions/49733669
更新时间:2023-10-09 08:10

最满意答案

在你的例子中,这是一个编译器错误。

然而,我认为你想要做的是这样的:

int n =23, *p;
p = &n;
//Change the value of p to 3000, p now points to address 3000
p = reinterpret_cast<int*>(3000); 
//Check if the address of n has changed
std::cout << "Address of n : " << reinterpret_cast<int>(&n) << std::endl; 

正如你在运行这段代码时所说的那样。 n的地址不变。

对于你的第二个问题。

是和否:)

如果你定义了两个相邻的变量,它们可能在内存中彼此相邻。

 int a,b,c,d;
 char c = 1;
 short s = 1;
 void* p = nullptr;
 int i = 1;

 std::cout << "a is at: " << reinterpret_cast<int>(&a) << std::endl;
 std::cout << "b is at: " << reinterpret_cast<int>(&b) << std::endl;
 std::cout << "c is at: " << reinterpret_cast<int>(&c) << std::endl;
 std::cout << "d is at: " << reinterpret_cast<int>(&d) << std::endl;
 std::cout << "Char is at: " << reinterpret_cast<int>(&c) << std::endl;
 std::cout << "Short is at: " << reinterpret_cast<int>(&s) << std::endl;
 std::cout << "Pointer is at: " << reinterpret_cast<int>(p) << std::endl;
 std::cout << "Int is at: " << reinterpret_cast<int>(&i) << std::endl;

这种行为会导致编译器确定在哪里进行转义。 它可能相邻,也可能不相邻。 如果您想确保它们彼此相邻,请使用数组。

int arr[] = {1,2,3,4,5,6,7};
int * p = &arr[0]; //get address of first element
for(int i = 0 ; i < 7; ++i)
    std::cout << "Value at address: " << reinterpret_cast<int>(p+i) 
        << " is: " << *( p + i) << std::endl;

In your example this is a compiler error.

However what I assume you wanted to do was this:

int n =23, *p;
p = &n;
//Change the value of p to 3000, p now points to address 3000
p = reinterpret_cast<int*>(3000); 
//Check if the address of n has changed
std::cout << "Address of n : " << reinterpret_cast<int>(&n) << std::endl; 

As you can tell when you run this code. The address of n does not change.

For your second question.

Yes and No :)

If you define two variables next to each other they may be next to each other in memory.

 int a,b,c,d;
 char c = 1;
 short s = 1;
 void* p = nullptr;
 int i = 1;

 std::cout << "a is at: " << reinterpret_cast<int>(&a) << std::endl;
 std::cout << "b is at: " << reinterpret_cast<int>(&b) << std::endl;
 std::cout << "c is at: " << reinterpret_cast<int>(&c) << std::endl;
 std::cout << "d is at: " << reinterpret_cast<int>(&d) << std::endl;
 std::cout << "Char is at: " << reinterpret_cast<int>(&c) << std::endl;
 std::cout << "Short is at: " << reinterpret_cast<int>(&s) << std::endl;
 std::cout << "Pointer is at: " << reinterpret_cast<int>(p) << std::endl;
 std::cout << "Int is at: " << reinterpret_cast<int>(&i) << std::endl;

This behavior is caused the compiler determining where to stick everthting. It may or may not exist next to each other. If you want to guarantee they exist next to one another, use an array.

int arr[] = {1,2,3,4,5,6,7};
int * p = &arr[0]; //get address of first element
for(int i = 0 ; i < 7; ++i)
    std::cout << "Value at address: " << reinterpret_cast<int>(p+i) 
        << " is: " << *( p + i) << std::endl;

相关问答

更多
  • 无论它是什么, operator new函数都不是任何类的非静态成员函数。 即使您声明并定义了一个特定于类的运算符new,它也被认为是一个静态成员函数; 如果它需要一个size_t参数,那么指向它的指针将为void* (*ptrToNew)( size_t ) 。 (如果它是一个新的位置,当然会有更多的参数。) 当您执行new Foo ,编译器首先在Foo的范围内对operator new进行名称查找(如果Foo是类类型),然后在全局命名空间中。 (有趣的是,编译器不会查看声明Foo的命名空间Foo也不会应 ...
  • 我正在定义一个指向什么都没有然后设置其值的指针? 它为什么设置了值? 随机内存插槽? 在哪里? 在堆栈还是堆? 好吧,相当。 没有答案。 从字面上看,结果是不确定的。 它可以向我的右眼发送电磁脉冲。 为什么有人创建一个类只是为了写一个做某事的函数? 存在无能。 我真的不明白MyClass这个类,doSomething实际上是否有可能填充某些数据结构? 这是可能的,但我们不能在没有看到它的情况下告诉你。 如果是,那么它是如何以及在哪里它也是一个指向什么的指针? 有些人认为他们可以通过狡猾的指针调用成员函数,只 ...
  • 你正在传递指针,但你没有分配内存。 所以他们指向内存中的随机位置。 int computeMoveLocation(int* r, int* c, char* board) { //some code up here *r = 0; //This breaks the program *c = 0; } 坏主要: int main() { int *r; int *c; char *board; // bad, passing in point ...
  • 在你的例子中,这是一个编译器错误。 然而,我认为你想要做的是这样的: int n =23, *p; p = &n; //Change the value of p to 3000, p now points to address 3000 p = reinterpret_cast(3000); //Check if the address of n has changed std::cout << "Address of n : " << reinterpret_cast(&n) < ...
  • uint8_t* buffer, curr, next; 你写它的方式, buffer是一个指针和curr , next只是uint8_t s。 你可能意思是: uint8_t *buffer, *curr, *next; 更好的(不太容易出错)就是让每个领域都有自己的路线。 uint8_t* buffer, curr, next; The way you wrote it, buffer is a pointer and curr and next are mere uint8_t ...
  • *p = 1将最后一个字节(char)设置为000000001 当你将char转换为int类型时, (int)1000的(binary)0000001111101000是(binary)0000001111101000你正在为最后8位i(e) (binary)0000001100000001即769 (binary)0000001100000001分配(int)1 。 使用256512工作,因为您更改的最后8位全部为零,即(int)256512 is (binary)111110101000000000因此 ...
  • 尝试*(up)->ux; 这是up指针保存的值,并从该值中选择ux字段 Even I do not understand why it is not working by the standard way, I've found the working solution: void point3D_Compute(struct point3D *uP) { double cx, cy, cz; double *pCx, *pCy; pCx = &cx; pCy = &cy; ...
  • 我的回答:你很幸运! 事实是,你碰巧在p中的值是一个有效的内存地址,你可以实际写入,这就是为什么它的工作原理... 尝试在编译器中使用优化选项(-O3),而不是获得不同的结果...... My answers: You're lucky! The fact is, the value you happen to have in p is a valid memory address, that you can actually write to, this is why it works... Try pl ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)