1

我想为我的 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];
    }
}

更新

遗憾的是, ObjectDB还没有 JDBC 驱动程序。但是,请随时提出建议!

提前致谢!

4

3 回答 3

1

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

于 2011-10-04T23:34:27.160 回答
1

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

private boolean authenticate(String username, char[] password) 可以使用 EJB 客户端来执行凭据验证。这个例子对我来说很好。唯一要做的更改是将您的 ObjectDb 实体用于数据模型,作为改进,您可以将接口 IUserAuthenticationService 放在单独的 jar 中以避免分发实现。

希望有帮助。

Rn

于 2015-08-22T12:03:16.013 回答
0

原来ObjectDB还没有JDBCDriver。我发现自己的实现太多了,所以我会等待:)

于 2011-11-05T19:58:19.693 回答