2011-10-04 9 views
1

WebサービスのHTTP基本認証を実装したいのですが、ObjectDBを使用して資格情報を格納することもできます。これを行う方法はありますか?私はカスタム領域を必要としていると思うし、誰かが既にこれをしていたと思うので、もしそうなら、手を挙げてください。それ以外の場合は、実装を手伝ってください。カスタムレルムの作成の基本を確認しました。何らかの形でJDBCRealmで動作させることは可能ですか、より直接的には、ObjectDBサーバーを使用するGlassFishでJDBCリソースを作成することは可能ですか?ObjectDBのカスタムレルム(HTTPの基本認証でObjectDBを使用)

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::悲しいことit turned outにはJDBCドライバが存在しないこと

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

私がこれまでRealmの拠点となってやった

まだObjectDBです。しかし、お気軽に提案してください!

ありがとうございます!

答えて

0

It turned out ObjectDBにはまだJDBCDriverが存在しません。私は自分自身を実装するにはあまりにも多くを見つけたので、私はただ待つだけです:)

1

直接的な回答ではありませんが、魚に付属するかなり剛性のあるJDBCRealmに代わるものとして、FlexibleJDBCRealmがあります。オープンソースで、ObjectDBにコードを適用することは、領域を最初から実装するよりもはるかに簡単です。

1

JDBCはObjectdbを使用している必要はありません。あなたは を実行するためにEJBクライアントを使用することができ、あなたの方法

プライベートブール認証(文字列のユーザー名は、[]パスワードをchar型)validation.Theログインを実行するために、あなたのObjectDbエンティティにアクセスするプロジェクト内のステートレスEJBを作成することができます資格情報の検証。 このexampleは私にとってうまく機能しました。作成する唯一の変更は、DatamodelにObjectDbエンティティを使用することです。また、実装の分散を避けるため、インターフェイスIUserAuthenticationServiceを別のjarに配置することができます。

希望するものがあります。

nn