异常:The absolute uri: http://www.springframework.org/security/tags cannot be resolved in either web.xml or the jar files deployed with this application

简介: The absolute uri: http://www.springframework.org/security/tags cannot be resolved in either web.xml or the jar files deployed with this application   需要添加spring-security-taglibs-3.

The absolute uri: http://www.springframework.org/security/tags cannot be resolved in either web.xml or the jar files deployed with this application

 

需要添加spring-security-taglibs-3.0.5.RELEASE.jar包及其依赖包

对于spring security我只是初学者,原来只是想找一个用于权限验证的源码借鉴一下,结果一搜索,就搜到了spring security安全机制框架,我现在要将这个安全机制框架整合到我原来的ssh项目中去。 
我现在只是在实验和学习阶段,没有深入的东西,用户名密码及其权限均是在xml文件配置的,以后有时间再学习一下如何和数据库交互,下面仅是简单的整合,将spring security的示例整合到项目中去。如果你是下载的spring security的发行包,会在其dist目录下找到一个spring-security-samples-tutorial-x.x.x.xxxxx.war的war包,我直接使用了这里的applicationContext-security.xml和jsp文件。 

下面开始整合: 

1.首先添加jar包依赖,我使用的maven来管理依赖包,只需添加下面依赖: 

Xml代码   收藏代码
  1. <dependency>  
  2.     <groupId>org.springframework.security</groupId>  
  3.     <artifactId>spring-security-core</artifactId>  
  4.     <version>3.0.5.RELEASE</version>  
  5. </dependency>  
  6. <dependency>  
  7.     <groupId>org.springframework.security</groupId>  
  8.     <artifactId>spring-security-web</artifactId>  
  9.     <version>3.0.5.RELEASE</version>  
  10. </dependency>  
  11. <dependency>  
  12.     <groupId>org.springframework.security</groupId>  
  13.     <artifactId>spring-security-config</artifactId>  
  14.     <version>3.0.5.RELEASE</version>  
  15. </dependency>  


版本号自己控制,我使用的3.0.5.RELEASE版本,自己手动管理jar包依赖的,将dist目录下的除了war包和***-sources.jar外的所有jar包添加项目下。 

2.在web.xml下配置spring security的过滤器和spring security的配置文件的位置,这里注意,在ssh框架整合spring security时,一定要将spring security的filter-mapping配置在struts2的filter-mapping之前,否则会出现如下错误: 

Html代码   收藏代码
  1. HTTP ERROR 404  
  2.   
  3. Problem accessing /Struts_Spring_Maven/spring_security_login. Reason:  
  4.   
  5.     There is no Action mapped for namespace [/] and action name [spring_security_login] associated with context path [/Struts_Spring_Maven].  


struts2和spring security配置如下: 

