/** * Create a new {@code DelegatingFilterProxy} that will retrieve the named target * bean from the given Spring {@code WebApplicationContext}. * <p>For use in Servlet 3.0+ environments where instance-based registration of * filters is supported. * <p>The target bean must implement the standard Servlet Filter interface. * <p>The given {@code WebApplicationContext} may or may not be refreshed when passed * in. If it has not, and if the context implements {@link ConfigurableApplicationContext}, * a {@link ConfigurableApplicationContext#refresh() refresh()} will be attempted before * retrieving the named target bean. * <p>This proxy's {@code Environment} will be inherited from the given * {@code WebApplicationContext}. * @param targetBeanName name of the target filter bean in the Spring application * context (must not be {@code null}). * @param wac the application context from which the target filter will be retrieved; * if {@code null}, an application context will be looked up from {@code ServletContext} * as a fallback. * @see #findWebApplicationContext() * @see #setEnvironment(org.springframework.core.env.Environment) */ public DelegatingFilterProxy(String targetBeanName, @Nullable WebApplicationContext wac) { Assert.hasText(targetBeanName, "Target Filter bean name must not be null or empty"); this.setTargetBeanName(targetBeanName); this.webApplicationContext = wac; if (wac != null) { this.setEnvironment(wac.getEnvironment()); } }
private void assertHasStandardServletEnvironment(WebApplicationContext ctx) { // ensure a default servlet environment exists Environment defaultEnv = ctx.getEnvironment(); assertThat(defaultEnv, notNullValue()); assertThat(defaultEnv, instanceOf(StandardServletEnvironment.class)); }
/** * Create a new {@code DelegatingFilterProxy} that will retrieve the named target * bean from the given Spring {@code WebApplicationContext}. * <p>For use in Servlet 3.0+ environments where instance-based registration of * filters is supported. * <p>The target bean must implement the standard Servlet Filter interface. * <p>The given {@code WebApplicationContext} may or may not be refreshed when passed * in. If it has not, and if the context implements {@link ConfigurableApplicationContext}, * a {@link ConfigurableApplicationContext#refresh() refresh()} will be attempted before * retrieving the named target bean. * <p>This proxy's {@code Environment} will be inherited from the given * {@code WebApplicationContext}. * @param targetBeanName name of the target filter bean in the Spring application * context (must not be {@code null}). * @param wac the application context from which the target filter will be retrieved; * if {@code null}, an application context will be looked up from {@code ServletContext} * as a fallback. * @see #findWebApplicationContext() * @see #setEnvironment(org.springframework.core.env.Environment) */ public DelegatingFilterProxy(String targetBeanName, @Nullable WebApplicationContext wac) { Assert.hasText(targetBeanName, "Target Filter bean name must not be null or empty"); this.setTargetBeanName(targetBeanName); this.webApplicationContext = wac; if (wac != null) { this.setEnvironment(wac.getEnvironment()); } }
@BeforeEach void setup() { webApplicationContext.getEnvironment(); allowQueryString = webApplicationContext.getBean(UaaTokenEndpoint.class).isAllowQueryString(); IdentityZoneHolder.setProvisioning(webApplicationContext.getBean(IdentityZoneProvisioning.class)); }
private void setProperty(String name, String value) { StandardServletEnvironment env = (StandardServletEnvironment) webApplicationContext.getEnvironment(); MockPropertySource mockPropertySource = new MockPropertySource(); mockPropertySource.setProperty(name, value); env.getPropertySources().addLast(mockPropertySource); assertEquals(value, webApplicationContext.getEnvironment().getProperty(name)); }
@BeforeEach void setUp() throws Exception { FilterChainProxy springSecurityFilterChain = webApplicationContext.getBean("springSecurityFilterChain", FilterChainProxy.class); mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext) .addFilter(springSecurityFilterChain) .build(); testClient = new TestClient(mockMvc); String adminToken = testClient.getClientCredentialsOAuthAccessToken("admin", "adminsecret", "clients.read clients.write clients.secret clients.admin uaa.admin"); String clientId = generator.generate().toLowerCase(); String clientSecret = generator.generate().toLowerCase(); String authorities = "scim.read,scim.write,password.write,oauth.approvals,scim.create,uaa.admin"; clientDetails = MockMvcUtils.createClient(mockMvc, adminToken, clientId, clientSecret, Collections.singleton("oauth"), Arrays.asList("openid", "foo", "bar"), Arrays.asList("client_credentials", "password"), authorities); scimReadWriteToken = testClient.getClientCredentialsOAuthAccessToken(clientId, clientSecret, "scim.read scim.write password.write"); scimCreateToken = testClient.getClientCredentialsOAuthAccessToken(clientId, clientSecret, "scim.create"); usersRepository = webApplicationContext.getBean(ScimUserProvisioning.class); identityProviderProvisioning = webApplicationContext.getBean(JdbcIdentityProviderProvisioning.class); codeStore = webApplicationContext.getBean(ExpiringCodeStore.class); mfaCredentialsProvisioning = webApplicationContext.getBean(JdbcUserGoogleMfaCredentialsProvisioning.class); mfaProviderProvisioning = webApplicationContext.getBean(JdbcMfaProviderProvisioning.class); uaaAdminToken = testClient.getClientCredentialsOAuthAccessToken(clientId, clientSecret, "uaa.admin"); usersMaxCount = Integer.parseInt(webApplicationContext.getEnvironment().getProperty("userMaxCount")); }
ServletContext sc = request.getSession().getServletContext(); WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(sc); String[] profiles = applicationContext.getEnvironment().getActiveProfiles();
/** * Autowired constructor * @param streamSerializer Serializer * @param context Context * @param logger Logger */ @Autowired public AweElements(XStreamSerializer streamSerializer, WebApplicationContext context, LogUtil logger) { this.serializer = streamSerializer; this.context = context; this.logger = logger; this.environment = context.getEnvironment(); }
@Override public void contextInitialized(ServletContextEvent sce) { LOGGER.info("Servlet context initialized"); int tpSize = Integer.valueOf(getWebApplicationContext(sce.getServletContext()).getEnvironment() .getProperty("grid.config.jetty.executor.threads.count", "500")); sce.getServletContext().setAttribute("org.eclipse.jetty.server.Executor", newFixedThreadPool(tpSize)); }
private static Environment getEnvironment() { return getApplicationContext().getEnvironment(); }
@PostConstruct public void onInitialize() { this.elements = getBean(AweElements.class); this.environment = context.getEnvironment(); this.logger = getBean(LogUtil.class); }
/** * @param context * * @return */ public static BaseContextConfiguration getContextConfigurationFromContext(WebApplicationContext context) { Map configMap = (Map) ((StandardServletEnvironment) context.getEnvironment()).getPropertySources() .get(ConfigurationConstants.EXECUTION_ENVIRONMENT_KEY).getSource(); return (BaseContextConfiguration) configMap.get(ConfigurationConstants.CONTEXT_CONFIGURATION_KEY); }
/** * @param context * * @return */ public static ServerConfiguration getConfigurationFromContext(WebApplicationContext context) { Map configMap = (Map) ((StandardServletEnvironment) context.getEnvironment()).getPropertySources() .get(ConfigurationConstants.EXECUTION_ENVIRONMENT_KEY).getSource(); return (ServerConfiguration) configMap.get(ConfigurationConstants.SERVER_CONFIGURATION_KEY); }
/** * @param context * * @return */ public static Class<? extends WebServer> getBootstrapClassFromContext(WebApplicationContext context) { Map configMap = (Map) ((StandardServletEnvironment) context.getEnvironment()).getPropertySources() .get(ConfigurationConstants.EXECUTION_ENVIRONMENT_KEY).getSource(); return (Class<? extends WebServer>) configMap.get(ConfigurationConstants.EXECUTION_PROPERTIES_BOOTSTRAP); }
/** * Create a new {@code DelegatingFilterProxy} that will retrieve the named target * bean from the given Spring {@code WebApplicationContext}. * <p>For use in Servlet 3.0+ environments where instance-based registration of * filters is supported. * <p>The target bean must implement the standard Servlet Filter interface. * <p>The given {@code WebApplicationContext} may or may not be refreshed when passed * in. If it has not, and if the context implements {@link ConfigurableApplicationContext}, * a {@link ConfigurableApplicationContext#refresh() refresh()} will be attempted before * retrieving the named target bean. * <p>This proxy's {@code Environment} will be inherited from the given * {@code WebApplicationContext}. * @param targetBeanName name of the target filter bean in the Spring application * context (must not be {@code null}). * @param wac the application context from which the target filter will be retrieved; * if {@code null}, an application context will be looked up from {@code ServletContext} * as a fallback. * @see #findWebApplicationContext() * @see #setEnvironment(org.springframework.core.env.Environment) */ public DelegatingFilterProxy(String targetBeanName, @Nullable WebApplicationContext wac) { Assert.hasText(targetBeanName, "Target Filter bean name must not be null or empty"); this.setTargetBeanName(targetBeanName); this.webApplicationContext = wac; if (wac != null) { this.setEnvironment(wac.getEnvironment()); } }
/** * Create a new {@code DelegatingFilterProxy} that will retrieve the named target * bean from the given Spring {@code WebApplicationContext}. * <p>For use in Servlet 3.0+ environments where instance-based registration of * filters is supported. * <p>The target bean must implement the standard Servlet Filter interface. * <p>The given {@code WebApplicationContext} may or may not be refreshed when passed * in. If it has not, and if the context implements {@link ConfigurableApplicationContext}, * a {@link ConfigurableApplicationContext#refresh() refresh()} will be attempted before * retrieving the named target bean. * <p>This proxy's {@code Environment} will be inherited from the given * {@code WebApplicationContext}. * @param targetBeanName name of the target filter bean in the Spring application * context (must not be {@code null}). * @param wac the application context from which the target filter will be retrieved; * if {@code null}, an application context will be looked up from {@code ServletContext} * as a fallback. * @see #findWebApplicationContext() * @see #setEnvironment(org.springframework.core.env.Environment) */ public DelegatingFilterProxy(String targetBeanName, @Nullable WebApplicationContext wac) { Assert.hasText(targetBeanName, "Target Filter bean name must not be null or empty"); this.setTargetBeanName(targetBeanName); this.webApplicationContext = wac; if (wac != null) { this.setEnvironment(wac.getEnvironment()); } }
if (productId == null) { Environment environment = WebApplicationContextUtils .findWebApplicationContext(req.getServletContext()).getEnvironment(); productId = environment.getProperty(PRODUCT_ID_KEY);
if (productId == null) { Environment environment = WebApplicationContextUtils .findWebApplicationContext(req.getServletContext()).getEnvironment(); productId = environment.getProperty(PRODUCT_ID_KEY);
mockMvc = MockMvcBuilders.webAppContextSetup(configurableApplicationContext) .addFilters(filters.toArray(new Filter[filters.size()])).build(); dataflowPort = configurableApplicationContext.getEnvironment().resolvePlaceholders("${server.port}");