@Test @SuppressWarnings("unchecked") void postHandle() { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); User user = mock(User.class); when(user.isSuperuser()).thenReturn(true); when(userAccountService.getCurrentUser()).thenReturn(user); when(appSettings.getLanguageCode()).thenReturn("de"); Object handler = mock(Object.class); ModelAndView modelAndView = new ModelAndView(); molgenisInterceptor.postHandle(request, response, handler, modelAndView); Map<String, Object> model = modelAndView.getModel(); assertEquals(resourceFingerprintRegistry, model.get(KEY_RESOURCE_FINGERPRINT_REGISTRY)); Map<String, String> environmentAttributes = gson.fromJson(String.valueOf(model.get(PluginAttributes.KEY_ENVIRONMENT)), HashMap.class); assertNotNull(model.get(KEY_APP_SETTINGS)); assertEquals(environment, environmentAttributes.get(ATTRIBUTE_ENVIRONMENT_TYPE)); assertTrue(model.containsKey(PluginAttributes.KEY_I18N)); assertSame(gson, model.get(KEY_GSON)); assertSame("de", model.get(KEY_FALLBACK_LANGUAGE)); assertSame(true, model.get(KEY_SUPER_USER)); }
@Override public void postHandle( HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { if (modelAndView != null) { String viewName = modelAndView.getViewName(); if (viewName == null || !viewName.startsWith("forward:")) { TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager); transactionTemplate.setReadOnly(true); transactionTemplate.execute( status -> { modelAndView.addObject( KEY_RESOURCE_FINGERPRINT_REGISTRY, resourceFingerprintRegistry); modelAndView.addObject(KEY_THEME_FINGERPRINT_REGISTRY, themeFingerprintRegistry); modelAndView.addObject(KEY_APP_SETTINGS, createAppSettings()); modelAndView.addObject( KEY_AUTHENTICATION_OIDC_CLIENTS, runAsSystem(this::getOidcClients)); modelAndView.addObject( KEY_AUTHENTICATION_SIGN_UP, authenticationSettings.getSignUp()); modelAndView.addObject(KEY_ENVIRONMENT, getEnvironmentAttributes()); modelAndView.addObject( KEY_I18N, new MessageSourceResourceBundle(messageSource, LocaleContextHolder.getLocale())); modelAndView.addObject(KEY_GSON, gson); modelAndView.addObject(KEY_LANGUAGE, LocaleContextHolder.getLocale().getLanguage()); modelAndView.addObject(KEY_FALLBACK_LANGUAGE, appSettings.getLanguageCode()); modelAndView.addObject( KEY_SUPER_USER, userAccountService.getCurrentUser().isSuperuser()); return null; }); } } }
MolgenisInterceptor extends HandlerInterceptorAdapter { @Override public void postHandle( HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { if (modelAndView != null) { String viewName = modelAndView.getViewName(); if (viewName == null || !viewName.startsWith("forward:")) { TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager); transactionTemplate.setReadOnly(true); transactionTemplate.execute( status -> { modelAndView.addObject( KEY_RESOURCE_FINGERPRINT_REGISTRY, resourceFingerprintRegistry); modelAndView.addObject(KEY_THEME_FINGERPRINT_REGISTRY, themeFingerprintRegistry); modelAndView.addObject(KEY_APP_SETTINGS, createAppSettings()); modelAndView.addObject( KEY_AUTHENTICATION_OIDC_CLIENTS, runAsSystem(this::getOidcClients)); modelAndView.addObject( KEY_AUTHENTICATION_SIGN_UP, authenticationSettings.getSignUp()); modelAndView.addObject(KEY_ENVIRONMENT, getEnvironmentAttributes()); modelAndView.addObject( KEY_I18N, new MessageSourceResourceBundle(messageSource, LocaleContextHolder.getLocale())); modelAndView.addObject(KEY_GSON, gson); modelAndView.addObject(KEY_LANGUAGE, LocaleContextHolder.getLocale().getLanguage()); modelAndView.addObject(KEY_FALLBACK_LANGUAGE, appSettings.getLanguageCode()); modelAndView.addObject( KEY_SUPER_USER, userAccountService.getCurrentUser().isSuperuser()); return null; }); } } } }
MolgenisInterceptor extends HandlerInterceptorAdapter { @Override public void postHandle( HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { if (modelAndView != null) { String viewName = modelAndView.getViewName(); if (viewName == null || !viewName.startsWith("forward:")) { TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager); transactionTemplate.setReadOnly(true); transactionTemplate.execute( status -> { modelAndView.addObject( KEY_RESOURCE_FINGERPRINT_REGISTRY, resourceFingerprintRegistry); modelAndView.addObject(KEY_THEME_FINGERPRINT_REGISTRY, themeFingerprintRegistry); modelAndView.addObject(KEY_APP_SETTINGS, createAppSettings()); modelAndView.addObject( KEY_AUTHENTICATION_OIDC_CLIENTS, runAsSystem(this::getOidcClients)); modelAndView.addObject( KEY_AUTHENTICATION_SIGN_UP, authenticationSettings.getSignUp()); modelAndView.addObject(KEY_ENVIRONMENT, getEnvironmentAttributes()); modelAndView.addObject( KEY_I18N, new MessageSourceResourceBundle(messageSource, LocaleContextHolder.getLocale())); modelAndView.addObject(KEY_GSON, gson); modelAndView.addObject(KEY_LANGUAGE, LocaleContextHolder.getLocale().getLanguage()); modelAndView.addObject(KEY_FALLBACK_LANGUAGE, appSettings.getLanguageCode()); modelAndView.addObject( KEY_SUPER_USER, userAccountService.getCurrentUser().isSuperuser()); return null; }); } } } MolgenisInterceptor(
      ResourceFingerprintRegistry resourceFingerprintRegistry,
      ThemeFingerprintRegistry themeFingerprintRegistry,
      AppSettings appSettings,
      AuthenticationSettings authenticationSettings,
      @Value("${environment}") String environment,
      MessageSource messageSource,
      Gson gson,
      PlatformTransactionManager transactionManager,
      UserAccountService userAccountService); }
