我有一个OSGi
捆绑包,部署到Apache Karaf 2.2.8
。在此捆绑包中,我使用CXF
和Camel
路由。我编写了一个CXF
拦截器来执行基本身份验证:从数据库中获取所有现有用户并进行验证。
问题是当调用方法handleMessage
时,AuthorizationPolicy
对象为空。它不提供任何凭据。这是我的代码:
@Override
public void handleMessage(Message message)
throws Fault {
AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
if (users == null) {
setLastAccessedTime(Calendar.getInstance());
}
if (!wasRecentlyAccessed()) {
users = this.loadUsers();
setLastAccessedTime(Calendar.getInstance());
}
for (String user : users.values()) {
LOGGER.debug("Existing user: " + user);
}
if (policy == null) {
LOGGER.error("User attempted to log in with no credentials");
sendErrorResponse(message, HttpURLConnection.HTTP_UNAUTHORIZED);
return;
}
String password = users.get(policy.getUserName());
if (password == null || !policy.getPassword().equals(password)) {
LOGGER.error("Invalid login authentication for user: " + policy.getUserName());
sendErrorResponse(message, HttpURLConnection.HTTP_FORBIDDEN);
}
}
我是否可以在Karaf中为特定端点设置基本认证参数?是否有某种配置文件或什么?我在网上找不到任何东西......
答案 0 :(得分:0)
非常清楚地说明了如何使用Apache Karaf
和Camel Jetty
进行基本身份验证。稍后您可以在Apache Karaf
中部署的每个捆绑包上使用它。