You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add Session object 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 roles field in the annotation, which accepts one or many roles.
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.
Session now works.
Testing Steps
For controller test classes, extend TestHelper.
In each test method (or setUp method, whichever depends on your testing needs), call super.setCookie(<specified_role>);.
In calling the API using mockMvc from TestHelper, specify the cookie by adding .cookie(cookies) after the URI call. For example: