1

現在、JSF Web サイトを拡張しています。私は Tomcat コンテナー管理の認証メカニズムを使用しています (うまく機能し、ユーザーは保護領域にアクセスする前にログインを強制されます)、追加のログイン ボタンを提供したいと考えています。

ログインボタンを使用して、orderProducts.xhtmlなどの保護されたページに到達する前に、Webサイトが追加機能(アドレスの変更/追加/削除など)を提供するために、ユーザーに「LOGGED_IN_CUST」資格情報を取得してもらいたい

例:

現在のサイト: index.xhtml 右上
のログイン リンクをクリックすると、login.xhtml ページが表示されます。

    <form action="j_security_check">
        <h:panelGrid columns="2" bgcolor="#eff5fa" cellspacing="5"
            frame="box" styleClass="center">
            <h:outputLabel value="User name:" />
            <h:inputText id="j_username" tabindex="1" />
            <h:outputLabel value="Password:" />
            <h:inputSecret id="j_password" />
            <h:outputLabel value="" />
            <h:commandButton id="login" value="Login" />
        </h:panelGrid>
    </form>

正しいユーザー認証情報を使用してログイン ボタンを押すと、次のエラーが表示されます。

HTTP Status 400 - Invalid direct reference to form login page
message: Invalid direct reference to form login page
description: The request sent by the client was syntactically incorrect.

追加のログイン リンクを使用してログインするソリューションはありますか。また、お客様がログインに成功した後、以前に表示されていたサイトが再びアクティブになりますか? (この例では index.xhtml)

4

1 に答える 1

0

アプリケーションを再構築しました。action 属性を持つログイン フォームの代わりに、次の doLogin メソッドを呼び出す"j_security_check"従来のフォームを作成しました。commandButton

public void doLogin(ActionEvent e) throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest) context
            .getExternalContext().getRequest();

    try {
        // Try to login customer via container management
        request.login(eMail, password);

        /*
         * In case that the Login link was clicked, then the variable
         * "requestedURI" is null ! In that case we can redirect the
         * customer directly to his customerOverview site. A user with role
         * ADMIN will be redirected to systemInfo.xhtml and a user with role
         * CUST is redirected to customerOverview.xhtml.
         */
        if(requestedURI == null){
            if(request.isUserInRole(ROLE_ADMIN)){
                requestedURI = BASE_NAME+"/faces/sections/admin/systemInfo.xhtml";
            }
            else if(request.isUserInRole(ROLE_CUST)){
                requestedURI = BASE_NAME+"/faces/sections/customer/customerOverview.xhtml";
            }
            else{
                requestedURI = BASE_URL;
            }
        }

        /*
         * If everything worked well, redirect the customer to the desired
         * page
         */
        context.getExternalContext().redirect(requestedURI);
    } catch (ServletException se) {
        context.addMessage(null, new FacesMessage(Internationalization.getLoginFailed()));
    }
}

このソリューションは私にとってはうまくいきます:)

于 2013-06-17T09:18:10.063 に答える