Apache Karaf中的基本身份验证

时间:2012-07-26 16:30:42

标签: java osgi cxf basic-authentication apache-karaf

我有一个OSGi捆绑包,部署到Apache Karaf 2.2.8。在此捆绑包中,我使用CXFCamel路由。我编写了一个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中为特定端点设置基本认证参数?是否有某种配置文件或什么?我在网上找不到任何东西......

1 个答案:

答案 0 :(得分:0)

看看这里:https://access.redhat.com/documentation/en-US/Fuse_ESB_Enterprise/7.1/html/Security_Guide/files/CamelJetty-BasicAuth.html

非常清楚地说明了如何使用Apache KarafCamel Jetty进行基本身份验证。稍后您可以在Apache Karaf中部署的每个捆绑包上使用它。