Handling AccessDenied with Method Level Security

前端 未结 3 413
春和景丽
春和景丽 2021-01-05 03:29

i have a method secured with spring security as follows:

@PreAuthorize(\"hasRole(\'add_user\')\")
public void addUser(User user) ;

and if a

3条回答
  •  礼貌的吻别
    2021-01-05 04:06

    Spring Security redirect to the access denied page just when the user don't have authorization to access the resource. This is, when the user is authenticated but doesn't have the allowed roles.

    But when the problem is not authorization, but authentication, Spring Security redirects to the login page (to let the user authenticate himself/herself), not to the access denied page.

    As you have a rule checking for "isAuthenticated()" in the rules, you won't be redirected to the access denied page, but to the login page.

    Hope it helps.

提交回复
热议问题