Spring Security antMachers -
i using spring security 3.2.0.release. want redirect user url if not permitted see page, how can this?
.antmatchers("/cabinet/control/members/*").hasrole("owner").redirectto(..)
you have define access denied handler/page, see spring security reference:
if
accessdeniedexception
thrown , user has been authenticated, means operation has been attempted don’t have enough permissions. in case,exceptiontranslationfilter
invoke second strategy,accessdeniedhandler
. default,accessdeniedhandlerimpl
used, sends 403 (forbidden) response client. alternatively can configure instance explicitly (as in above example) , set error page url forwards request [13]. can simple "access denied" page, such jsp, or more complex handler such mvc controller. , of course, can implement interface , use own implementation.
example:
@override protected void configure(final httpsecurity http) throws exception { http .authorizerequests() .antmatchers("/cabinet/control/members/*").hasrole("owner") .and() .exceptionhandling() .accessdeniedpage("/access_denied.jsp") .and() .formlogin(); }
Comments
Post a Comment