【问题标题】:Basic Authentication in Apache KarafApache Karaf 中的基本身份验证
【发布时间】:2012-07-26 16:30:42
【问题描述】:

我有一个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 中为特定端点设置基本身份验证参数?是否有某种配置文件或其他东西?我在互联网上找不到任何东西...

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-05
      • 2016-02-08
      • 2012-02-04
      • 2017-03-10
      • 1970-01-01
      相关资源
      最近更新 更多