MolgenisInterceptor extends HandlerInterceptorAdapter { @Override public void postHandle( HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { if (modelAndView != null) { String viewName = modelAndView.getViewName(); if (viewName == null || !viewName.startsWith("forward:")) { TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager); transactionTemplate.setReadOnly(true); transactionTemplate.execute( status -> { modelAndView.addObject( KEY_RESOURCE_FINGERPRINT_REGISTRY, resourceFingerprintRegistry); modelAndView.addObject(KEY_THEME_FINGERPRINT_REGISTRY, themeFingerprintRegistry); modelAndView.addObject(KEY_APP_SETTINGS, createAppSettings()); modelAndView.addObject( KEY_AUTHENTICATION_OIDC_CLIENTS, runAsSystem(this::getOidcClients)); modelAndView.addObject( KEY_AUTHENTICATION_SIGN_UP, authenticationSettings.getSignUp()); modelAndView.addObject(KEY_ENVIRONMENT, getEnvironmentAttributes()); modelAndView.addObject( KEY_I18N, new MessageSourceResourceBundle(messageSource, LocaleContextHolder.getLocale())); modelAndView.addObject(KEY_GSON, gson); modelAndView.addObject(KEY_LANGUAGE, LocaleContextHolder.getLocale().getLanguage()); modelAndView.addObject(KEY_FALLBACK_LANGUAGE, appSettings.getLanguageCode()); modelAndView.addObject( KEY_SUPER_USER, userAccountService.getCurrentUser().isSuperuser()); return null; }); } } } MolgenisInterceptor(
      ResourceFingerprintRegistry resourceFingerprintRegistry,
      ThemeFingerprintRegistry themeFingerprintRegistry,
      AppSettings appSettings,
      AuthenticationSettings authenticationSettings,
      @Value("${environment}") String environment,
      MessageSource messageSource,
      Gson gson,
      PlatformTransactionManager transactionManager,
      UserAccountService userAccountService); @Override void postHandle(
      HttpServletRequest request,
      HttpServletResponse response,
      Object handler,
      ModelAndView modelAndView); }
MolgenisInterceptor extends HandlerInterceptorAdapter { @Override public void postHandle( HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { if (modelAndView != null) { String viewName = modelAndView.getViewName(); if (viewName == null || !viewName.startsWith("forward:")) { TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager); transactionTemplate.setReadOnly(true); transactionTemplate.execute( status -> { modelAndView.addObject( KEY_RESOURCE_FINGERPRINT_REGISTRY, resourceFingerprintRegistry); modelAndView.addObject(KEY_THEME_FINGERPRINT_REGISTRY, themeFingerprintRegistry); modelAndView.addObject(KEY_APP_SETTINGS, createAppSettings()); modelAndView.addObject( KEY_AUTHENTICATION_OIDC_CLIENTS, runAsSystem(this::getOidcClients)); modelAndView.addObject( KEY_AUTHENTICATION_SIGN_UP, authenticationSettings.getSignUp()); modelAndView.addObject(KEY_ENVIRONMENT, getEnvironmentAttributes()); modelAndView.addObject( KEY_I18N, new MessageSourceResourceBundle(messageSource, LocaleContextHolder.getLocale())); modelAndView.addObject(KEY_GSON, gson); modelAndView.addObject(KEY_LANGUAGE, LocaleContextHolder.getLocale().getLanguage()); modelAndView.addObject(KEY_FALLBACK_LANGUAGE, appSettings.getLanguageCode()); modelAndView.addObject( KEY_SUPER_USER, userAccountService.getCurrentUser().isSuperuser()); return null; }); } } } MolgenisInterceptor(
      ResourceFingerprintRegistry resourceFingerprintRegistry,
      ThemeFingerprintRegistry themeFingerprintRegistry,
      AppSettings appSettings,
      AuthenticationSettings authenticationSettings,
      @Value("${environment}") String environment,
      MessageSource messageSource,
      Gson gson,
      PlatformTransactionManager transactionManager,
      UserAccountService userAccountService); @Override void postHandle(
      HttpServletRequest request,
      HttpServletResponse response,
      Object handler,
      ModelAndView modelAndView); static final String KEY_LANGUAGE; static final String KEY_FALLBACK_LANGUAGE; static final String KEY_SUPER_USER; static final String ATTRIBUTE_ENVIRONMENT_TYPE; }