Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void init(AuthenticationManagerBuilder auth) {

class InitializeUserDetailsManagerConfigurer extends GlobalAuthenticationConfigurerAdapter {

private final Log logger = LogFactory.getLog(getClass());
private final Log logger = LogFactory.getLog(InitializeUserDetailsBeanManagerConfigurer.class);

@Override
public void configure(AuthenticationManagerBuilder auth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

package org.springframework.security.config.annotation.authentication.configuration;

import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -266,6 +271,31 @@ public void getAuthenticationWhenAuthenticationProviderAndUserDetailsBeanThenAut
am.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "password"));
}

@Test
public void getAuthenticationWhenAuthenticationProviderAndUserDetailsBeanThenWarningUsesConfigurerLogger()
throws Exception {
Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
ListAppender<ILoggingEvent> appender = new ListAppender<>();
appender.start();
rootLogger.addAppender(appender);

try {
this.spring.register(AuthenticationProviderBeanAndUserDetailsServiceConfig.class).autowire();

this.spring.getContext().getBean(AuthenticationConfiguration.class).getAuthenticationManager();

assertThat(appender.list)
.filteredOn(
(event) -> event.getFormattedMessage().contains("UserDetailsService beans will not be used"))
.extracting(ILoggingEvent::getLoggerName)
.containsExactly(InitializeUserDetailsBeanManagerConfigurer.class.getName());
}
finally {
rootLogger.detachAppender(appender);
appender.stop();
}
}

// gh-3091
@Test
public void getAuthenticationWhenAuthenticationProviderBeanThenUsed() throws Exception {
Expand Down