【问题标题】:Credentials for ActiveMQ/Jolokia/HawtIO through Java通过 Java 获得 ActiveMQ/Jolokia/HawtIO 的凭证
【发布时间】:2013-11-13 05:59:33
【问题描述】:

我知道 5.9.0 的 HawtIO/Jolokia 的默认密码是在 \conf\ 文件夹中设置的,并且是

管理员/管理员 系统/经理 等等

但是,当尝试通过 Java 执行 restful 命令时,这些密码都不起作用:

CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(null, -80), new UsernamePasswordCredentials("admin", "admin"));
CloseableHttpClient httpclient0 = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
URI uri0 = URI.create("http://localhost:8161/hawtio/auth/login/");
HttpGet httpget = new HttpGet(uri0);
HttpResponse r0 = httpclient0.execute(httpget);
System.out.println("Login form get: " + r0.getStatusLine());
for (Header h : r0.getAllHeaders())
  System.out.println(h.getName() + "/" + h.getValue());
HttpEntity entity = r0.getEntity();

InputStream is0 = entity.getContent();
String resp = IOUtils.toString(is0);
System.out.println("Response0: " + resp);

下面的代码只是返回一个 403 Forbidden 回复!我尝试了很多用户名和密码的组合。

Login form get: HTTP/1.1 403 Forbidden
Access-Control-Allow-Origin/*
Content-Length/0
Server/Jetty(7.6.9.v20130131)

这里有什么作用?

我记得在运行 5.8.0 时,“admin/admin”可以工作,但我想改用 5.9.0。仅仅因为用户名和密码改变了就退出这个版本是很糟糕的。

此外,哪个 \conf 文件规定了此密码...?

【问题讨论】:

    标签: java apache activemq hawtio jolokia


    【解决方案1】:

    您几乎已经完成了,您只需要 POST 到该 URL 而不是执行 GET。您只需在 Authorization 标头中设置您的用户名/密码。 hawtio 中的身份验证过滤器避免发回 401,因为这会使浏览器身份验证提示出现,因此您看不到返回 401。

    【讨论】:

    • 宾果游戏!谢谢!我有点希望我设置并附加到我的 httpclient 变量的凭据能够自动或通过设置翻转完成此操作,但无论哪种方式我都已连接!
    猜你喜欢
    • 1970-01-01
    • 2013-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-30
    • 2015-02-26
    • 1970-01-01
    • 2021-10-20
    相关资源
    最近更新 更多