2017-05-31 17 views
0

私はこのようなログインフォームを持つサイトを持っています。Safariのオートパニューが空白文字列

<h:panelGrid columns="3"> 
    <p:outputLabel value="Username:" for="username"/> 
    <p:inputText id="username" autocomplete="off" /> 
    <p:message for="username"/> 

    <p:outputLabel value="Password:" for="password"/> 
    <p:password id="password" /> 
    <p:message for="password"/> 
</h:panelGrid> 

我々はパスワードを検証するために春のセキュリティを使用している、と私は春のUsernamePasswordAuthenticationFilterにブレークポイントを投げるときSafariの自動入力パスワード機能を使用する場合、パスワードは常に空白です。これにより、ログインが失敗します。参考のため

は、ここに私のブレークポイントは、私はこれを解決するためにチェックすることができるものに総損失によ

public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { 
    if (postOnly && !request.getMethod().equals("POST")) { 
     throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); 
    } 

    String username = obtainUsername(request); 
    String password = obtainPassword(request); 

    if (username == null) { 
     username = ""; 
    } 

    //My breakpoint is here, but password = "" even though we have a user name 
    if (password == null) { 
     password = ""; 
    } 

    username = username.trim(); 

    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password); 

    // Allow subclasses to set the "details" property 
    setDetails(request, authRequest); 

    return this.getAuthenticationManager().authenticate(authRequest); 
} 

に位置しているSpringのコードの一部です。このパスワードの問題はSafariにのみ影響します。 IE、Chrome、FFなどの他のブラウザはうまく動作します。

+1

フォームをどのように提出していますか?あなたの 'p:password'を処理していますか? –

答えて

0

私は問題を見つけた!

<p:defaultCommand target="ndaLoginButton" /> 
    <h:panelGroup styleClass="errorText centered" rendered="#{authenticationBean.failedLogin}"> 
     <h:outputText rendered="#{authenticationBean.isFailedLogin() and not authenticationBean.lockedAccount}" 
        value="Invalid username or password. Please try again." /> 
     <h:outputText rendered="#{authenticationBean.lockedAccount}" 
        value="Account locked. You can reset account password below." /> 
    </h:panelGroup> 
    #{authenticationBean.setFailedLogin(false)} 


    <h:form id="loginDialogForm" prependId="false"> 
     <h:panelGrid columns="2" styleClass="ndaLoginDialogTable" columnClasses="ndaLoginDialogTop, ndaLoginDialogTop"> 
      <h:panelGroup> 
       <h:panelGrid columns="3"> 
        <p:outputLabel value="Username:" for="username"/> 
        <p:inputText id="username" autocomplete="off" /> 
        <p:message for="username"/> 

        <p:outputLabel value="Password:" for="password"/> 
        <p:password id="password" autocomplete="off" /> 
        <p:message for="password"/> 
       </h:panelGrid> 
       <input type="submit" style="visibility: hidden;" onclick="$j('#ndaLoginButton').click();"/> 
       <input type="hidden" id="loginDialogSubmit" name="loginDialogSubmit" value="loginDialogSubmit" /> 
       <input type="hidden" id="loginDialogRedirect" name="loginDialogRedirect" /> 
      </h:panelGroup> 

      <h:panelGroup> 
       <p:commandButton id="ndaLoginButton" value="NDA Login" type="submit" action="#{loginDialogPageBean.login}" 
           ajax="false" onclick="ndar.showPreloader()"/> 
      </h:panelGroup> 
     </h:panelGrid> 
    </h:form> 

問題は<p:defaultCommand>タグです。このタグは、ユーザーがキーボードのEnterキーを押したときに押されるコントロールを指定するために使用されます。ハッピングとは、フォーム上にパスワードフィールドを入力する前に、Safariが仮想のEnterキーを送信していたことです。とにかくこの<p:defaultCommand>タグを削除するだけで問題は解決しました。

関連する問題