-
Notifications
You must be signed in to change notification settings - Fork 0
Session Implementation
Jonathan edited this page Jun 13, 2019
·
1 revision
- Add
Sessionobject to your controller method's parameter, whether it is used or not. - Annotate your controller class/method/parameter with annotation
WithAnyRole - Specify allowed roles by
rolesfield in the annotation, which accepts one or many roles. - Specify if the controller method should throw unauthorized exception or not by setting
noUnauthorizedtrue for not throwing exception. If unauthorized exception is expected to be thrown, then ignore the field as default falue fornoUnauthorizedisfalse. - Session now works.
- For controller test classes, extend
TestHelper. - In each test method (or
setUpmethod, whichever depends on your testing needs), callsuper.setCookie(<specified_role>);. - In calling the API using
mockMvcfromTestHelper, specify the cookie by adding.cookie(cookies)after the URI call. For example:
mockMvc.perform(get("/api/test")
.cookie(cookies)
.param("param", "name"));- Run the test, which should be working fine.
Further questions can be consulted to team.