Spring Security +spring Boot Custom 403 page

Source: Internet
Author: User

Use the spring security to do permission control when Access does not have permission to jump to the default 403 page of the transfer. Does not meet current project requirements.

is the solution:

 PackageCom.ycmedia;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.EnableAutoConfiguration;Importorg.springframework.boot.autoconfigure.SpringBootApplication;ImportOrg.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;ImportOrg.springframework.boot.context.embedded.ErrorPage;ImportOrg.springframework.context.annotation.Bean;ImportOrg.springframework.http.HttpStatus;ImportOrg.springframework.security.core.userdetails.UserDetailsService;ImportOrg.springframework.web.servlet.config.annotation.ViewControllerRegistry;ImportOrg.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;ImportCom.ycmedia.service.UserService, @SpringBootApplication @enableautoconfiguration Public classApplicationextendsWebmvcconfigureradapter {@Bean PublicUserdetailsservice Userdetailsservice () {return NewUserService (); }    /*** Custom Exception page*/@Bean PublicEmbeddedservletcontainercustomizer Containercustomizer () {return(Container{errorpage Error401page=NewErrorPage (Httpstatus.forbidden, "/403.html"); ErrorPage Error404page=NewErrorPage (Httpstatus.not_found, "/404.html"); ErrorPage Error500page=NewErrorPage (Httpstatus.internal_server_error, "/500.html");       Container.adderrorpages (Error401page, Error404page, error500page);    }); } @Override Public voidaddviewcontrollers (Viewcontrollerregistry registry) {} Public Static voidMain (string[] args) {springapplication.run (application.class, args); }}

See on the net what realizes Accessdeniedhandler, seem not good use.

Spring Security +spring Boot Custom 403 page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.