Commit 64e94f3b authored by Andy Wilkinson's avatar Andy Wilkinson

Correct javadoc syntax and apply code formatting

parent 9d0e50c6
...@@ -20,6 +20,7 @@ import java.util.Map; ...@@ -20,6 +20,7 @@ import java.util.Map;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -29,7 +30,8 @@ import org.springframework.security.config.annotation.authentication.configurati ...@@ -29,7 +30,8 @@ import org.springframework.security.config.annotation.authentication.configurati
import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter; 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:
* *
* <pre> * <pre>
* public void configureGlobal(AuthenticationManagerBuilder auth) { * public void configureGlobal(AuthenticationManagerBuilder auth) {
...@@ -37,22 +39,27 @@ import org.springframework.security.config.annotation.authentication.configurers ...@@ -37,22 +39,27 @@ import org.springframework.security.config.annotation.authentication.configurers
* } * }
* </pre> * </pre>
* *
* within their classes annotated with {{@EnableAutoConfiguration}} or use {{@SpringBootApplication}}. * within their classes annotated with {@link EnableAutoConfiguration} or
* {@link SpringBootApplication}.
* *
* @author Rob Winch * @author Rob Winch
* @since 1.2.2
*/ */
@Configuration @Configuration
@ConditionalOnClass(GlobalAuthenticationConfigurerAdapter.class) @ConditionalOnClass(GlobalAuthenticationConfigurerAdapter.class)
public class BootGlobalAuthenticationConfiguration { public class BootGlobalAuthenticationConfiguration {
@Bean @Bean
public static BootGlobalAuthenticationConfigurationAdapter bootGlobalAuthenticationConfigurationAdapter(ApplicationContext context) { public static BootGlobalAuthenticationConfigurationAdapter bootGlobalAuthenticationConfigurationAdapter(
ApplicationContext context) {
return new BootGlobalAuthenticationConfigurationAdapter(context); return new BootGlobalAuthenticationConfigurationAdapter(context);
} }
private static class BootGlobalAuthenticationConfigurationAdapter extends GlobalAuthenticationConfigurerAdapter { private static class BootGlobalAuthenticationConfigurationAdapter extends
GlobalAuthenticationConfigurerAdapter {
private final ApplicationContext context; 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) { public BootGlobalAuthenticationConfigurationAdapter(ApplicationContext context) {
this.context = context; this.context = context;
...@@ -60,8 +67,9 @@ public class BootGlobalAuthenticationConfiguration { ...@@ -60,8 +67,9 @@ public class BootGlobalAuthenticationConfiguration {
@Override @Override
public void init(AuthenticationManagerBuilder auth) { public void init(AuthenticationManagerBuilder auth) {
Map<String, Object> beansWithAnnotation = context.getBeansWithAnnotation(EnableAutoConfiguration.class); Map<String, Object> beansWithAnnotation = this.context
if(logger.isDebugEnabled()) { .getBeansWithAnnotation(EnableAutoConfiguration.class);
if (logger.isDebugEnabled()) {
logger.debug("Eagerly initializing " + beansWithAnnotation); logger.debug("Eagerly initializing " + beansWithAnnotation);
} }
} }
......
...@@ -50,7 +50,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur ...@@ -50,7 +50,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
@EnableConfigurationProperties @EnableConfigurationProperties
@Import({ SpringBootWebSecurityConfiguration.class, @Import({ SpringBootWebSecurityConfiguration.class,
AuthenticationManagerConfiguration.class, AuthenticationManagerConfiguration.class,
BootGlobalAuthenticationConfiguration.class}) BootGlobalAuthenticationConfiguration.class })
public class SecurityAutoConfiguration { public class SecurityAutoConfiguration {
@Bean @Bean
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
<name>Pivotal Software, Inc.</name> <name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url> <url>http://www.spring.io</url>
</organization> </organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package sample; package sample;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -24,13 +25,8 @@ import org.springframework.security.config.annotation.authentication.builders.Au ...@@ -24,13 +25,8 @@ import org.springframework.security.config.annotation.authentication.builders.Au
public class HelloWebSecurityApplication { public class HelloWebSecurityApplication {
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
throws Exception { auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
// @formatter:on
} }
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package sample; package sample;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -30,43 +31,45 @@ import org.springframework.security.crypto.codec.Base64; ...@@ -30,43 +31,45 @@ import org.springframework.security.crypto.codec.Base64;
import org.springframework.security.web.FilterChainProxy; import org.springframework.security.web.FilterChainProxy;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = HelloWebSecurityApplication.class) @SpringApplicationConfiguration(classes = HelloWebSecurityApplication.class)
@WebIntegrationTest(randomPort = true) @WebIntegrationTest(randomPort = true)
public class HelloWebSecurityApplicationTests { public class HelloWebSecurityApplicationTests {
@Autowired @Autowired
FilterChainProxy springSecurityFilterChain; private FilterChainProxy springSecurityFilterChain;
MockHttpServletRequest request; private MockHttpServletRequest request;
MockHttpServletResponse response; private MockHttpServletResponse response;
MockFilterChain chain; private MockFilterChain chain;
@Before @Before
public void setup() { public void setup() {
request = new MockHttpServletRequest(); this.request = new MockHttpServletRequest();
response = new MockHttpServletResponse(); this.response = new MockHttpServletResponse();
chain = new MockFilterChain(); this.chain = new MockFilterChain();
} }
@Test @Test
public void requiresAuthentication() throws Exception { 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 @Test
public void userAuthenticates() throws Exception { 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));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment