Search in sources :

Example 71 with GenericWebApplicationContext

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

the class OAuth2ResourceServerSpecTests method autowireWebServerGenericWebApplicationContext.

private GenericWebApplicationContext autowireWebServerGenericWebApplicationContext() {
    GenericWebApplicationContext context = new GenericWebApplicationContext();
    context.registerBean("webHandler", DispatcherHandler.class);
    this.spring.context(context).autowire();
    return (GenericWebApplicationContext) this.spring.getContext();
}
Also used : GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext)

Example 72 with GenericWebApplicationContext

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

the class OAuth2ResourceServerSpecTests method getJwtAuthenticationConverterWhenTwoBeansWiredThenThrowsWiringException.

@Test
public void getJwtAuthenticationConverterWhenTwoBeansWiredThenThrowsWiringException() {
    GenericWebApplicationContext context = autowireWebServerGenericWebApplicationContext();
    ServerHttpSecurity http = new ServerHttpSecurity();
    http.setApplicationContext(context);
    ReactiveJwtAuthenticationConverter beanWiredJwtAuthenticationConverter = new ReactiveJwtAuthenticationConverter();
    context.registerBean("firstJwtAuthenticationConverter", ReactiveJwtAuthenticationConverter.class, () -> beanWiredJwtAuthenticationConverter);
    context.registerBean("secondJwtAuthenticationConverter", ReactiveJwtAuthenticationConverter.class, () -> beanWiredJwtAuthenticationConverter);
    ServerHttpSecurity.OAuth2ResourceServerSpec.JwtSpec jwt = http.oauth2ResourceServer().jwt();
    assertThatExceptionOfType(NoUniqueBeanDefinitionException.class).isThrownBy(jwt::getJwtAuthenticationConverter);
}
Also used : ReactiveJwtAuthenticationConverter(org.springframework.security.oauth2.server.resource.authentication.ReactiveJwtAuthenticationConverter) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) NoUniqueBeanDefinitionException(org.springframework.beans.factory.NoUniqueBeanDefinitionException) Test(org.junit.jupiter.api.Test)

Example 73 with GenericWebApplicationContext

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

the class OAuth2ResourceServerSpecTests method getJwtDecoderWhenBeanWiredAndDslWiredThenDslTakesPrecedence.

@Test
public void getJwtDecoderWhenBeanWiredAndDslWiredThenDslTakesPrecedence() {
    GenericWebApplicationContext context = autowireWebServerGenericWebApplicationContext();
    ServerHttpSecurity http = new ServerHttpSecurity();
    http.setApplicationContext(context);
    ReactiveJwtDecoder beanWiredJwtDecoder = mock(ReactiveJwtDecoder.class);
    ReactiveJwtDecoder dslWiredJwtDecoder = mock(ReactiveJwtDecoder.class);
    context.registerBean(ReactiveJwtDecoder.class, () -> beanWiredJwtDecoder);
    ServerHttpSecurity.OAuth2ResourceServerSpec.JwtSpec jwt = http.oauth2ResourceServer().jwt();
    jwt.jwtDecoder(dslWiredJwtDecoder);
    assertThat(jwt.getJwtDecoder()).isEqualTo(dslWiredJwtDecoder);
}
Also used : ReactiveJwtDecoder(org.springframework.security.oauth2.jwt.ReactiveJwtDecoder) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) Test(org.junit.jupiter.api.Test)

Example 74 with GenericWebApplicationContext

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

the class OAuth2ResourceServerConfigurerTests method getBearerTokenResolverWhenDuplicateResolverBeansAndAnotherOnTheDslThenTheDslOneIsUsed.

@Test
public void getBearerTokenResolverWhenDuplicateResolverBeansAndAnotherOnTheDslThenTheDslOneIsUsed() {
    BearerTokenResolver resolverBean = mock(BearerTokenResolver.class);
    BearerTokenResolver resolver = mock(BearerTokenResolver.class);
    GenericWebApplicationContext context = new GenericWebApplicationContext();
    context.registerBean("resolverOne", BearerTokenResolver.class, () -> resolverBean);
    context.registerBean("resolverTwo", 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 75 with GenericWebApplicationContext

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

the class OAuth2ResourceServerConfigurerTests method getJwtAuthenticationConverterWhenDuplicateConverterBeansAndAnotherOnTheDslThenTheDslOneIsUsed.

@Test
public void getJwtAuthenticationConverterWhenDuplicateConverterBeansAndAnotherOnTheDslThenTheDslOneIsUsed() {
    JwtAuthenticationConverter converter = new JwtAuthenticationConverter();
    JwtAuthenticationConverter converterBean = new JwtAuthenticationConverter();
    GenericWebApplicationContext context = new GenericWebApplicationContext();
    context.registerBean("converterOne", JwtAuthenticationConverter.class, () -> converterBean);
    context.registerBean("converterTwo", 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)

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