|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright 2002-2016 the original author or authors.
|
|
|
|
|
|
+ * Copyright 2002-2019 the original author or authors.
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -17,26 +17,30 @@ package org.springframework.security.config.annotation.authentication.configurat
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
|
|
|
+import org.junit.Rule;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
-import org.junit.runner.RunWith;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
|
|
|
+import org.springframework.security.config.test.SpringTestRule;
|
|
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
* @author Rob Winch
|
|
* @author Rob Winch
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-@RunWith(SpringJUnit4ClassRunner.class)
|
|
|
|
public class EnableGlobalAuthenticationTests {
|
|
public class EnableGlobalAuthenticationTests {
|
|
- @Autowired
|
|
|
|
- AuthenticationConfiguration auth;
|
|
|
|
|
|
+ @Rule
|
|
|
|
+ public final SpringTestRule spring = new SpringTestRule();
|
|
|
|
|
|
// gh-4086
|
|
// gh-4086
|
|
@Test
|
|
@Test
|
|
public void authenticationConfigurationWhenGetAuthenticationManagerThenNotNull() throws Exception {
|
|
public void authenticationConfigurationWhenGetAuthenticationManagerThenNotNull() throws Exception {
|
|
|
|
+ this.spring.register(Config.class).autowire();
|
|
|
|
+
|
|
|
|
+ AuthenticationConfiguration auth = spring.getContext().getBean(AuthenticationConfiguration.class);
|
|
|
|
+
|
|
assertThat(auth.getAuthenticationManager()).isNotNull();
|
|
assertThat(auth.getAuthenticationManager()).isNotNull();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -50,4 +54,67 @@ public class EnableGlobalAuthenticationTests {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void enableGlobalAuthenticationWhenNoConfigurationAnnotationThenBeanProxyingEnabled() {
|
|
|
|
+ this.spring.register(BeanProxyEnabledByDefaultConfig.class).autowire();
|
|
|
|
+
|
|
|
|
+ Child childBean = this.spring.getContext().getBean(Child.class);
|
|
|
|
+ Parent parentBean = this.spring.getContext().getBean(Parent.class);
|
|
|
|
+
|
|
|
|
+ assertThat(parentBean.getChild()).isSameAs(childBean);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @EnableGlobalAuthentication
|
|
|
|
+ static class BeanProxyEnabledByDefaultConfig {
|
|
|
|
+ @Bean
|
|
|
|
+ public Child child() {
|
|
|
|
+ return new Child();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Bean
|
|
|
|
+ public Parent parent() {
|
|
|
|
+ return new Parent(child());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void enableGlobalAuthenticationWhenProxyBeanMethodsFalseThenBeanProxyingDisabled() {
|
|
|
|
+ this.spring.register(BeanProxyDisabledConfig.class).autowire();
|
|
|
|
+
|
|
|
|
+ Child childBean = this.spring.getContext().getBean(Child.class);
|
|
|
|
+ Parent parentBean = this.spring.getContext().getBean(Parent.class);
|
|
|
|
+
|
|
|
|
+ assertThat(parentBean.getChild()).isNotSameAs(childBean);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Configuration(proxyBeanMethods = false)
|
|
|
|
+ @EnableGlobalAuthentication
|
|
|
|
+ static class BeanProxyDisabledConfig {
|
|
|
|
+ @Bean
|
|
|
|
+ public Child child() {
|
|
|
|
+ return new Child();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Bean
|
|
|
|
+ public Parent parent() {
|
|
|
|
+ return new Parent(child());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static class Parent {
|
|
|
|
+ private Child child;
|
|
|
|
+
|
|
|
|
+ Parent(Child child) {
|
|
|
|
+ this.child = child;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Child getChild() {
|
|
|
|
+ return child;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static class Child {
|
|
|
|
+ Child() {
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|