Hello. I'm having a weird error thrown when I try to use @Secured or @PreAuthorize in a @Controller method already annotated with @RequestMapping. It gives me the following error when I try to start the application:
I'm using spring 3.1 and spring security 3.1. Also, the main sections of my servlet and security context files are:Code:Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file com/dnp/web/controllers/HomeController at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) at java.lang.ClassLoader.defineClass(ClassLoader.java:615) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2820) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1150) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523) at org.springframework.util.ClassUtils.forName(ClassUtils.java:258) at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:417) at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1283) at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1254) ... 43 more
security-context.xml
servlet-context.xmlCode:<http pattern="/resources/**" security="none"/> <http use-expressions="true" entry-point-ref="authenticationEntryPoint"> <intercept-url pattern="/login.htm*" access="isAnonymous()" /> <intercept-url pattern="/*" access="isAuthenticated()" /> <form-login authentication-failure-url="/login.htm" /> <logout /> </http> <authentication-manager alias="authenticationManager"> <authentication-provider user-service-ref="usuarioService"> <password-encoder ref="passwordEncoder" /> </authentication-provider> </authentication-manager> <!-- Login form ajax redirection --> <beans:bean id="authenticationEntryPoint" class="com.dnp.security.impl.JsonAwareAuthenticationEntryPoint"> <beans:constructor-arg name="loginFormUrl" value="/login.htm" /> </beans:bean> <!-- Password encoder --> <beans:bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" />
And the controller code:Code:<!-- Secured controller actions --> <sec:global-method-security pre-post-annotations="enabled" /> <!-- Enables the Spring MVC @Controller programming model --> <annotation-driven conversion-service="conversionService" /> <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> <resources mapping="/resources/**" location="/resources/" /> <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <beans:property name="prefix" value="/WEB-INF/views/" /> <beans:property name="suffix" value=".jsp" /> </beans:bean> <context:component-scan base-package="com.dnp.web.controllers" /> <!-- Enable @Valid for @RequestBody --> <beans:bean class="com.dnp.util.RequestBodyValidatorAspect" /> <!-- Flash service --> <beans:bean id="flashService" class="com.dnp.service.impl.FlashServiceImpl" scope="session"> <aop:scoped-proxy proxy-target-class="false" /> </beans:bean>
PD: The full application trace is here: http://pastebin.com/raw.php?i=VxdYPDXLCode:@Controller public class HomeController { private static final Logger logger = LoggerFactory.getLogger(HomeController.class); /** * Simply selects the home view to render by returning its name. */ @PreAuthorize("hasRole('ROLE_USER')") @RequestMapping(value = "/", method = RequestMethod.GET) public String home(Locale locale, Model model) { logger.info("Welcome home! the client locale is "+ locale.toString()); Date date = new Date(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); String formattedDate = dateFormat.format(date); model.addAttribute("serverTime", formattedDate ); return "home"; } }


Reply With Quote