【发布时间】:2015-10-28 19:23:13
【问题描述】:
我正在尝试使用基本身份验证并在 Mule 流程中获取凭据。
这是我的 Mule 流程:
<http:listener config-ref="httpConfig" path="/*" doc:name="HTTP" allowedMethods="get, post, delete" />
<apikit:router config-ref="api-config" doc:name="APIkit Router" />
<flow name="get:/sourcing/helloworld-secure:api-config">
<flow-ref name="authenticate-ldap" doc:name="authenticate-ldap"/>
</flow>
<flow name="authenticate-ldap">
<logger message="Name: #[message.inboundProperties.get('username')] Password:#[message.inboundProperties['password']] level="INFO"/>
<component class="com.test.AuthTest" doc:name="Java"/>
<logger message="After java: #[flowVars.username] #[flowVars.password]" level="INFO" doc:name="Logger"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<data-mapper:transform config-ref="Map_auth_to_ldap_request" doc:name="Map auth to ldap request"/>
</flow>
Java 代码:
public class AuthTest implements Callable {
@Override
public Map<String, String> onCall(MuleEventContext eventContext) throws Exception {
Map<String, String> authMap = new HashMap<String, String>();
final String authorization = eventContext.getMessage().getInboundProperty("authorization");
if (authorization != null && authorization.startsWith("Basic")) {
String base64Credentials = authorization.substring("Basic".length()).trim();
String credentials = new String(Base64.decode(base64Credentials), Charset.forName(Base64.PREFERRED_ENCODING));
if (credentials != null) {
final String[] values = credentials.split(":",2);
eventContext.getMessage().setInvocationProperty("username", values[0]);
eventContext.getMessage().setInvocationProperty("password", values[1]);
authMap.put("username", values[0]);
authMap.put("password", values[1]);
}
}
return authMap;
}
}
要运行这个应用程序,我在 Chrome 中使用 rest 客户端并选择基本身份验证,然后提供用户名和密码。
以上代码运行良好。我需要的不是在 Java 中获取凭据然后放入 Map,而是在不使用 Java 代码的情况下获取 Mule 流中的凭据。这可以直接在 Mule 流中实现吗?
我已经实现了 Spring 安全性,它工作正常,但在这种情况下,我需要用户输入凭据并继续进行。
【问题讨论】:
标签: mule