5

私は、EJB セキュリティと GlassFish の認証、承認メカニズムに非常に慣れていません。jdbcレルムがありsun-web.xmlweb.xmlロールをマップしてページへのアクセスを制限するように構成されています。

ただし、私の問題は、すべてのページへのアクセスを制限すると、ウェルカムページをロードする前に (BASIC 認証を使用して) 機能し、ログインポップアップがトリガーされることです。

<web-resource-collection>
  <web-resource-name>All Pages</web-resource-name>
  <description/>
  <url-pattern>/*</url-pattern>
  <http-method>GET</http-method>
  <http-method>POST</http-method>
  <http-method>HEAD</http-method>
  <http-method>PUT</http-method>
  <http-method>OPTIONS</http-method>
  <http-method>TRACE</http-method>
  <http-method>DELETE</http-method>
</web-resource-collection>

しかし、フォルダー内のページへのアクセスを制限するとsecurity、GlassFish はログインを要求せず、ユーザーを制限されたページにリダイレクトします。

<web-resource-collection>
  <web-resource-name>All Pages</web-resource-name>
  <description/>
  <url-pattern>/security/*</url-pattern>
  <http-method>GET</http-method>
  <http-method>POST</http-method>
  <http-method>HEAD</http-method>
  <http-method>PUT</http-method>
  <http-method>OPTIONS</http-method>
  <http-method>TRACE</http-method>
  <http-method>DELETE</http-method>
</web-resource-collection>`

この問題の解決を手伝ってください。よろしくお願いします。

セキュリティマネージャーをオンにした後、これらのエントリも見つかりました

Processing login with credentials of type: class com.sun.enterprise.security.auth.login.PasswordCredential Logging in user [admin] into realm: admin-realm using JAAS module: fileRealm Login module initialized: class com.sun.enterprise.security.auth.login.FileLoginModule File login succeeded for: admin JAAS login complete. JAAS authentication committed. Password login succeeded for : admin permission check done to set SecurityContext Set security context as user: admin

[Web-Security] hasResource perm: (javax.security.jacc.WebResourcePermission /faces/security/UserRedirect.jsp GET)

jdbcrealm を使用するのではなく、admin-realm の admin プリンシパルが自動的に認証され、アプリケーションに使用されるようです。これを修正する方法について何か考えはありますか?

アップデート

申し訳ありませんが、認証を確認するフォームに変更しました。再度BASICに戻しました。はい、jdbcrealm という名前をデフォルトのレルムとして使用しています。

そうですよね…まさにその通りです

GlassFish はログイン フォーム ページにリダイレクトせず、制限されたリソースへのアクセスは制限されません

admin-realm admin が自動的に認証され、制限されたページにアクセスしようとすると、認証されたユーザーがチェックされ、管理者であり、ページへの権限があるため、ページにアクセスでき、ログインを求められないためだと思います。

これらは、アプリケーションを実行し、glass fish の管理コンソールにログインしようとしていないときにも表示されます

Processing login with credentials of type: class com.sun.enterprise.security.auth.login.PasswordCredential
Logging in user [admin] into realm: admin-realm using JAAS module: fileRealm
Login module initialized: class com.sun.enterprise.security.auth.login.FileLoginModule
File login succeeded for: admin
JAAS login complete.
JAAS authentication committed.
Password login succeeded for : admin
permission check done to set SecurityContext
Set security context as user: admin

これらも

(unresolved javax.security.jacc.WebUserDataPermission /security/* null)
 (unresolved javax.security.jacc.WebUserDataPermission /:/security/* null)
 (unresolved com.sun.corba.ee.impl.presentation.rmi.DynamicAccessPermission access null)
 (unresolved javax.security.jacc.WebResourcePermission /:/security/* null)
 (unresolved javax.security.jacc.WebResourcePermission /security/* !DELETE,GET,HEAD,OPTIONS,POST,PUT,TRACE)
 (unresolved com.sun.enterprise.security.CORBAObjectPermission * *)

更新 2

<url-pattern>/*</url-pattern> 代わりに使ってみた<url-pattern>/security/*</url-pattern>

興味深いことに、これは私がトレースで得たものです。

Processing login with credentials of type: class com.sun.enterprise.security.auth.login.PasswordCredential
Logging in user [employee] into realm: emsSecurity using JAAS module: jdbcRealm
Login module initialized: class com.sun.enterprise.security.auth.login.JDBCLoginModule
JDBC login succeeded for: employee groups:[Ljava.lang.String;@16bfca4
JAAS login complete.
JAAS authentication committed.
Password login succeeded for : employee
permission check done to set SecurityContext
Set security context as user: employee

アクセス拒否ページに移動します。

「HTTP ステータス 403 - 要求されたリソースへのアクセスが拒否されました」

ユーザーがログイン資格情報を送信せずに、glassfish がユーザーの従業員を認証する方法がわかりません。「従業員のパスワード ログインに成功しました」とさえ表示されます。この問題を解決するのを手伝ってください。


何よりも、ご尽力いただき、誠にありがとうございました。私はまだ問題に悩まされています。ここにxmlファイルを投稿しています。

sun-web.xml

<security-role-mapping>
<role-name>Employee</role-name>
<group-name>Employee</group-name>

web.xml

    <security-constraint>
    <display-name>Login Constraint</display-name>
    <web-resource-collection>
        <web-resource-name>User Redirect page</web-resource-name>
        <description/>
        <url-pattern>/security/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
        <http-method>HEAD</http-method>
        <http-method>PUT</http-method>
        <http-method>OPTIONS</http-method>
        <http-method>TRACE</http-method>
        <http-method>DELETE</http-method>
    </web-resource-collection>
    <auth-constraint>
        <description/>
        <role-name>Employee</role-name>
        </auth-constraint>
    </security-constraint>
<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>deliverySecurity</realm-name>
    <form-login-config>
        <form-login-page>/Login.jsp</form-login-page>
        <form-error-page>/index.jsp</form-error-page>
        </form-login-config>
    </login-config>
<security-role>
    <description/>
    <role-name>Employee</role-name>
</security-role>

また、スタック トレースもありません。例外はありません。認証要件がないかのように、ユーザーは保護されたページにリダイレクトされます。これは、Netbeans 6.5.1 と Glassfish v2 を使用した jsf ビジュアル Web 開発プロジェクトです。どうもありがとう。

4

4 に答える 4

3

URL パターンに「/faces」を追加してみてください。例: /faces/security/*

于 2011-06-16T16:55:06.093 に答える
2

web.xml私はこれでテストを行ったので、関連するすべての部分を投稿してくださいweb.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

  <display-name>Archetype Created Web Application</display-name>

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Protected Area</web-resource-name>
      <url-pattern>/jsp/security/protected/*</url-pattern>
      <http-method>PUT</http-method>
      <http-method>DELETE</http-method>
      <http-method>GET</http-method>
      <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>role1</role-name>
    </auth-constraint>
  </security-constraint>

  <!-- Security roles referenced by this web application -->
  <security-role>
    <role-name>role1</role-name>
  </security-role>
  <login-config>
    <auth-method>BASIC</auth-method>
  </login-config>
</web-app>

また、保護されたリソース (ここではhttp://localhost:8080/mywebapp/jsp/security/protected/ ) を要求すると、ユーザー名とパスワードの入力が求められます。つまり、問題を再現できません (GlassFish v3 を使用していました)。

更新:サンプル Web アプリケーションをjdbcレルムで保護し、正常に動作していることを確認しました。ですから、私が言ったように、あなたweb.xmlとあなたのを提供してくださいsun-web.xml。また、セキュリティのためにログ レベルを FINEST に設定してください。

代替テキスト

そして、関連するトレースを結合します。

更新:表示されているトレースは、管理コンソールでの管理者ユーザーのログインに関するものだと思います。そうでない場合は、jdbc レルムをデフォルト レルムとして設定しましたか (データベースは、次のキャプチャの jdbc レルムです)。

代替テキスト

ところで、BASIC 認証を使用していると思いました。しかし、提供した記述子によると、FORM を使用しています。では、実際に何を使用していて、何が問題なのかを明確にしていただけますか (「GlassFish がログイン フォーム ページにリダイレクトされず、制限されたリソースへのアクセスが制限されていない」など)。

于 2010-03-06T18:59:17.780 に答える
1

考えられる解決策は次の 2 つです。

1 - 別のブラウザから試しましたか? ログイン情報はキャッシュできるため、一度入力すると、ログアウト アクションを実行するまで再確認されません。

2 -ログアウト メソッドを実装します。私は JSF 2.0 を使用しており、ログアウト方法は次のようなものです。

public String logout() {
        FacesContext context = FacesContext.getCurrentInstance();

        // remove data from beans:
        for (String bean : context.getExternalContext().getSessionMap().keySet()) {
            context.getExternalContext().getSessionMap().remove(bean);
        }

        // destroy session:
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        session.invalidate();

        // using faces-redirect to initiate a new request:
        return "/security/index.xhtml?faces-redirect=true";

    }

このメソッドを Bean に追加してから、' action="#{yourBean.logout}" ' を使用してボタンから呼び出すことができます。

次に、ブラウザーを更新すると、ログイン資格情報の入力を求められます。

于 2011-10-13T17:20:23.997 に答える
0

NetBeans 6.8 を使用している場合は、「再デプロイメント間でセッションを保持する」プロパティがオフになっていることを確認してください。

GlassFish v3 の NetBeans 6.8 のサーバー プロパティ ダイアログ http://blogs.sun.com/vkraemer/resource/preserve-session.png

なんで?最初に「すべてロック」のケースをテストしたようです (そして、正常にログインできました)。/security/* を使用するように web.xml を変更した場合、古いセッションはまだ有効であり、ログインしていたので、認証を要求される代わりに、ページに直接移動します。

Eclipse 用のサーバー アダプターにもこの機能があります。

于 2010-03-06T22:59:39.207 に答える