diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/BootGlobalAuthenticationConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/BootGlobalAuthenticationConfiguration.java index a0568568101..933b64fdd3b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/BootGlobalAuthenticationConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/BootGlobalAuthenticationConfiguration.java @@ -20,6 +20,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; @@ -29,7 +30,8 @@ import org.springframework.security.config.annotation.authentication.configurati import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter; /** - * This works with the {@link AuthenticationConfiguration} to ensure that users are able to use: + * This works with the {@link AuthenticationConfiguration} to ensure that users are able + * to use: * *
  * public void configureGlobal(AuthenticationManagerBuilder auth) {
@@ -37,22 +39,27 @@ import org.springframework.security.config.annotation.authentication.configurers
  * }
  * 
* - * within their classes annotated with {{@EnableAutoConfiguration}} or use {{@SpringBootApplication}}. + * within their classes annotated with {@link EnableAutoConfiguration} or + * {@link SpringBootApplication}. * * @author Rob Winch + * @since 1.2.2 */ @Configuration @ConditionalOnClass(GlobalAuthenticationConfigurerAdapter.class) public class BootGlobalAuthenticationConfiguration { @Bean - public static BootGlobalAuthenticationConfigurationAdapter bootGlobalAuthenticationConfigurationAdapter(ApplicationContext context) { + public static BootGlobalAuthenticationConfigurationAdapter bootGlobalAuthenticationConfigurationAdapter( + ApplicationContext context) { return new BootGlobalAuthenticationConfigurationAdapter(context); } - private static class BootGlobalAuthenticationConfigurationAdapter extends GlobalAuthenticationConfigurerAdapter { + private static class BootGlobalAuthenticationConfigurationAdapter extends + GlobalAuthenticationConfigurerAdapter { private final ApplicationContext context; - private static final Log logger = LogFactory.getLog(BootGlobalAuthenticationConfiguration.class); + private static final Log logger = LogFactory + .getLog(BootGlobalAuthenticationConfiguration.class); public BootGlobalAuthenticationConfigurationAdapter(ApplicationContext context) { this.context = context; @@ -60,8 +67,9 @@ public class BootGlobalAuthenticationConfiguration { @Override public void init(AuthenticationManagerBuilder auth) { - Map beansWithAnnotation = context.getBeansWithAnnotation(EnableAutoConfiguration.class); - if(logger.isDebugEnabled()) { + Map beansWithAnnotation = this.context + .getBeansWithAnnotation(EnableAutoConfiguration.class); + if (logger.isDebugEnabled()) { logger.debug("Eagerly initializing " + beansWithAnnotation); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java index 71913f28067..b30ed98fa32 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java @@ -50,7 +50,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur @EnableConfigurationProperties @Import({ SpringBootWebSecurityConfiguration.class, AuthenticationManagerConfiguration.class, - BootGlobalAuthenticationConfiguration.class}) + BootGlobalAuthenticationConfiguration.class }) public class SecurityAutoConfiguration { @Bean diff --git a/spring-boot-security-tests/spring-boot-security-tests-web-helloworld/pom.xml b/spring-boot-security-tests/spring-boot-security-tests-web-helloworld/pom.xml index 591d762a0c1..416d29c5f5f 100644 --- a/spring-boot-security-tests/spring-boot-security-tests-web-helloworld/pom.xml +++ b/spring-boot-security-tests/spring-boot-security-tests-web-helloworld/pom.xml @@ -15,6 +15,9 @@ Pivotal Software, Inc. http://www.spring.io + + ${basedir}/../.. + org.springframework.boot diff --git a/spring-boot-security-tests/spring-boot-security-tests-web-helloworld/src/main/java/sample/HelloWebSecurityApplication.java b/spring-boot-security-tests/spring-boot-security-tests-web-helloworld/src/main/java/sample/HelloWebSecurityApplication.java index dacf1ea7629..7a2a784cad6 100644 --- a/spring-boot-security-tests/spring-boot-security-tests-web-helloworld/src/main/java/sample/HelloWebSecurityApplication.java +++ b/spring-boot-security-tests/spring-boot-security-tests-web-helloworld/src/main/java/sample/HelloWebSecurityApplication.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package sample; import org.springframework.beans.factory.annotation.Autowired; @@ -24,13 +25,8 @@ import org.springframework.security.config.annotation.authentication.builders.Au public class HelloWebSecurityApplication { @Autowired - public void configureGlobal(AuthenticationManagerBuilder auth) - throws Exception { - // @formatter:off - auth - .inMemoryAuthentication() - .withUser("user").password("password").roles("USER"); - // @formatter:on + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + auth.inMemoryAuthentication().withUser("user").password("password").roles("USER"); } public static void main(String[] args) { diff --git a/spring-boot-security-tests/spring-boot-security-tests-web-helloworld/src/test/java/sample/HelloWebSecurityApplicationTests.java b/spring-boot-security-tests/spring-boot-security-tests-web-helloworld/src/test/java/sample/HelloWebSecurityApplicationTests.java index 284c809f5cf..36eebd24ed6 100644 --- a/spring-boot-security-tests/spring-boot-security-tests-web-helloworld/src/test/java/sample/HelloWebSecurityApplicationTests.java +++ b/spring-boot-security-tests/spring-boot-security-tests-web-helloworld/src/test/java/sample/HelloWebSecurityApplicationTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package sample; import javax.servlet.http.HttpServletResponse; @@ -30,43 +31,45 @@ import org.springframework.security.crypto.codec.Base64; import org.springframework.security.web.FilterChainProxy; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = HelloWebSecurityApplication.class) @WebIntegrationTest(randomPort = true) public class HelloWebSecurityApplicationTests { + @Autowired - FilterChainProxy springSecurityFilterChain; + private FilterChainProxy springSecurityFilterChain; - MockHttpServletRequest request; + private MockHttpServletRequest request; - MockHttpServletResponse response; + private MockHttpServletResponse response; - MockFilterChain chain; + private MockFilterChain chain; @Before public void setup() { - request = new MockHttpServletRequest(); - response = new MockHttpServletResponse(); - chain = new MockFilterChain(); + this.request = new MockHttpServletRequest(); + this.response = new MockHttpServletResponse(); + this.chain = new MockFilterChain(); } @Test public void requiresAuthentication() throws Exception { - springSecurityFilterChain.doFilter(request, response, chain); + this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain); - assertThat(response.getStatus(), equalTo(HttpServletResponse.SC_UNAUTHORIZED)); + assertThat(this.response.getStatus(), + equalTo(HttpServletResponse.SC_UNAUTHORIZED)); } - @Test public void userAuthenticates() throws Exception { - request.addHeader("Authorization", "Basic " + new String(Base64.encode("user:password".getBytes("UTF-8")))); + this.request.addHeader("Authorization", + "Basic " + new String(Base64.encode("user:password".getBytes("UTF-8")))); - springSecurityFilterChain.doFilter(request, response, chain); + this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain); - assertThat(response.getStatus(), equalTo(HttpServletResponse.SC_OK)); + assertThat(this.response.getStatus(), equalTo(HttpServletResponse.SC_OK)); } }