1、配置web.xml文件:
2、配置spring-security.xml(该文件名字与web.xml中的<context-param />中的相对应) :
method拦截有三种配置方式:
第一种方式是在java代码添加注释@Secured({"ROLE_SUPER"})、在spring-security.xml中添加<global-method-security secured-annotations="enabled"></global-method-security>,具体配置如下:
spring-security.xml
@Secured({"ROLE_SUPER"})注释中Secured是注释的名称,括号中是可以访问该方法的角色,用大括号括起来,多个角色用分号分割。可以加在service中也可以加在dao中,可以加在接口中也可以加在接口的实现中,此处是加在service接口的实现中。
CategoryServiceImpl.java
第二种方法是不需要在代码中添加注释,只需在spring-security.xml中添加pointcut,利用表达式和通配符指定要拦截的类及方法:
spring-security.xml
第三种方法是直接在要拦截的bean定义中添加<intercept-methods />对指定方法进行拦截,可以使用通配符:
注意:三种方法都需要在spring-security.xml中保留<http auto-config="true">...</http>,否则会出现找不到springSecurityFilterChain的错误。