Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class TestSecurityContextHolder

  1. Object
  2. TestSecurityContextHolder

Who the calling thread’s tests are running as. WithMockUser sets it for a test; a test that needs to change it part-way does so here.

TestSecurityContextHolder.setAuthentication(
        UsernamePasswordAuthenticationToken.authenticated("ada", null, authorities));

While one is set, every request the thread sends through MockMvc is from that authentication, and SecurityContextHolder on the thread holds it.

Methods

public static SecurityContext getContext()The context in place, or an empty one.
public static void setContext(SecurityContext context)Puts context in place for this thread’s tests.
public static void setAuthentication(Authentication authentication)Puts authentication in place for this thread’s tests.
public static void clearContext()Removes what was put in place: the thread’s tests run as nobody again.

Inherited methods

Method details

getContext

public static SecurityContext getContext()
The context in place, or an empty one.

setContext

public static void setContext(SecurityContext context)
Puts context in place for this thread’s tests.

setAuthentication

public static void setAuthentication(Authentication authentication)
Puts authentication in place for this thread’s tests.

clearContext

public static void clearContext()
Removes what was put in place: the thread’s tests run as nobody again.