2013-09-25 4 views
2

내 GWT의 첫 번째 페이지 애플리케이션 "/HumanResources.html"에 대한 액세스를 보호하기 위해 스프링 보안을 사용하고 있습니다. 사용자 자격 증명이 올바른지 (LDAP 콘텐츠와 비교하여) 사용자가 데이터베이스 (사용자 정의 인증 표)에 있는지 확인합니다.로그 아웃 후 GWT + 스프링 보안 로그인 문제

처음으로 사용자가 로그인해도 문제가없는 경우 사용자 로그 아웃과 ".jsp"페이지가 표시됩니다. 하지만 "HumanResources.html"페이지에 다시 액세스하려고하면 인증이 무시됩니다 (로그인 양식이 표시되지 않음). 페이지가 표시됩니다. 인터페이스 만 표시되며 보안 RPC 서비스에서 데이터를 검색합니다.

이 문제는 외부 Tomcat Server (Firefox 및 Chrome에서 테스트 됨)에는 표시되지만 GWT Dev 모드에는 표시되지 않습니다. CTRL + F5가 작동하는 것 같고 다른 캐시 문제를 찾았지만 도움이되지 않았습니다.

아무도 도와 줄 수 있습니까?

보안 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"); 
     } 
    } 
} 

답변

0

편집 : 당신을 missleading에 대한 죄송합니다. 나는 조금 파고 발견 사용자 브라우저가 캐싱 xxx.html 페이지, js, CSS 등 수 있습니다. 1) 강제로 새로 고침 페이지 : html 헤더를 설정하여 그게 가장 간단한 해결책, 그리고 이후로 당신은 안전한 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; 
      } 
     } 
    } 
} 

당신은 어딘가에 즉 호출해야합니다 당신에게 현재 기록 된 사용자를 표시하는 동안 : 보안 오류가 RPC에 ocured 경우

2) 우리의 응용 프로그램을 확인하고 있습니다

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

또는 당신이 잡을 수 있습니다 예외 중 하나에 대한 예외 방법

+0

답장을 보내 주셔서 감사합니다. HumanResources.html에 액세스 역할 (ROLE_HR)을 추가하여 해결책을 시도했지만 작동하지 않았습니다. :/다시 로그 할 때 인증 단계가 "건너 뛰었습니다"... – ersefuril

+0

다시 한번 감사드립니다! HTML 헤더가 최상의 솔루션 일 수 있습니다 (소수의 사용자가 응용 프로그램에 연결됨). 난 항상이 솔루션을 보았지만, 내가 시도한 지난 번에 작동하지 않았다 (어쩌면 내가 잘못하고있다). 어떻게 대처할 수 있는지 보여 주시겠습니까? – ersefuril

+0

우리는 그것을한다 2) 길 - 코드는 나의 지위에있다. onFailure의 RPC에서는 보안 예외를 처리합니다 –

관련 문제