Search in sources :

Example 6 with AnnotationConfigServletWebServerApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project spring-boot by spring-projects.

the class JolokiaAutoConfigurationTests method agentServletWithCustomPath.

@Test
public void agentServletWithCustomPath() throws Exception {
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, "endpoints.jolokia.path=/foo/bar");
    this.context.register(EndpointsConfig.class, WebMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1);
    MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
    mockMvc.perform(MockMvcRequestBuilders.get("/foo/bar")).andExpect(MockMvcResultMatchers.content().string(Matchers.containsString("\"request\":{\"type\"")));
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 7 with AnnotationConfigServletWebServerApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project spring-boot by spring-projects.

the class PublicMetricsAutoConfigurationTests method loadWeb.

private void loadWeb(Class<?>... config) {
    AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
    if (config.length > 0) {
        context.register(config);
    }
    context.register(DataSourcePoolMetadataProvidersConfiguration.class, CacheStatisticsAutoConfiguration.class, PublicMetricsAutoConfiguration.class, MockServletWebServerFactory.class);
    context.refresh();
    this.context = context;
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)

Example 8 with AnnotationConfigServletWebServerApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project spring-boot by spring-projects.

the class OAuth2AutoConfigurationTests method testResourceServerOverride.

@Test
public void testResourceServerOverride() {
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    this.context.register(AuthorizationAndResourceServerConfiguration.class, CustomResourceServer.class, MinimalSecureWebApplication.class);
    this.context.refresh();
    ClientDetails config = this.context.getBean(ClientDetails.class);
    assertThat(countBeans(AUTHORIZATION_SERVER_CONFIG)).isEqualTo(1);
    assertThat(countBeans(CustomResourceServer.class)).isEqualTo(1);
    assertThat(countBeans(RESOURCE_SERVER_CONFIG)).isEqualTo(1);
    verifyAuthentication(config);
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) Test(org.junit.Test)

Example 9 with AnnotationConfigServletWebServerApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project spring-boot by spring-projects.

the class OAuth2AutoConfigurationTests method resourceServerConditionWhenJwkConfigurationPresentShouldMatch.

@Test
public void resourceServerConditionWhenJwkConfigurationPresentShouldMatch() throws Exception {
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, "security.oauth2.resource.jwk.key-set-uri:http://my-auth-server/token_keys");
    this.context.register(ResourceServerConfiguration.class, MinimalSecureWebApplication.class);
    this.context.refresh();
    assertThat(countBeans(RESOURCE_SERVER_CONFIG)).isEqualTo(1);
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) Test(org.junit.Test)

Example 10 with AnnotationConfigServletWebServerApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project spring-boot by spring-projects.

the class OAuth2AutoConfigurationTests method testCanUseClientCredentialsWithEnableOAuth2Client.

@Test
public void testCanUseClientCredentialsWithEnableOAuth2Client() {
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    this.context.register(ClientConfiguration.class, MinimalSecureWebApplication.class);
    EnvironmentTestUtils.addEnvironment(this.context, "security.oauth2.client.clientId=client", "security.oauth2.client.grantType=client_credentials");
    this.context.refresh();
    // The primary context is fine (not session scoped):
    OAuth2ClientContext bean = this.context.getBean(OAuth2ClientContext.class);
    assertThat(bean.getAccessTokenRequest()).isNotNull();
    assertThat(countBeans(ClientCredentialsResourceDetails.class)).isEqualTo(1);
    // Kind of a bug (should ideally be 1), but the cause is in Spring OAuth2 (there
    // is no need for the extra session-scoped bean). What this test proves is that
    // even if the user screws up and does @EnableOAuth2Client for client credentials,
    // it will still just about work (because of the @Primary annotation on the
    // Boot-created instance of OAuth2ClientContext).
    assertThat(countBeans(OAuth2ClientContext.class)).isEqualTo(2);
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) OAuth2ClientContext(org.springframework.security.oauth2.client.OAuth2ClientContext) Test(org.junit.Test)

Aggregations

AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)52 Test (org.junit.Test)41 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)8 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)7 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)6 Jsr250MethodSecurityMetadataSource (org.springframework.security.access.annotation.Jsr250MethodSecurityMetadataSource)4 DelegatingMethodSecurityMetadataSource (org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource)4 MethodSecurityMetadataSource (org.springframework.security.access.method.MethodSecurityMetadataSource)4 ServerPortInfoApplicationContextInitializer (org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer)3 ServletContextEvent (javax.servlet.ServletContextEvent)2 ServletContextListener (javax.servlet.ServletContextListener)2 MethodSecurityExpressionHandler (org.springframework.security.access.expression.method.MethodSecurityExpressionHandler)2 PreInvocationAuthorizationAdvice (org.springframework.security.access.prepost.PreInvocationAuthorizationAdvice)2 PrePostAnnotationSecurityMetadataSource (org.springframework.security.access.prepost.PrePostAnnotationSecurityMetadataSource)2 OAuth2ClientContext (org.springframework.security.oauth2.client.OAuth2ClientContext)2 OAuth2MethodSecurityExpressionHandler (org.springframework.security.oauth2.provider.expression.OAuth2MethodSecurityExpressionHandler)2 RestTemplate (org.springframework.web.client.RestTemplate)2 StandardServletMultipartResolver (org.springframework.web.multipart.support.StandardServletMultipartResolver)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1