Correct javadoc syntax and apply code formatting

This commit is contained in:
Andy Wilkinson 2015-02-18 16:51:45 +00:00
parent 9d0e50c6ac
commit 64e94f3b1b
5 changed files with 39 additions and 29 deletions

View File

@ -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:
*
* <pre>
* public void configureGlobal(AuthenticationManagerBuilder auth) {
@ -37,22 +39,27 @@ import org.springframework.security.config.annotation.authentication.configurers
* }
* </pre>
*
* 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<String, Object> beansWithAnnotation = context.getBeansWithAnnotation(EnableAutoConfiguration.class);
if(logger.isDebugEnabled()) {
Map<String, Object> beansWithAnnotation = this.context
.getBeansWithAnnotation(EnableAutoConfiguration.class);
if (logger.isDebugEnabled()) {
logger.debug("Eagerly initializing " + beansWithAnnotation);
}
}

View File

@ -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

View File

@ -15,6 +15,9 @@
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -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) {

View File

@ -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));
}
}