2011-12-26 3 views
1

내 curl GWT 응용 프로그램 로그인에서 백 엔드 XMPP 서버를 사용하여 서버에서 Username-Password 조합을 인증하고 응답은 RPC 로그인 메커니즘을 통해 다시 전송 된 연결 ID입니다.GWT와 스프링 보안 통합

그러나 XMPP 서버와 공유되는 새로운 "사용자"데이터베이스를 생성하여 사용자 정보가 저장되며 Spring Security로 사용자 이름과 암호를 인증하는 데 사용됩니다.

누구나 GWT + Spring Security, 로그인/로그 아웃 코드에 대한 코드 스 니펫을 공유 할 수 있습니까?

답변

2

이 기사에서 코드를 사용하고 있습니다 : http://www.javacodegeeks.com/2010/12/securing-gwt-apps-with-spring-security.html

는 기본적으로, 당신은 인증합니다 (인증) 방법이있는 봄 인터페이스

org.springframework.security.authentication.AuthenticationProvider 

를 구현합니다. 당신은 봄 보안의 필터 (링크 참조)를 구성

String username = (String) authentication.getPrincipal(); 
String password = (String) authentication.getCredentials(); 
// now try to get the user from your DB 
User user = db.getUser(username, password); 

하고 Spring 컨텍스트에서 당신의 AuthenticationProvider에 선언한다 : 당신은이 메소드 내에서 사용자가 입력 한 사용자 이름과 암호를 얻을

<bean id="authProvider" class="com.example.security.MyAuthenticationProvider" /> 

<security:authentication-manager alias="authenticationManager"> 
    <security:authentication-provider ref="authProvider" /> 
</security:authentication-manager> 

을 나는 GWT를 전혀 사용하지 않는다. 단지 일반 JSP 페이지이다. JSP 로긴 페이지 (그리고 로그 아웃 링크)의 예를 볼 수있다. here 사용자가 로그온하면, GWT app 로드되었습니다. 다음과 같이

RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "/j_spring_security_logout"); 
try { 
    rb.sendRequest(null, new RequestCallback() { 
     public void onResponseReceived(Request request, Response response) { 
      GWT.log("Logged user out: " + response.getStatusText()); 
     } 
     public void onError(Request request, Throwable caught) { 
      // try to recover somehow 
     } 
    }); 
} catch (RequestException re) { 
    someOtherLogoutMechanism(); 
} 
0

내 구성은 다음과 같습니다 는 그런 짓을, 로그 아웃합니다. 나는 나의 위해 welcome.jsp 내 web.xml에

<filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

내 JSP

<form name="login" action="<c:url value="j_spring_security_check"/>" method="POST"> 

에 GWT 응용 프로그램

를 사용

<sec:authorize ifAnyGranted="<%=gRoles%>">  
    <meta http-equiv="REFRESH" content="0; url=demoApp/demoApp.jsp"> 
</sec:authorize> 

스프링 security.xml

<http auto-config="false" access-denied-page="/login.jsp?error=Access%20Denied"> 
    <intercept-url pattern="/login.jsp*" filters="none" /> 
    <intercept-url pattern="/demoApp/**" access="${app.roles}" /> 

    <form-login login-page="/login.jsp" 
       default-target-url="/welcome.jsp" 
       always-use-default-target="true" 
       authentication-failure-url="/login.jsp?error=true" /> 
    <logout logout-success-url="/login.jsp"/> 
    <anonymous/> 

여기 양식 기반 보안 샘플을 사용합니다. 보안을 위해 jdbc-user-service를 사용하여 인증을 위해 DB에 연결할 수 있습니다.

샘플보기 here