Java Code Examples for org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder#inMemoryAuthentication()

The following examples show how to use org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder#inMemoryAuthentication() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TraderUISecurityConfiguration.java    From java-trader with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(AuthenticationManagerBuilder builder) throws Exception {
    String users = ConfigUtil.getString(ITEM_USERS);
    IniFile usersIni = new IniFile(new StringReader(users));

    InMemoryUserDetailsManagerConfigurer userConfigurer = builder.inMemoryAuthentication();
    for(IniFile.Section section:usersIni.getAllSections()) {
        String username=section.get("username");
        String credential = section.get("credential");
        String rolesStr = section.get("roles");
        String[] roles = StringUtil.split(rolesStr, ",|;");
        if ( roles.length==0 ) {
            roles = new String[] {"user"};
        }
        userConfigurer.withUser(username).password(credential).roles(roles);
    }

}
 
Example 2
Source File: WebSecurityConfig.java    From spring-ddd-bank with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**Configures the {@link #predefinedUsernames} as known users with their password equal to the user name.
* @param auth a SecurityBuilder injected by Spring, used to create an AuthenticationManager
* @throws Exception if an error occurs when configuring the in memory authentication
* */
  @Autowired
  public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception {
      final InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder> inMemoryAuthentication = auth.inMemoryAuthentication();
      for(final String username: predefinedUsernames) {
      	final String role = username.equalsIgnoreCase(BANK_ROLE) ? BANK_ROLE : CLIENT_ROLE;
	inMemoryAuthentication.withUser(username).password(username).roles(role);
      }
  }
 
Example 3
Source File: WebSecurityConfigJWT.java    From quartz-manager with Apache License 2.0 5 votes vote down vote up
private void configureInMemoryAuthentication(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
  PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
  if(inMemoryAccountProps.isEnabled() && inMemoryAccountProps.getUsers() != null && !inMemoryAccountProps.getUsers().isEmpty()) {
    InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder> inMemoryAuth = authenticationManagerBuilder.inMemoryAuthentication();
    inMemoryAccountProps.getUsers()
    .forEach(u -> inMemoryAuth
        .withUser(u.getName())
        .password(encoder.encode(u.getPassword()))
        .roles(u.getRoles().toArray(new String[0])));
  }
}
 
Example 4
Source File: DefaultMethodSecurityConfigurer.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
	@Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
		if(userDetailsService!=null){
			auth.userDetailsService(userDetailsService)
				.passwordEncoder(passwordEncoder);
		}else{
			InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder> inMemory = auth.inMemoryAuthentication();
//			InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder> inMemory = auth.apply(new ExtInMemoryUserDetailsManagerConfigurer());
			securityConfig.getMemoryUsers().forEach((user, config)->{
				UserDetailsBuilder udb = inMemory.withUser(user).password(config.getPassword());
				if(!LangUtils.isEmpty(config.getRoles())){
					udb.roles(config.getRoles());
				}
				if(!LangUtils.isEmpty(config.getAuthorities())){
					udb.authorities(config.getAuthorities());
				}
			});
			inMemory.passwordEncoder(passwordEncoder);
		}
		
		/*DaoAuthenticationProvider daoProvider = new DaoAuthenticationProvider();
		daoProvider.setUserDetailsService(userDetailsService);
		daoProvider.setPasswordEncoder(passwordEncoder);
		daoProvider.afterPropertiesSet();
		auth.authenticationProvider(daoProvider);*/
    }
 
Example 5
Source File: WebSecurityConfig.java    From tailstreamer with MIT License 5 votes vote down vote up
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    if (!users.isEmpty()) {
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder> configurer = auth.inMemoryAuthentication();
        configurer.passwordEncoder(encoder);

        for (User user : users) {
            configurer.withUser(user.getUsername()).password(user.getPassword()).roles("USER");
        }
    }
}
 
Example 6
Source File: GlobalSecurityConfig.java    From secrets-proxy with Apache License 2.0 4 votes vote down vote up
/**
 * This is a workaround to avoid generating default password as an <code>InMemoryAuthentication
 * </code> manager is already configured in {@link WebSecurityConfig}.
 */
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
  log.info("Configuring global authentication manager.");
  auth.inMemoryAuthentication();
}
 
Example 7
Source File: SecurityConfiguration.java    From omh-dsu-ri with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication();
}
 
Example 8
Source File: SecurityConfig.java    From tutorials with MIT License 4 votes vote down vote up
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication();
}
 
Example 9
Source File: SecurityConfig.java    From tutorials with MIT License 4 votes vote down vote up
@Autowired
public void configureGlobal1(AuthenticationManagerBuilder auth) throws Exception {
    //try in memory auth with no users to support the case that this will allow for users that are logged in to go anywhere
    auth.inMemoryAuthentication();
}
 
Example 10
Source File: SecurityConfig.java    From tutorials with MIT License 4 votes vote down vote up
@Autowired
public void configureGlobal1(AuthenticationManagerBuilder auth) throws Exception {
    //try in memory auth with no users to support the case that this will allow for users that are logged in to go anywhere
    auth.inMemoryAuthentication();
}