我必须将方法的访问限制为仅具有特定角色的用户。 IdentityManager 已正确构建。
我有这个 Controller 类。
@Named
@RequestScoped
@LoggedIn
public class UserController{
@RolesAllowed({"tt"})
public String saveUserChanges() {
...
...
}
}
该类处理上述 saveUserChanges
方法抛出的 AccessDeniedException
。
@ExceptionHandler
public class SecurityExceptionHandler {
public void onAccessDeniedException(@BeforeHandles ExceptionEvent<AccessDeniedException> event) {
...
...
}
}
问题是 AccessDeniedException
被 SecurityExceptionHandler
类正确抛出并捕获,但方法 saveUserChanges()
仍然被执行。
是吗?我希望如果用户没有“tt”角色,则不再执行 saveUserChanges()
方法。
最佳答案
您是否注释了在 saveUserChanges()
完成后失败的其他函数?您使用 @Logged
对您的 UserController
进行了注释,以便至少登录的人可以执行您的所有功能,并且您的 @RolesAllowed
注释可能不会执行完全在工作。
关于java - @RolesAllowed 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25384514/