HDIV issue while redirecting in Spring MVC Controller

501 Views Asked by At

I have inherited some Java Spring MVC code that does internal redirects in the Controller on a form submission

Ex:

Form is submitted to

/login_submit       (POST request)

On success, it is redirected inside controller :-

.....
return "redirect:"+"/user/home"

However, since it is inside code and not using <c:redirect> or <c:url> tags, HDIV fails this form submission with

INVALID_ACTION error

Please help on understanding and resolving this preferably without changing the legacy code too much

Many thanks in advance for your prompt reply!!!

1

There are 1 best solutions below

4
On

There are two ways you can achieve it,

1) To skip the validation:

@Configuration
@EnableHdivWebSecurity
public class HdivSecurityConfig extends HdivWebSecurityConfigurerAdapter {
    @Override
    public void addExclusions(ExclusionRegistry registry) {
        registry.addUrlExclusions("/user/home");
    }
}

2) URL can be generated with HDIV's processor as can be seen below,

 LinkUrlProcessor urlProcessor = HDIVUtil.getLinkUrlProcessor(servletContext);
 String processUrl = urlProcessor.processUrl(request, "/user/home");
 return "redirect:"+processUrl;

I hope this should resolve the issue.