Skip to content

Session Implementation

Jonathan edited this page Jun 13, 2019 · 1 revision

How to Use Session from function-session Module


Table of Contents


Implementation Steps

  1. Add Session object to your controller method's parameter, whether it is used or not.
  2. Annotate your controller class/method/parameter with annotation WithAnyRole
  3. Specify allowed roles by roles field in the annotation, which accepts one or many roles.
  4. Specify if the controller method should throw unauthorized exception or not by setting noUnauthorized true for not throwing exception. If unauthorized exception is expected to be thrown, then ignore the field as default falue for noUnauthorized is false.
  5. Session now works.

Testing Steps

  1. For controller test classes, extend TestHelper.
  2. In each test method (or setUp method, whichever depends on your testing needs), call super.setCookie(<specified_role>);.
  3. In calling the API using mockMvc from TestHelper, specify the cookie by adding .cookie(cookies) after the URI call. For example:
mockMvc.perform(get("/api/test")
   .cookie(cookies)
   .param("param", "name"));
  1. Run the test, which should be working fine.

Further questions can be consulted to team.

Clone this wiki locally