java - How do I add an Access Denied Handler in spring-security-javaconfig -
i'm using spring-security-javaconfig library spring security. if using xml config files, i'd use define custom access denied page:
<http auto-config="true"> <intercept-url pattern="/admin*" access="role_admin" /> <access-denied-handler ref="accessdeniedhandler"/> </http>
here security configuration class far:
@configuration @enablewebsecurity public class securityconfigurator extends websecurityconfigureradapter { @override protected void registerauthentication(authenticationmanagerbuilder auth) throws exception { auth.inmemoryauthentication().withuser("user").password("password").roles("user"); auth.inmemoryauthentication().withuser("admin").password("password").roles("admin"); } @override protected void configure(httpsecurity http) throws exception { http.authorizeurls().antmatchers( "/admin").hasrole("admin"); } }
i suppose should trick:
httpsecurity http = ... http.exceptionhandling().accessdeniedhandler(myaccessdeniedhandler);
Comments
Post a Comment