Engineering-Research-and-Development / true-connector-basic_data_app

GNU Affero General Public License v3.0
2 stars 9 forks source link

UserDetailService improvement #137

Open IgorBalog-Eng opened 6 months ago

IgorBalog-Eng commented 6 months ago

Current implementation is not optimal. It creates UserProvider per user, instead creating one user provider containing all users.

Possible improvements:

  1. (with reading users from property file)
    @Bean
    public UserDetailsService users() {
    UserDetails user = User.builder()
    .username("idsUser")
    .password("$2a$10$MQ5grDaIqDpBjMlG78PFduv.AMRe9cs0CNm/V4cgUubrqdGTFCH3m")
    .roles("PROXY")
    .build();
    UserDetails admin = User.builder()
    .username("bob")
    .password("$2a$12$8ngZQYUF9pATTwNRmLiYeu6XGlLd79eb4FIgr5ezzuAA6tGLxuAyy")
    .roles("PROXY")
    .build();
    return new InMemoryUserDetailsManager(user, admin);
    }
  2. 
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder> builder = auth.inMemoryAuthentication();

userProperties.getUserCredentials().keySet().forEach(user -> { String password = userProperties.getPasswordForUser(user); if (password != null) { try { builder.withUser(user).password(password).roles("PROXY"); } catch (Exception e) { logger.error("Error configuring authentication for user " + user, e.getMessage()); } } }); }


Before starting investigate which solution will be optimal and check if both implementations does not create providers per user