2222
2323import eu .openanalytics .containerproxy .auth .IAuthenticationBackend ;
2424import eu .openanalytics .containerproxy .util .EnvironmentUtils ;
25+ import org .slf4j .Logger ;
26+ import org .slf4j .LoggerFactory ;
2527import org .springframework .core .env .Environment ;
2628import org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
2729import org .springframework .security .config .annotation .authentication .configurers .provisioning .InMemoryUserDetailsManagerConfigurer ;
2830import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
2931
3032import javax .inject .Inject ;
33+ import java .util .HashSet ;
3134import java .util .List ;
35+ import java .util .Set ;
3236
3337/**
3438 * Simple authentication method where user/password combinations are
@@ -40,6 +44,7 @@ public class SimpleAuthenticationBackend implements IAuthenticationBackend {
4044
4145 @ Inject
4246 private Environment environment ;
47+ private final Logger logger = LoggerFactory .getLogger (getClass ());
4348
4449 @ Override
4550 public String getName () {
@@ -59,13 +64,19 @@ public void configureHttpSecurity(HttpSecurity http) {
5964 @ Override
6065 public void configureAuthenticationManagerBuilder (AuthenticationManagerBuilder auth ) throws Exception {
6166 InMemoryUserDetailsManagerConfigurer <AuthenticationManagerBuilder > userDetails = auth .inMemoryAuthentication ();
67+ Set <String > usernames = new HashSet <>();
6268 int i = 0 ;
6369 SimpleUser user = loadUser (i ++);
6470 while (user != null ) {
65- userDetails
66- .withUser (user .name )
67- .password ("{noop}" + user .password )
68- .roles (user .roles );
71+ if (usernames .contains (user .name .toLowerCase ())) {
72+ logger .warn ("Ignoring duplicate user with username '{}' in 'proxy.users[{}]' (usernames are case-insensitive)" , user .name , i - 1 );
73+ } else {
74+ userDetails
75+ .withUser (user .name )
76+ .password ("{noop}" + user .password )
77+ .roles (user .roles );
78+ usernames .add (user .name .toLowerCase ());
79+ }
6980 user = loadUser (i ++);
7081 }
7182 }
@@ -75,7 +86,6 @@ private SimpleUser loadUser(int index) {
7586 if (userName == null ) return null ;
7687 String password = environment .getProperty (String .format ("proxy.users[%d].password" , index ));
7788
78- // method 1: single property with comma seperated groups
7989 List <String > groups = EnvironmentUtils .readList (environment , String .format ("proxy.users[%d].groups" , index ));
8090 if (groups != null ) {
8191 return new SimpleUser (userName , password , groups .toArray (new String [0 ]));
0 commit comments