Xml代码   收藏代码
  1. <context-param>  
  2.     <param-name>contextConfigLocation</param-name>  
  3.     <param-value>  
  4.         classpath:applicationContext.xml  
  5.         /WEB-INF/applicationContext-security.xml  
  6.     </param-value>  
  7. </context-param>  
  8. <!-- 配置Struts中心过滤器 -->  
  9. <filter>  
  10.     <filter-name>struts2</filter-name>  
  11.     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  
  12.     <init-param>  
  13.         <param-name>actionPackages</param-name>  
  14.         <param-value>zwh.struts.maven.action</param-value>  
  15.     </init-param>  
  16. </filter>  
  17.   
  18. <!-- 配置spring security的过滤器 -->  
  19. <filter>  
  20.     <filter-name>springSecurityFilterChain</filter-name>  
  21.     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>  
  22. </filter>  
  23.   
  24. <!-- spring security的filter-mapping一定要配置struts的前面 -->  
  25. <filter-mapping>  
  26.   <filter-name>springSecurityFilterChain</filter-name>  
  27.   <url-pattern>/*</url-pattern>  
  28. </filter-mapping>  
  29. <!-- struts的filter-mapping -->  
  30. <filter-mapping>  
  31.     <filter-name>struts2</filter-name>  
  32.     <url-pattern>/*</url-pattern>  
  33. </filter-mapping>  



3.添加applicationContext-security.xml文件,我是直接将示例项目中的文件直接拷贝到我的项目中去的,拷贝到WEB-INF目录下。文件内容如下: 

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans:beans xmlns="http://www.springframework.org/schema/security"  
  3.     xmlns:beans="http://www.springframework.org/schema/beans"  
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  6.                         http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">  
  7.   
  8.     <global-method-security pre-post-annotations="enabled">  
  9.         <!-- AspectJ pointcut expression that locates our "post" method and applies security that way  
  10.         <protect-pointcut expression="execution(* bigbank.*Service.post*(..))" access="ROLE_TELLER"/>  
  11.         -->  
  12.     </global-method-security>  
  13.   
  14.     <http use-expressions="true">  
  15.         <intercept-url pattern="/secure/extreme/**" access="hasRole('ROLE_SUPERVISOR')"/>  
  16.         <intercept-url pattern="/secure/**" access="isAuthenticated()" />  
  17.         <!-- Disable web URI authorization, as we're using <global-method-security> and have @Secured the services layer instead  
  18.         <intercept-url pattern="/listAccounts.html" access="isRememberMe()" />  
  19.         <intercept-url pattern="/post.html" access="hasRole('ROLE_TELLER')" />  
  20.         -->  
  21.         <intercept-url pattern="/**" access="permitAll" />  
  22.         <form-login />  
  23.         <logout />  
  24.         <remember-me />  
  25. <!--  
  26.     Uncomment to enable X509 client authentication support  
  27.         <x509 />  
  28. -->  
  29.         <!-- Uncomment to limit the number of sessions a user can have -->  
  30.         <session-management invalid-session-url="/timeout.jsp">  
  31.             <concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />  
  32.         </session-management>  
  33.   
  34.     </http>  
  35.   
  36.     <!--  
  37.     Usernames/Passwords are  
  38.         rod/koala  
  39.         dianne/emu  
  40.         scott/wombat  
  41.         peter/opal  
  42.     -->  
  43.     <authentication-manager>  
  44.         <authentication-provider>  
  45.             <password-encoder hash="md5"/>  
  46.             <user-service>  
  47.                 <user name="rod" password="a564de63c2d0da68cf47586ee05984d7" authorities="ROLE_SUPERVISOR, ROLE_USER, ROLE_TELLER" />  
  48.                 <user name="dianne" password="65d15fe9156f9c4bbffd98085992a44e" authorities="ROLE_USER,ROLE_TELLER" />  
  49.                 <user name="scott" password="2b58af6dddbd072ed27ffc86725d7d3a" authorities="ROLE_USER" />  
  50.                 <user name="peter" password="22b5c9accc6e1ba628cedc63a72d57f8" authorities="ROLE_USER" />  
  51.             </user-service>  
  52.         </authentication-provider>  
  53.     </authentication-manager>  
  54.   
  55. </beans:beans>  


从该文件中可以看到/secure路径下面的所有文件的访问需要登陆才能访问,而/secure/extreme路径下的所有文件的访问必须是超级用户,即具备ROLE_SUPERVISOR的角色。rod是超级用户,密码是koala,后面登陆需要使用。 

4.在项目目录下创建secure目录和secure/extreme目录,并在这些目录下放一些需要验证才能访问的页面,我为了省事,将示例中jsp页面直接拷贝到项目目录下了。 

5.下面将该项目添加到tomcat中去,运行,访问http://localhost:8080/项目名称/secure/index.jsp 。这时你发现并不是展示出你访问的页面,而是出现了一个登陆页面。如下: 
 

6.输入用户名rod和密码koala,提交,这时就可以看到了你想要访问的页面了。 

7.如果遇到如下问题: 

Html代码   收藏代码
  1. The absolute uri: http://www.springframework.org/security/tags cannot be resolved in either web.xml or the jar files deployed with this application.  


对于maven还需要添加如下依赖 

Xml代码   收藏代码
  1. <dependency>  
  2.     <groupId>org.springframework.security</groupId>  
  3.     <artifactId>spring-security-taglibs</artifactId>  
  4.     <version>3.0.5.RELEASE</version>  
  5. </dependency>  


自己管理jar包需要添加spring-security-taglibs-3.0.5.RELEASE.jar包及其依赖包。

若转载请注明出处!若有疑问,请回复交流!
目录
相关文章
|
存储 安全 前端开发
第6章 Spring Security 的 Web 安全性(2024 最新版)(上)
第6章 Spring Security 的 Web 安全性(2024 最新版)
329 0
|
3月前
|
开发框架 监控 安全
Windows Defender 导致 Web IIS 服务异常停止排查
某日凌晨IIS服务异常停止,经查为Windows Defender安全补丁KB2267602触发引擎更新,导致系统资源波动,进而引发应用池回收。确认非人为操作,系统无重启。通过分析日志与监控,定位原因为Defender更新后扫描加重负载。解决方案:将IIS及.NET相关路径添加至Defender排除列表,避免业务影响。
529 116
|
安全 Java Go
第6章 Spring Security 的 Web 安全性(2024 最新版)(下)
第6章 Spring Security 的 Web 安全性(2024 最新版)
414 1
|
7月前
|
安全 网络安全 流计算
修改代码以确保对SSL和HTTP异常的正确处理。
记得,在海上和代码世界里,风暴总是突如其来。但只要你的代码准备妥当,合理地处理SSL和HTTP异常,你的小船就能安全航行,最终到达它的目的地。
176 12
【Azure 应用服务】Web App Service 中的 应用程序配置(Application Setting) 怎么获取key vault中的值
【Azure 应用服务】Web App Service 中的 应用程序配置(Application Setting) 怎么获取key vault中的值
196 0
|
10月前
|
移动开发 前端开发 API
鸿蒙web加载本地网页资源异常
在鸿蒙NEXT Api 12中,为解决Web组件加载本地资源(如图片、CSS等)失败的问题,我们采用拦截机制。具体步骤如下: 1. **替换路径**:通过正则表达式将HTML和CSS中的资源路径替换为带有标记的URL(如`http://local`),以便后续识别。 2. **拦截与返回**:在资源加载时,拦截带有标记的URL,读取对应的本地文件并返回给Web组件。此过程确保了本地资源能正确加载和显示。 代码实现包括路径替换、资源拦截及响应构建,确保Web页面能够顺利加载本地资源。
602 7
|
11月前
|
网络协议 Java Shell
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
783 7
|
前端开发 JavaScript Java
如何捕获和处理HTTP GET请求的异常
如何捕获和处理HTTP GET请求的异常
|
监控 前端开发 Serverless
现代化 Web 应用构建问题之观测站点的PV、UV和API异常等指标如何解决
现代化 Web 应用构建问题之观测站点的PV、UV和API异常等指标如何解决
194 2
|
Java Linux Shell
【Azure 应用服务】部署Jar到App Service for Linux,因启动命令路径配置错误而引起:( Application Error 问题
【Azure 应用服务】部署Jar到App Service for Linux,因启动命令路径配置错误而引起:( Application Error 问题
254 0