How to redirect request when @PreAuthorize returns false

1

I'm learning about Spring MVC and Spring Security .

How do I redirect the page when the next line returns false within a @Controller ?

@PostAuthorize(" hasRole('page')")

If the above line returns true there is no problem and the page displays correctly.

If the above line returns false page is displayed! But all variables get beech, Ex: it displays a table only with the header and without any line.

I ask: how can I redirect to another page instead of displaying the empty page?

    
asked by anonymous 22.10.2017 / 03:57

1 answer

0

Think about whether you can do something like this in your controller:

    @RequestMapping(value = {"/login", "/"})
    public String login(@AuthenticationPrincipal User user){
        //se usuario for true (logado), manda pra home
        if(user != null){
            return "redirect:/home";
        }
       //se usuario for vazio (falso), retorna pro login
        return "Login";
    }
    
14.11.2017 / 13:40