Spring-Security sec:授权标签不起作用

时间:2014-07-22 11:03:26

标签: java spring security spring-security taglib

我最近更新了一个Springsource-Project,让它在Tomcat7和Hibernate 3.5.x上运行。

它似乎已经差不多完成了,但是当我到达一个定义了sec:authorize标签的jsp-Page时,会抛出异常:

> Jul 22, 2014 12:42:42 PM org.apache.catalina.core.StandardWrapperValve
> invoke Schwerwiegend: Servlet.service() for servlet [partsorder] in
> context with path [/partsorder] threw exception
> [/WEB-INF/jsp/application/details.jsp (line: 157, column: 0) Unable to
> load tag handler class
> "org.springframework.security.taglibs.authz.AuthorizeTag" for tag
> "sec:authorize"] with root cause org.apache.jasper.JasperException:
> /WEB-INF/jsp/application/details.jsp (line: 157, column: 0) Unable to
> load tag handler class
> "org.springframework.security.taglibs.authz.AuthorizeTag" for tag
> "sec:authorize"   at
> org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
>   at
> org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
>   at
> org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:199)
>   at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1226)
>   at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1452)
>   at org.apache.jasper.compiler.Parser.parse(Parser.java:138)     at
> org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
>   at
> org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
>   at
> org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
>   at org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)   at
> org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)    at
> org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)    at
> org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
>   at
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
>   at
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
>   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
>   at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)     at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
>   at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>   at
> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
>   at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
>   at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>   at
> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
>   at
> org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
>   at
> org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
>   at
> org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
>   at
> org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
>   at
> org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
>   at
> org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1225)
>   at
> org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1012)
>   at
> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
>   at
> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
>   at
> org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
>   at
> org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
>   at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)     at
> org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
>   at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)     at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
>   at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>   at
> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
>   at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
>   at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>   at
> org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:177)
>   at
> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
>   at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
>   at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>   at
> org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
>   at
> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
>   at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
>   at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>   at
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
>   at
> org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
>   at
> org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
>   at
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
>   at
> org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
>   at
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
>   at
> org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
>   at
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
>   at
> org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
>   at
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
>   at
> org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
>   at
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
>   at
> org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
>   at
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
>   at
> org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter.doFilter(AbstractPreAuthenticatedProcessingFilter.java:94)
>   at
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
>   at
> org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
>   at
> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
>   at
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
>   at
> org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
>   at
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
>   at
> org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
>   at
> org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
>   at
> org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
>   at
> org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
>   at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
>   at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>   at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
>   at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
>   at
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
>   at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
>   at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
>   at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
>   at
> com.bmw.authenticator.extranet.catalina.ExtranetValve.invoke(ExtranetValve.java:175)
>   at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
>   at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
>   at
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
>   at
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
>   at
> org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)
>   at
> org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)
>   at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>   at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>   at java.lang.Thread.run(Thread.java:745)

我的依赖项:

    <hibernateEjb3PersistenceVersion>1.0.2.GA</hibernateEjb3PersistenceVersion>
    <hibernateEntityManagerVersion>3.6.5.Final</hibernateEntityManagerVersion>
    <hibernateValidatorVersion>5.0.3.Final</hibernateValidatorVersion>
    <hibernateVersion>3.5.4-Final</hibernateVersion>
    <hibernateCoreVersion>3.6.5.Final</hibernateCoreVersion>
    <hsqldbVersion>1.8.0.10</hsqldbVersion>
    <httpUnitVersion>1.6.2</httpUnitVersion>
    <javaxMailVersion>1.4.1</javaxMailVersion>
    <!-- javaxPersistenceVersion>1.0.1.Final</javaxPersistenceVersion> -->
    <javaxValidationVersion>1.1.0.Final</javaxValidationVersion>
    <jasperVersion>7.0.34</jasperVersion><!-- 6.0.18 -->
    <jettyVersion>6.1.16</jettyVersion>
    <junitVersion>4.7</junitVersion>
    <log4jVersion>1.2.15</log4jVersion>
    <mavenSurefirePluginVersion>2.4.3</mavenSurefirePluginVersion>
    <mavenJettyPluginVersion>6.1.15</mavenJettyPluginVersion>
    <oracleJdbcDriverVersion>10.2.0.3.0</oracleJdbcDriverVersion>
    <slf4jJclVersion>1.6.1</slf4jJclVersion>
    <springVersion>4.0.2.RELEASE</springVersion>
    <springJsVersion>2.4.0.RELEASE</springJsVersion>
    <springSecurityVersion>3.2.4.RELEASE</springSecurityVersion>
    <xalanVersion>2.7.0</xalanVersion>
    <servletApiVersion>3.1.0</servletApiVersion>
    <jspApiVersion>2.2</jspApiVersion>
    <jstlVersion>1.2</jstlVersion>
    <taglibsVersion>1.1.2</taglibsVersion>
    <elVersion>2.2.4</elVersion>

有人能帮助我吗?

2 个答案:

答案 0 :(得分:0)

看起来你错过了Spring Security Taglib的依赖项 - 请参阅http://mvnrepository.com/artifact/org.springframework.security/spring-security-taglibs

答案 1 :(得分:0)

好的,好像我已经解决了这个问题:

我编辑了security.tld:

而不是:

<tag>
    <name>authorize</name>
    <tag-class>org.springframework.security.taglibs.authz.AuthorizeTag</tag-class>
    <description>
        A tag which outputs the body of the tag if the configured access expression
        evaluates to true for the currently authenticated principal.
    </description>

我已将tag-class更改为:

<tag-class>org.springframework.security.taglibs.authz.JspAuthorizeTag</tag-class>

这对我来说很好,因为现在可以识别sec:authorize选项卡了。