2

Spring Security を使用して、GWT の最初のページ アプリケーション"/HumanResources.html"へのアクセスを保護しています。ユーザーの資格情報が正しいかどうかを確認し (ldap コンテンツと比較して)、ユーザーがデータベース (カスタム承認テーブル) に存在するかどうかを確認します。

初回のユーザーログインは問題なく、ユーザーログアウトすると「.jsp」ページが表示されます。しかし、再度「HumanResources.html」ページにアクセスしようとすると、どうやら認証が無視されて (ログインフォームが表示されず)、ページが表示されてしまいます。インターフェイスのみが表示され、データはセキュリティで保護された RPC サービスによって取得されます。

この問題は、外部 Tomcat サーバー (Firefox および Chrome でテスト済み) で発生しますが、GWT Dev モードでは発生しません。CTRL + F5 は機能しているようで、他のキャッシュの問題を探しましたが、役に立ちませんでした。

誰でも私を助けることができますか?

私のsecurity-applicationContext.xmlの一部:

<http use-expressions="true" auto-config="false">
    <intercept-url pattern="/HumanResources.html" access="isAuthenticated()" />
    <form-login 
        login-page='/login.jsp'
        authentication-failure-url = "/login.jsp?login_error=1"
        authentication-success-handler-ref="HRAuthenticationHandler" />
    <logout 
        logout-url="/logout" 
        logout-success-url="/logout.jsp" 
        delete-cookies="JSESSIONID"/>
</http>

<beans:bean id="HRAuthenticationHandler" class="lu.sfeir.candidate.server.auth.HRAuthenticationHandler">
    <beans:property name="useReferer" value="true" />
</beans:bean>

<ldap-server url="${ldap.serverUrl}" manager-dn="${ldap.adminLogin}" manager-password="${ldap.adminPassword}" />

<authentication-manager>
    <ldap-authentication-provider 
        group-search-base="${ldap.groups}"
        user-search-base="${ldap.users}"
        user-search-filter="${ldap.userId}">
    </ldap-authentication-provider>
</authentication-manager>

および私のカスタムAuthenticationHandler 実装:

public class HRAuthenticationHandler extends SavedRequestAwareAuthenticationSuccessHandler {

    @Autowired
    private AuthorizedUsersDao usersDao;

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException,
            ServletException {

        // Check if the user exist in the DB
        if(usersDao.findUser(((UserDetails)authentication.getPrincipal()).getUsername())) {
            // Redirect to home page
            super.onAuthenticationSuccess(request, response, authentication);
        } else {
            // Redirect to error page
            response.sendRedirect("/spring_security_login?login_error");
        }
    }
}
4

1 に答える 1

0

編集:誤解を招いて申し訳ありません。少し掘り下げたところ、ユーザーのブラウザが xxx.html ページ、js、css などをキャッシュしているため、セキュリティが機能しないことがわかりました。次のことができます。1) html ヘッダーを設定して、ページを強制的に更新します。それはあなたにとって十分なはずです。または、キャッシュをまったく無効にします。

ネットワークトラフィックが増加することに注意してください。

2) アプリケーションは、RPC でセキュリティ エラーが発生したかどうかを確認しています。

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.InvocationException;

public abstract class CustomAsyncCallback<T> implements AsyncCallback<T> {
    @Override
    public void onFailure(Throwable caught) {
        if (caught instanceof InvocationException) {
            InvocationException ie = (InvocationException) caught;
            if(ie.getMessage().contains("j_spring_security_check")) {
                Window.alert("User session expired, please login again");
                Window.open(GWT.getHostPageBaseURL() + "login.jsp", "_self", null);
                return;
            }
        }
    }
}

現在ログインしているユーザーを表示しているときに、どこかで呼び出す必要があります。

    userSecurityService.getUser(new CustomAsyncCallback<String>() {
        @Override
        public void onSuccess(String result) {
            usrLoginLbl.setText(result);
        }
    });

または、この例外を onFailure メソッドのいずれかにキャッチすることができます

于 2013-09-25T15:21:04.107 に答える