2013-04-17 3 views
1

저는 Spring 보안으로 보안 된 GWT 애플리케이션을 작성하고 있습니다. 로그인은 정상적으로 작동하지만 인증은하지 않습니다.Spring 보안을 사용하여 GWT 서블릿 보안하기

내 방법에서 @Secured 및 @PreAuthorize 주석을 사용해 보았지만 그 중 하나가 작동하지 않았습니다.

는 예를 들어,이 AppUserServiceImpl

에서 코드
@Secured("ROLE_ADMINISTRATOR") 
    @Override 
    public List<AppUser> fetch(Integer startRow, Integer endRow, Map criteria) { 
     return appUserManagerBean.getUsers(criteria); 
    } 

ApplicationContext.xml

<?xml version="1.0" encoding="UTF-8"?> 

<beans:beans xmlns="http://www.springframework.org/schema/security" 
      xmlns:beans="http://www.springframework.org/schema/beans" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
         http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"> 


<http auto-config="true"> 
    <intercept-url pattern="/testapplication/**" access="ROLE_USER"/> 
    <intercept-url pattern="/gwt/**" access="ROLE_USER"/> 
    <intercept-url pattern="/**/*.html" access="ROLE_USER"/> 
    <intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
    <intercept-url pattern="/security/*" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
    <intercept-url pattern="/testapplication/appUserService*" access="ROLE_ADMIN"/> 

    <form-login 
      login-page="/login.jsp" 
      authentication-failure-url="/security/error.html" 
      login-processing-url="/j_spring_security_check" 
      /> 
</http> 
<beans:bean id="appUserService" class="com.test.testapplication.server.admin.appuser.AppUserServiceImpl"/> 


<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
[DATASOURCE CONFIGURATION] 
</beans:bean> 
<global-method-security pre-post-annotations="enabled" secured-annotations="enabled" /> 
<authentication-manager> 
    <authentication-provider> 
     <password-encoder hash="sha" /> 
     <jdbc-user-service data-source-ref="dataSource" 
          users-by-username-query="select username,password,DECODE(enabled,'Y',1,'N',0) as enabled from APP_USER where username=?" 

          authorities-by-username-query="select u.username, ur.role from APP_USER u, APP_USER_ROLE ur 
                  where u.id = ur.APP_USER_ID and u.username =? " 

       /> 
    </authentication-provider> 
</authentication-manager> 

테스트하는 것입니다, 나는 'appUserService'을 확보하기 위해 노력하고있어.

web.xml을

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
      version="2.5"> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      /WEB-INF/applicationContext.xml 
     </param-value> 
    </context-param> 
    <servlet> 
     <servlet-name>appUserService</servlet-name> 
    <servlet-class>com.test.testapplication.server.admin.appuser.AppUserServiceImpl</servlet-class> 
</servlet> 

<!-- Spring security filter --> 
<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> 
<!-- Spring listener --> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
<!-- Default page to serve --> 
<welcome-file-list> 
    <welcome-file>testapplication.html</welcome-file> 
</welcome-file-list> 

내가 가장 간단한 해결책을 찾고 있어요 내가 AspectJ를 사용하지 않는 선호 당신이 당신의 서블릿 매핑되는 경우, 도움이 크게

+0

@Secured 및 @PreAuthorize 사용에 대해 자세히 설명해 주시겠습니까? 웹 레이어 또는 서비스 레이어에서 사용하고 있습니까? 위의 일부 발췌 문장을 추가 할 수 있습니까? –

+0

확실한 것. 클라이언트 나 서버 계층에서 사용할 수 있는지 여부는 중요하지 않습니다. – Crowlix

+0

간단한 테스트를 작성하여 봄 3.1.0 및 3.1.3으로 시도했지만 정상적으로 작동했습니다. –

답변

1

을 감상 할 수있다 특정 경로로?

RemoteServiceServlets와 Spring의 통합을 위해 gwt-sl을 사용하고 있습니다.

<servlet> 
    <servlet-name>gwtservice</servlet-name> 
    <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

그리고 당신의 GWT-서블릿 선언 및 매핑 : 은 당신의 web.xml에 디스패처 서블릿을 정의

<bean name="DeviceListenerServlet" class="your.package.your.SomeService"/> 
<bean id="urlMappingGWT" class="org.gwtwidgets.server.spring.GWTHandler"> 
    <property name="mappings"> 
     <map> 
      <entry key="/service" value-ref="DriverServiceImpl"/> 
     </map> 
    </property> 
</bean> 

그리고 내 예제가 될 것입니다 (당신의 RemoteService에 클래스에 주석을 변경 @RemoteServiceRelativePath ("gwtservice/service")). (추가 한 경우)

지금 당신은 당신에게

희망이 도움을 @Secured 주석을 사용할 수 있습니다.

+0

gwt-sl을 설치하려면 어떻게해야합니까? 사이트에서는이를 수행하는 방법을 지정하지 않습니다. jar 파일을 lib 폴더로 가져와야합니까? – Crowlix