Skip to content

Commit

Permalink
fixing UserDetailsServiceImpl circular dependency injection
Browse files Browse the repository at this point in the history
re-adding @primary annotation in UserDetailsServiceImpl
  • Loading branch information
hylstonnb authored and aurambaj committed Aug 2, 2023
1 parent c5fbb92 commit 92fadd6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import com.box.l10n.mojito.service.security.user.UserRepository;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/** @author wyau */
@Primary
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

/** logger */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.HttpStatus;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer;
Expand Down Expand Up @@ -63,6 +61,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired UserService userService;

@Autowired UserDetailsServiceImpl userDetailsService;

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
for (SecurityConfig.AuthenticationType authenticationType :
Expand Down Expand Up @@ -99,7 +99,7 @@ void configureActiveDirectory(AuthenticationManagerBuilder auth) throws Exceptio

void configureDatabase(AuthenticationManagerBuilder auth) throws Exception {
logger.debug("Configuring in database authentication");
auth.userDetailsService(getUserDetailsService()).passwordEncoder(new BCryptPasswordEncoder());
auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());
}

void configureLdap(AuthenticationManagerBuilder auth) throws Exception {
Expand Down Expand Up @@ -248,10 +248,4 @@ String[] getHeathcheckPatterns() {
}
return patterns.toArray(new String[patterns.size()]);
}

@Primary
@Bean
protected UserDetailsServiceImpl getUserDetailsService() {
return new UserDetailsServiceImpl();
}
}

0 comments on commit 92fadd6

Please sign in to comment.