2011-10-04 44 views
1

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

我做什么迄今已是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

可悲it turned out即不存在用于JDBC驱动程序ObjectDB呢。不过随意提出建议!

在此先感谢!

回答

0

It turned out ObjectDB还没有JDBCDriver。我发现它实现我自己太多,所以我会等待:)

1

不是一个直接的答案,但有优秀的FlexibleJDBCRealm,提供了一个替代鱼相伴而生的JDBCRealm。它是开源的,将代码调整到ObjectDB应该比从零开始实现领域容易得多。

1

JDBC是不是强制性的,你是使用Objectdb。你可以在你的项目,访问ObjectDb实体执行登录validation.The你的方法

私人布尔身份验证创建一个无状态EJB(字符串的用户名,CHAR []密码) 可以使用EJB客户端执行凭据验证。 这example为我工作得很好。唯一要做的修改是将ObjectDb实体用于数据模型,作为一项改进,您可以将IUserAuthenticationService接口放在单独的jar中以避免分发实现。

希望有所帮助。

Rn