2012-05-23 5 views
3

저는 스프링 MVC와 스프링 보안을 사용하고 있습니다.스프링 보안 + MVC 주석 잘못된 인수 예외

주석 중심의 컨트롤러가 있고 보안 주석을 추가하려고합니다.

컨트롤러 코드 :

@Controller 
public class SomeController implements MessageSourceAware { 

    @Secured("ROLE_ADMIN") 
    @RequestMapping(value = "/somepage", method = RequestMethod.GET) 
    public String getPage(HttpServletRequest request, ModelMap model) { 
     // logic 
     return ADMIN_VIEW_NAME; 
    }

spring-security.xml :

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class 
HandlerMethod details: 
Controller [$Proxy139] 
Method [public java.lang.String SomeController.getPage(javax.servlet.http.HttpServletRequest,org.springframework.ui.ModelMap)] 
Resolved arguments: 
[0] [type=org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper] [value=SecurityContextHolderAwareRequestWrapper[ FirewalledRequest[ [email protected]]]] 
[1] [type=org.springframework.validation.support.BindingAwareModelMap] [value={}]

내가 보안 주석 및 주석 다음을 제거하는 경우 : 나는 열려있는 보안 페이지를하려고하면

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:security="http://www.springframework.org/schema/security" 
     xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
     http://www.springframework.org/schema/security 
     http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 

    <security:global-method-security secured-annotations="enabled" /> 

    <security:http auto-config="true" use-expressions="true" access-denied-page="/denied"> 

     <security:intercept-url pattern="/login" access="permitAll"/> 
     <!--<security:intercept-url pattern="/admin" access="hasRole('ROLE_ADMIN')"/>--> 

     <security:form-login 
       login-page="/login" 
       authentication-failure-url="/login?error=true" 
       default-target-url="/index"/> 

     <security:logout 
       invalidate-session="true" 
       logout-success-url="/login" 
       logout-url="/logout"/> 

    </security:http> 

    <!-- Declare an authentication-manager to use a custom userDetailsService --> 
    <security:authentication-manager> 
     <security:authentication-provider user-service-ref="authManager"> 
      <security:password-encoder ref="passwordEncoder"/> 
     </security:authentication-provider> 
    </security:authentication-manager> 

    <!-- Use a SHA encoder since the user's passwords are stored as SHA in the database --> 
    <bean class="org.springframework.security.authentication.encoding.ShaPasswordEncoder" id="passwordEncoder"/> 

    <!-- A custom service where Spring will retrieve users and their corresponding access levels --> 
    <bean id="authManager" class="some.package.AdminManager"/> 

</beans>

것은 내가 오류 다음 얻을 spring-security.xml의 전화 번호 :

<security:intercept-url pattern="/admin" access="hasRole('ROLE_ADMIN')"/>

모두 정상적으로 작동합니다.

도움 주셔서 감사합니다.

답변

11

주요 디스패처 서블릿, 서블릿의 context.xml 또는 응용 프로그램의 context.xml 같은 보통 무언가가 참조하는 XML 파일에 스프링 security.xml에서 이동

<security:global-method-security secured-annotations="enabled" /> 

여기 를 참조하십시오 또한 http://static.springsource.org/spring-security/site/faq/faq.html#faq-method-security-in-web-context

, 난 당신이

처럼뿐만 아니라 글로벌 방법 보안 주석에 '프록시 대상 클래스 = "true"로'추가 할 필요가 있다고 생각
<security:global-method-security secured-annotations="enabled" proxy-target-class="true"/> 
+1

감사합니다. 'proxy-target-class'가 필요합니다. 나는 cglib와 asm을 추가했으며 작동한다. –

관련 문제