Java 在spring security中访问特定用户的特定URL
在我的应用程序中,我有两个角色,一个角色是让来宾查看数据,另一个角色是管理员。在管理员页面中,管理员可以编辑数据,在查看页面中,来宾角色可以查看数据。当我尝试访问URL时,我可以看到guest和admin的页面视图和admin,但我希望guest不应该访问admin页面 以下是我的spring安全文件:Java 在spring security中访问特定用户的特定URL,java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,在我的应用程序中,我有两个角色,一个角色是让来宾查看数据,另一个角色是管理员。在管理员页面中,管理员可以编辑数据,在查看页面中,来宾角色可以查看数据。当我尝试访问URL时,我可以看到guest和admin的页面视图和admin,但我希望guest不应该访问admin页面 以下是我的spring安全文件: <b:beans xmlns="http://www.springframework.org/schema/security" xmlns:b="http://www.s
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<http auto-config="true" use-expressions="true">
<!-- Adds Support for basic authentication -->
<intercept-url pattern="/admin" access="hasAnyRole('ROLE_USER')" />
<!-- <http-basic /> -->
<form-login login-page="/login" authentication-failure-url="/loginFailed" default-target-url="/view" />
<logout />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="leader" password="1234" authorities="ROLE_ADMIN" />
<user name="sudheer" password="1234" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</b:beans>
下面是我的控制器类:
@RequestMapping(value="/admin", method=RequestMethod.GET)
public ModelAndView admin(){
ModelAndView model = new ModelAndView();
List<ApplicationTO> list=application.getApplicationList();
model.addObject("applicationList", list);
model.setViewName("admin");
return model;
}
@RequestMapping(value="/view", method=RequestMethod.GET)
public ModelAndView view(){
ModelAndView model = new ModelAndView();
List<ApplicationTO> list=application.getApplicationList();
model.addObject("applicationList", list);
model.setViewName("view");
return model;
}
@RequestMapping(value=“/admin”,method=RequestMethod.GET)
公共模型和视图管理(){
ModelAndView模型=新的ModelAndView();
List=application.getApplicationList();
addObject(“应用程序列表”,列表);
model.setViewName(“管理员”);
收益模型;
}
@RequestMapping(value=“/view”,method=RequestMethod.GET)
公共模型和视图(){
ModelAndView模型=新的ModelAndView();
List=application.getApplicationList();
addObject(“应用程序列表”,列表);
model.setViewName(“视图”);
收益模型;
}
请将-
从您的代码更改为
<intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')" />
请将-
从您的代码更改为
<intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')" />