6

指示に従って、glassfish 用のカスタム セキュリティ レルムを作成しました。すべて正常に機能し、ユーザーは正しく認証されます。ただし、問題は次のとおりです。

  • ユーザー資格情報は文字列で暗号化されます
  • レルムはこの文字列を復号化し、データベースに対して認証を実行します (機能します)。
  • 復号化された値を securityContext のプリンシパルとして使用する代わりに、暗号化された文字列が渡されます。

私はすでに commit() メソッドをオーバーライドして、 を_userPrincipal使用して独自の実装を置き換えるかアタッチしようとしましたgetSubject().getPrincipals().add(new PrincipalImpl("user"))。どちらも期待どおりに機能していませんでした。基本的に、質問は次のように単純です: 注入された securityContext と一緒に使用できるように、glassfish のカスタム セキュリティ レルムに独自のプリンシパルを設定するにはどうすればよいですか?

私の環境:

  • Glassfish 3.1.2.2 (ビルド 5) フル プロファイル
  • 認証の背後で実行されているアプリケーションは、JAX-RS 1.1 ベースのアプリケーションです。
  • SecurityContext はインジェクションを使用して取得されます
4

1 に答える 1

2

commit() メソッドをオーバーライドして _userPrincipal を置き換えるか、getSubject().getPrincipals().add(new PrincipalImpl("user")) を使用して独自の実装をアタッチしようとしました。どちらも期待どおりに機能していませんでした。

どのようなエラーが発生しますか?

とにかく、あなたの問題はこのプロセスの 3 番目のステップにあると思います。SecurityContext は BASIC_AUTH、FORM_AUTH、CLIENT_CERT_AUTH、DIGEST_AUTH のみを AuthenticationScheme として定義するため、おそらく SecurityContext はセキュリティ スキームまたはタイプの実装を認識できません。ただし、これらの手順を試すことができます。うまくいくことを願っています。

A- Java Authentication and Authorization Service (JAAS) LoginModule を実装するか、com.sun.appserv.security.AppservPasswordLoginModule を拡張する

public class MyLoginModule extends AppservPasswordLoginModule {

@Override
protected void authenticateUser() throws LoginException {
    if (!authenticate(_username, _password)) {
//Login fails
        throw new LoginException("LoginFailed");
    }
    String[] myGroups = getGroupNames(_username);
    commitUserAuthentication(myGroups);
}

private boolean authenticate(String username, String 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.
}

B- レルム クラスの実装。

public class MyRealm extends AppservRealm {

@Override
public void init(Properties props)
throws BadRealmException, NoSuchRealmException {
//here you initialize the realm
}
@Override
public String getAuthType() {
return "Custom Realm";
}
}

C- レルムと LoginModule をサーバーにインストールして構成する。

このためには、JSR 196 を見て、javax.security.auth.message.module.ServerAuthModule を実装して独自の SAM を作成する必要があります。以下のリンクを見てください。 https://blogs.oracle.com/enterprisetechtips/entry/adding_authentication_mechanisms_to_the

于 2014-02-12T19:01:25.270 に答える