Search in sources :

Example 26 with GenericWebApplicationContext

use of org.springframework.web.context.support.GenericWebApplicationContext in project spring-security by spring-projects.

the class OAuth2ResourceServerConfigurerTests method getJwtAuthenticationConverterWhenConverterBeanSpecified.

@Test
public void getJwtAuthenticationConverterWhenConverterBeanSpecified() {
    JwtAuthenticationConverter converterBean = new JwtAuthenticationConverter();
    GenericWebApplicationContext context = new GenericWebApplicationContext();
    context.registerBean(JwtAuthenticationConverter.class, () -> converterBean);
    this.spring.context(context).autowire();
    OAuth2ResourceServerConfigurer.JwtConfigurer jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
    assertThat(jwtConfigurer.getJwtAuthenticationConverter()).isEqualTo(converterBean);
}
Also used : JwtAuthenticationConverter(org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) Test(org.junit.jupiter.api.Test)

Example 27 with GenericWebApplicationContext

use of org.springframework.web.context.support.GenericWebApplicationContext in project spring-security by spring-projects.

the class OAuth2ResourceServerConfigurerTests method getJwtAuthenticationConverterWhenConverterBeanAndAnotherOnTheDslThenTheDslOneIsUsed.

@Test
public void getJwtAuthenticationConverterWhenConverterBeanAndAnotherOnTheDslThenTheDslOneIsUsed() {
    JwtAuthenticationConverter converter = new JwtAuthenticationConverter();
    JwtAuthenticationConverter converterBean = new JwtAuthenticationConverter();
    GenericWebApplicationContext context = new GenericWebApplicationContext();
    context.registerBean(JwtAuthenticationConverter.class, () -> converterBean);
    this.spring.context(context).autowire();
    OAuth2ResourceServerConfigurer.JwtConfigurer jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
    jwtConfigurer.jwtAuthenticationConverter(converter);
    assertThat(jwtConfigurer.getJwtAuthenticationConverter()).isEqualTo(converter);
}
Also used : JwtAuthenticationConverter(org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) Test(org.junit.jupiter.api.Test)

Example 28 with GenericWebApplicationContext

use of org.springframework.web.context.support.GenericWebApplicationContext in project spring-security by spring-projects.

the class OAuth2ResourceServerConfigurerTests method getJwtDecoderWhenTwoJwtDecoderBeansAndAnotherWiredOnDslThenDslWiredOneTakesPrecedence.

@Test
public void getJwtDecoderWhenTwoJwtDecoderBeansAndAnotherWiredOnDslThenDslWiredOneTakesPrecedence() {
    JwtDecoder decoderBean = mock(JwtDecoder.class);
    JwtDecoder decoder = mock(JwtDecoder.class);
    GenericWebApplicationContext context = new GenericWebApplicationContext();
    context.registerBean("decoderOne", JwtDecoder.class, () -> decoderBean);
    context.registerBean("decoderTwo", JwtDecoder.class, () -> decoderBean);
    this.spring.context(context).autowire();
    OAuth2ResourceServerConfigurer.JwtConfigurer jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
    jwtConfigurer.decoder(decoder);
    assertThat(jwtConfigurer.getJwtDecoder()).isEqualTo(decoder);
}
Also used : NimbusJwtDecoder(org.springframework.security.oauth2.jwt.NimbusJwtDecoder) JwtDecoder(org.springframework.security.oauth2.jwt.JwtDecoder) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) Test(org.junit.jupiter.api.Test)

Example 29 with GenericWebApplicationContext

use of org.springframework.web.context.support.GenericWebApplicationContext in project spring-security by spring-projects.

the class OAuth2ResourceServerConfigurerTests method getBearerTokenResolverWhenResolverBeanAndAnotherOnTheDslThenTheDslOneIsUsed.

@Test
public void getBearerTokenResolverWhenResolverBeanAndAnotherOnTheDslThenTheDslOneIsUsed() {
    BearerTokenResolver resolver = mock(BearerTokenResolver.class);
    BearerTokenResolver resolverBean = mock(BearerTokenResolver.class);
    GenericWebApplicationContext context = new GenericWebApplicationContext();
    context.registerBean(BearerTokenResolver.class, () -> resolverBean);
    this.spring.context(context).autowire();
    OAuth2ResourceServerConfigurer oauth2 = new OAuth2ResourceServerConfigurer(context);
    oauth2.bearerTokenResolver(resolver);
    assertThat(oauth2.getBearerTokenResolver()).isEqualTo(resolver);
}
Also used : GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) DefaultBearerTokenResolver(org.springframework.security.oauth2.server.resource.web.DefaultBearerTokenResolver) BearerTokenResolver(org.springframework.security.oauth2.server.resource.web.BearerTokenResolver) Test(org.junit.jupiter.api.Test)

Example 30 with GenericWebApplicationContext

use of org.springframework.web.context.support.GenericWebApplicationContext in project spring-framework by spring-projects.

the class DelegatingWebMvcConfigurationIntegrationTests method load.

private void load(Consumer<GenericWebApplicationContext> context) {
    GenericWebApplicationContext webContext = new GenericWebApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(webContext);
    webContext.setServletContext(new MockServletContext());
    context.accept(webContext);
    webContext.registerBean(DelegatingWebMvcConfiguration.class);
    webContext.refresh();
    this.context = webContext;
}
Also used : GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext)

Aggregations

GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)93 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)33 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)32 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)31 Test (org.junit.Test)30 Test (org.junit.jupiter.api.Test)30 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)9 MockServletContext (org.springframework.mock.web.MockServletContext)8 BeforeEach (org.junit.jupiter.api.BeforeEach)6 DefaultAdvisorAutoProxyCreator (org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator)6 ApplicationContext (org.springframework.context.ApplicationContext)6 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)6 WebApplicationContext (org.springframework.web.context.WebApplicationContext)6 Method (java.lang.reflect.Method)5 HttpSession (javax.servlet.http.HttpSession)5 SimpleTraceInterceptor (org.springframework.aop.interceptor.SimpleTraceInterceptor)5 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)5 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4