【发布时间】:2010-09-21 23:35:45
【问题描述】:
我为用户提供带有访问密钥的特殊 URL。与简单的匿名用户相比,通过这个特殊 url 访问公共页面的用户应该能够看到一些额外的数据。
我想根据请求中提供的参数给匿名用户一些额外的角色,这样我就可以在我的模板中做这样的事情:
<@sec.authorize ifAnyGranted="ROLE_ADMIN, ROLE_USER, ROLE_INVITED_VISITOR">
...some additional stuff for invited user to see
</@sec.authorize>
目前我正在实现 Spring 的 OncePerRequestfilter:
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
if (null != request.getParameter("accessKey")) {
if(isValid(request.getParameter("accessKey"))) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
//how do i add additional roles to authenticated (potentially anonymous) user?
}
}
}
【问题讨论】:
标签: spring-security roles anonymous