1

設定:

  • Glassfish 3.1.1
  • JSF 2.1
  • postgreSQLを使用したjdbcRealm

ログインフォームに有効なユーザー資格情報を入力した後、ログインして次のページにリダイレクトされます。しかし、そのページを離れて、もちろん許可されたurlパターンにある別のページに移動すると、「HTTPステータス403-要求されたリソースへのアクセスが拒否されました」というメッセージが表示されます。その後、Webアプリのどのサイトにもアクセスできなくなります。

ログインは、glassfishのserver-config/securityのStandard-Realmを自分のレルムに設定した場合にのみ機能します。

デプロイ時にサーバーログに次の警告が表示されます。

Warnung: Keine Principals zugeordnet zu Rolle [USER].
(Warning: No principals mapped to role [USER])

Chrome DebuggerでJSESSIONIDを削除すると、再度ログインできます。許可された1つのWebサイトなどにアクセスした後、サーバー側でセッションが破棄されたようです。

関連する情報源をいくつか添付しました。ログインメカニズムが機能し、例外がないので、レルムなどとは何の関係もないと思います...

web.xml

<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>jdbcRealm</realm-name>
    <form-login-config>
        <form-login-page>/faces/login.xhtml</form-login-page>
        <form-error-page>/faces/loginError.xhtml</form-error-page>
    </form-login-config>
</login-config>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>User</web-resource-name>
        <url-pattern>/faces/user/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>ADMIN</role-name>
    </auth-constraint>
</security-constraint>

glassfish-web-app.xml(手動で追加)

<glassfish-web-app>
<security-role-mapping>
    <role-name>USER</role-name>
    <group-name>USER</group-name>
</security-role-mapping>
</glassfish-web-app>

login.xhtml

<h:form>
<h:outputLabel for="usernameInput">
    Username:
</h:outputLabel>
<h:inputText id="usernameInput" value="#{authBackingBean.username}" 
             required="true" />
<br />
<h:outputLabel for="passwordInput">
    Password:
</h:outputLabel>
<h:inputSecret id="passwordInput" value="#{authBackingBean.password}" 
               required="true" />
<br />
<h:commandButton value="Login" 
                 action="#{authBackingBean.login}" />

AuthBackingBean

@Stateless
@Named
public class AuthBackingBean {

    private String username;
    private String password;

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String login() {
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
        try {
            request.login(this.username, this.password);
        } catch (ServletException e) {
            context.addMessage(null, new FacesMessage("Login failed."));
            return "loginError";
        }
        return "user/index";
    }

    public void logout() {
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
        try {
            request.logout();
        } catch (ServletException e) {
            context.addMessage(null, new FacesMessage("Logout failed."));
        }
    }
}

PS:多くの論理エラー、タイプミス、コピー/貼り付けエラーが含まれているため、オラクルのめちゃくちゃなドキュメントには本当に失望しています。構造化されておらず、読みにくく、過負荷になっています。(申し訳ありませんが、それは言わなければなりませんでした)

4

2 に答える 2

6

これは陽気です。何時間もテストしてこの質問を書いた後、投稿してから1分後に答えが見つかりました。

server-config/securityで"Standard-Principalauf Rollenzuordnung"(Standard-Principal to Rolemapping)をアクティブにしたところ、機能するようになりました。

于 2013-03-22T00:51:04.260 に答える
1

ロール、プリンシパル、およびロールマッピングに関するこのドキュメントに従った後、「標準プリンシパルからロールへのマッピング」を有効にする代わりに、ロールのマッピングを使用してglassfish-web.xml(WEB-INFの下)記述子を定義できることがわかりました。 。

例:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD
GlassFish Application Server 3.1 Servlet 3.0//EN"
        "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd"
        >

<glassfish-web-app>
    <context-root>/istop</context-root>
    <security-role-mapping>
        <role-name>described-role</role-name>
        <principal-name>user-that-should-have-this-role</principal-name>
        <group-name>equivalent-role-in-db</group-name>
    </security-role-mapping>
</glassfish-web-app>

described-roleで使用されているものが、または<role-name />を使用しているweb.xmlの定義と一致していることを確認してください。<role-name />@DeclaredRoles

最後に、「Standar-プリンシパルからロールへのマッピング」オプションが何をするかを正しく理解している場合、アプリケーションで定義されたものと一致するRoleレルムマッピングからを期待しているため、データベース内のすべてのユーザーが一致するロールを持っている必要がありますGoup Name Column定義された役割の1つ。

于 2015-06-19T15:43:15.987 に答える