2011-10-04 16 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