0

When I have spring security settings as below:

<http pattern="/ui/**" auto-config="true" authentication-manager-ref="authenticationManager">
        <intercept-url pattern="/ui/login*" access="isAnonymous() or hasRole('USER')" requires-channel="${web.channel}" />
        <intercept-url pattern="/ui/**" access="hasRole('USER')" requires-channel="${web.channel}" />

        <form-login login-page="/ui/login" login-processing-url="/ui/j_spring_security_check" default-target-url="/ui/dashboard" />
        <logout logout-url="/ui/logout" logout-success-url="/ui/login" />
</http>

my controller is ignored and both methods are never invoked. I've tried adding breakpoints inside both of them but the execution never stops. I have also tried adding System.out.println() to them and nothing was written to system output, so I am pretty sure both methods are either not mapped or just never invoked.

@Controller
public class MyController {

    @RequestMapping(value = { "/ui", "/ui/login"}, method = GET)
    public String indexNoTrailingSlash() {
        return index();
    }

    @RequestMapping(value = "/", method = GET)
    public String index() {
        return "redirect:/ui/dashboard";
    }
}

Security works fine and thanks to default-target-url="/ui/dashboard" in the xml I do get to my dashboard page after successful login. What I want to achieve is, however, that a user is redirected to dashboard also if he's already logged in. I've tried to follow this answer and that's what I need the controller for. Is there a way either to map these methods so I can use my controller for redirecting or to somehow redirect with just spring security?

Thanks :)

Community
  • 1
  • 1
Samuel
  • 2,430
  • 5
  • 31
  • 41
  • 2
    To solve your problem, I used a Redirect Interceptor, see my answer for a similar question http://stackoverflow.com/a/18012060/280244 – Ralph Feb 16 '16 at 07:31
  • why you are using `@Controller` ? instead you have to use `@RestController` to your Rest class Or add `@RequestMapping("/")` to class – ojus kulkarni Feb 16 '16 at 21:19

1 Answers1

0

If the answer link you included is what you look for, do the following for your case.

return new ModelAndView("redirect:/"); 

It will redirect to your index() method.

Tin
  • 794
  • 5
  • 10