Search code examples
spring-securityhdiv

Generate Valid hdiv url in controller


i have successfully configured Spring Boot 2.0.4 to use spring-security with HDIV. I decided to use jquery datatable as table rendering technology. Here come the problem... For each row of my datatable i'd like to create a detail link signed with _HDIV_STATE_ parameter how can i generate a valid link while iterating my item list in a controller?

A generic Controller:

@Controller
public class ItemController {

   ....

   @GetMapping(value = "/test")
   public @ResponseBody test() {
      List<Item> items = service.getList();
      items.foreach(item -> {
         item.setDetailUrl(HDIV_GENERATED_URL);
      })
    }

   ...

  }

Thanks


Solution

  • You can inject the LinkUrlProcessor class in the controller.

    @autowired
    LinkUrlProcessor linkUrlProcessor;
    

    And invoke processUrl method.

    String processedUrl linkUrlProcessor.processUrl(request, originalUrl);
    

    The processedUrl will contain the _HDIV_STATE_ parameter.