Child pages
  • Geomajas FAQ
Skip to end of metadata
Go to start of metadata

Security in unit test

To use backend security in a unit test:

  • add before/after to create/destroy context
  • (optionally) autowire SecurityContext if you need it in your test or just for checking
  • (optionally) force reload of application context if you have interference with a previous test that has not cleaned up the context correctly
@ContextConfiguration(locations = {"/org/geomajas/spring/geomajasContext.xml", <others>....})
@TestExecutionListeners(listeners = {ReloadContextTestExecutionListener.class,
		DependencyInjectionTestExecutionListener.class})  // optional, forces reload of application context
@ReloadContext // optional, forces reload of application context
public class MyTest {
	private SecurityContext securityContext; // optional autowired security context
	private securityManager;
	public void login() {
		// assure security context is set
	// alternative for login()
	public void loginWithToken() {
		// alternatively log in with a token of a known user
		String token = userRegisteredBySpecificProcess();
	public void clearSecurityContext() {
		// clear the security context (logout)

  • No labels

1 Comment

  1. In Deskmanager, register user based on a Profile:

    	private SecurityService securityService;
    	* return token
    	public String registerUser(Profile profile) {
    		return ((DeskmanagerSecurityService) securityService).registerRole(RetrieveRolesRequest.MANAGER_ID, profile);