001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.docs.web.security; 018 019import org.springframework.context.annotation.Configuration; 020import org.springframework.security.config.annotation.web.builders.HttpSecurity; 021import org.springframework.security.config.annotation.web.builders.WebSecurity; 022import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 023 024/** 025 * Example configuration for using a {@link WebSecurityConfigurerAdapter} to configure 026 * unauthenticated access to the home page at "/". 027 * 028 * @author Robert Stern 029 */ 030public class UnauthenticatedAccessExample { 031 032 /** 033 * {@link WebSecurityConfigurerAdapter} that provides init to configure 034 * {@link WebSecurity} argument to customize access rules. 035 */ 036 // tag::configuration[] 037 @Configuration 038 static class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { 039 040 @Override 041 public void init(WebSecurity web) { 042 web.ignoring().antMatchers("/"); 043 } 044 045 @Override 046 protected void configure(HttpSecurity http) throws Exception { 047 http.antMatcher("/**").authorizeRequests().anyRequest().authenticated(); 048 } 049 050 } 051 // end::configuration[] 052 053}