001/* 002 * Copyright 2012-2016 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.autoconfigure.security; 018 019import org.springframework.boot.autoconfigure.AutoConfigureAfter; 020import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 021import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 022import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 023import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 024import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 025import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 026import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration; 027import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 028 029/** 030 * If the user explicitly disables the basic security features and forgets to 031 * {@code @EnableWebSecurity}, and yet still wants a bean of type 032 * WebSecurityConfigurerAdapter, he is trying to use a custom security setup. The app 033 * would fail in a confusing way without this shim configuration, which just helpfully 034 * defines an empty {@code @EnableWebSecurity}. 035 * 036 * @author Dave Syer 037 */ 038@ConditionalOnProperty(prefix = "security.basic", name = "enabled", havingValue = "false") 039@ConditionalOnBean(WebSecurityConfigurerAdapter.class) 040@ConditionalOnClass(EnableWebSecurity.class) 041@ConditionalOnMissingBean(WebSecurityConfiguration.class) 042@ConditionalOnWebApplication 043@AutoConfigureAfter(SecurityAutoConfiguration.class) 044@EnableWebSecurity 045public class FallbackWebSecurityAutoConfiguration { 046 047}