ObjectDB 的自定义领域,使用 ObjectDB 和 HTTP 基本身份验证

发布于 2024-12-07 23:42:56 字数 2387 浏览 1 评论 0原文

我想为我的 Web 服务实现 HTTP 基本身份验证,但我也想使用 ObjectDB 来存储凭据。有什么办法可以做到这一点吗?我想我需要一个自定义领域,而且,之前已经有人这样做了,所以如果是,请举手。否则请帮助我实施。我已经检查了制作自定义领域的基础知识。是否可以以某种方式使其与 JDBCRealm 一起使用,或者更直接地说,是否可以在使用 ObjectDB 服务器的 GlassFish 中创建 JDBC 资源?

到目前为止我所做的是 Realm:

package objectdbrealm;

import com.sun.appserv.security.AppservRealm;
import com.sun.enterprise.security.auth.realm.BadRealmException;
import com.sun.enterprise.security.auth.realm.InvalidOperationException;
import com.sun.enterprise.security.auth.realm.NoSuchRealmException;
import com.sun.enterprise.security.auth.realm.NoSuchUserException;
import java.util.Enumeration;
import java.util.Properties;

public class ObjectDbRealm extends AppservRealm {

    @Override
    public void init(Properties properties) throws BadRealmException, NoSuchRealmException {
        //initialize the realm
    }

    @Override
    public String getAuthType() {
        return "ObjectDB Realm";
    }

    @Override
    public Enumeration getGroupNames(String string) throws InvalidOperationException, NoSuchUserException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

LoginModule:

package objectdbrealm;

import com.sun.appserv.security.AppservPasswordLoginModule;
import com.sun.enterprise.security.auth.login.common.LoginException;

public class ObjectDbLoginModule extends AppservPasswordLoginModule {

    @Override
    protected void authenticateUser() throws LoginException {
        if (!authenticate(_username, _passwd)) {
            //Login fails
            throw new LoginException((new StringBuilder()).append("Login Failed for:").append(_username).toString());
        }
        String[] groups = getGroupNames(_username);
        commitUserAuthentication(groups);
    }

    private boolean authenticate(String username, char[] password) {
        /*
        Check the credentials against the authentication source,
        return true if authenticated, return false otherwise
         */
        return true;
    }

    private String[] getGroupNames(String username) {
        // Return the list of groups this user belongs to.
        return new String[0];
    }
}

UPDATE

的基础objectdb.com/database/forum/271" rel="nofollow">事实证明还没有适用于 ObjectDB 的 JDBC 驱动程序。不过,请随意提出建议!

提前致谢!

I want to implement HTTP Basic Authentication for my web services, but I also want to use ObjectDB to store credentials. Is there any way to do this? I guess I'm in the need of a custom realm, and also, that somebody already did this before, so if yes please raise your hands. Otherwise please help me with the implementation. I already checked the basics of making custom realms. Is it possible somehow to make it work with JDBCRealm, or more directly, is it possible to create a JDBC resource in GlassFish that uses the ObjectDB server?

What I did so far is the base of the Realm:

package objectdbrealm;

import com.sun.appserv.security.AppservRealm;
import com.sun.enterprise.security.auth.realm.BadRealmException;
import com.sun.enterprise.security.auth.realm.InvalidOperationException;
import com.sun.enterprise.security.auth.realm.NoSuchRealmException;
import com.sun.enterprise.security.auth.realm.NoSuchUserException;
import java.util.Enumeration;
import java.util.Properties;

public class ObjectDbRealm extends AppservRealm {

    @Override
    public void init(Properties properties) throws BadRealmException, NoSuchRealmException {
        //initialize the realm
    }

    @Override
    public String getAuthType() {
        return "ObjectDB Realm";
    }

    @Override
    public Enumeration getGroupNames(String string) throws InvalidOperationException, NoSuchUserException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

, and LoginModule:

package objectdbrealm;

import com.sun.appserv.security.AppservPasswordLoginModule;
import com.sun.enterprise.security.auth.login.common.LoginException;

public class ObjectDbLoginModule extends AppservPasswordLoginModule {

    @Override
    protected void authenticateUser() throws LoginException {
        if (!authenticate(_username, _passwd)) {
            //Login fails
            throw new LoginException((new StringBuilder()).append("Login Failed for:").append(_username).toString());
        }
        String[] groups = getGroupNames(_username);
        commitUserAuthentication(groups);
    }

    private boolean authenticate(String username, char[] password) {
        /*
        Check the credentials against the authentication source,
        return true if authenticated, return false otherwise
         */
        return true;
    }

    private String[] getGroupNames(String username) {
        // Return the list of groups this user belongs to.
        return new String[0];
    }
}

UPDATE

Sadly it turned out that there is no JDBC driver for ObjectDB yet. Feel free to make suggestions however!

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

这不是一个直接的答案,但是有一个出色的FlexibleJDBCRealm,它提供了一种替代相当严格的 JDBCRealm 的方法鱼。它是开源的,使该代码适应 ObjectDB 应该比从头开始实现一个领域容易得多。

Not a direct answer, but there's the excellent FlexibleJDBCRealm that offers an alternative to the rather rigid JDBCRealm that comes with the Fish. It's open source, adapting that code to ObjectDB should be a lot easier than starting to implement a realm from scratch.

少女的英雄梦 2024-12-14 23:42:56

如果您使用的是 Objectdb,则 JDBC 不是必需的。您可以在项目中创建一个无状态 EJB,该 EJB 访问您的 ObjectDb 实体以执行登录验证。您的方法

私有布尔验证(字符串用户名,char[]密码)
可以使用 EJB 客户端来执行凭据验证。
这个示例 对我来说效果很好。唯一要做的更改是使用 ObjectDb 实体作为数据模型,作为改进,您可以将接口 IUserAuthenticationService 放在单独的 jar 中以避免分发实现。


希望有帮助。

JDBC is not mandatory is you are using Objectdb. You can create a Stateless EJB in your project that access your ObjectDb entities to perform the login validation.The your method

private boolean authenticate(String username, char[] password)
can use an EJB client to perform the credentials validations.
This example worked fine for me. The only change to make is using your ObjectDb entities for the datamodel and as an improvement you can put the interface IUserAuthenticationService in a separate jar to avoid distributing the implementation.

Hope that helps.

Rn

橘味果▽酱 2024-12-14 23:42:56

事实证明目前还没有适用于ObjectDB的JDBCDriver。我发现它太多了,无法实现我自己的,所以我只会等待:)

It turned out that there is no JDBCDriver for ObjectDB yet. I've found it too much to implement my own, so I will just wait :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文