问题描述
[ disclamer ]我不是Java开发人员。我可能会遗漏明显的要点
我正在编写一个库,以使用基本身份验证保护wso2 ESB(v.6.5.0)公开的REST API。我从this documentation指向this code sample开始。它的工作原理很像魅力,但是主要的限制是凭证是经过硬编码的
public class BasicAuthHandler implements Handler {
....
public boolean processSecurity(String credentials) {
String decodedCredentials = new String(new Base64().decode(credentials.getBytes()));
String userName = decodedCredentials.split(":")[0];
String password = decodedCredentials.split(":")[1];
if ("admin".equals(userName) && "some_password".equals(password)) {
return true;
} else {
return false;
}
}
如果我可以从governance registry检索凭据,那将非常好,这样我就可以在不同的环境中使用相同的库。问题是:我不确定如何。
第一个路径:使用WSO2 Carbon Kernel Core
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.registry.core</artifactId>
<version>4.4.26</version>
</dependency>
这方面的知识很棒,但我不确定要使用哪个类或方法。此软件包是否包含检索注册表项的相关方法?是最新的吗?
public class BasicAuthHandler implements Handler {
....
private Properties getPropertiesFromGovernanceFile(String location) {
Properties properties = null;
try {
properties = SomeAmazingClass.getRegistryProperties("/_system/governance/" + location);
} catch (Exception e) {
e.printstacktrace();
}
return properties;
}
public boolean processSecurity(String credentials) {
String decodedCredentials = new String(new Base64().decode(credentials.getBytes()));
String userName = decodedCredentials.split(":")[0];
String password = decodedCredentials.split(":")[1];
if (getPropertiesFromGovernanceFile("users/ei_user").equals(userName) && getPropertiesFromGovernanceFile("secrets/ei_password").equals(password)) {
return true;
} else {
return false;
}
}
路径二:cabon gouvernance client
在这种情况下我应该使用什么类?您能否指出一些提取注册表值的源代码或示例,以便我对如何做有一个小小的想法?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)