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

The following examples show how to use org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder#eraseCredentials() . 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: WebSecurityConfig.java    From mogu_blog_v2 with Apache License 2.0 5 votes vote down vote up
@Autowired
public void configureAuthentication(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
    authenticationManagerBuilder
            // 设置UserDetailsService
            .userDetailsService(this.userDetailsService)
            // 使用BCrypt进行密码的hash
            .passwordEncoder(passwordEncoder());
    //remember me
    authenticationManagerBuilder.eraseCredentials(false);
}
 
Example 2
Source File: SpringletsSecurityInMemoryAuthenticationConfigurer.java    From springlets with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * Initializes the InMemoryUserDetailsManager with the following users:
 * 
 * * user/password, role USER
 * * admin/password, role ADMIN
 * 
 * Neither the method {@link AuthenticationManagerBuilder#inMemoryAuthentication()} 
 * nor {@link AuthenticationManagerBuilder#apply(SecurityConfigurerAdapter)} 
 * are used to avoid to override the default UserDetailsService. Note that Springlets 
 * configure the JpaUserDetailsService as the default one.
 * 
 * Use the passwords as given, they aren't encrypted.
 */
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {

  // clear credentials after success authentication
  auth.eraseCredentials(securityProperties.getAuth().getInMemory().isEraseCredentials());

  // Configure a in memory AuthenticationProvider with two users
  InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder> inMemAuthProvConfigurer =
      new InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder>();

  String userPassw = UUID.randomUUID().toString();
  inMemAuthProvConfigurer.withUser("user").password(userPassw).roles("USER");

  String adminPassw = UUID.randomUUID().toString();
  inMemAuthProvConfigurer.withUser("admin").password(adminPassw).roles("USER",
      "ADMIN");

  LOG.info("\n\nDefault security users [USERNAME : PASSWORD : ROLES]:\n" +
           "\n  [user  : {} : ROLE_USER]\n" +
           "\n  [admin : {} : ROLE_USER, ROLE_ADMIN]\n", userPassw , adminPassw);

  // Add users credentials to Environment for dev purposes

  Map<String, Object> map = new HashMap<String, Object>();
  map.put("springlets.security.auth.in-memory.enabled", true);
  map.put("springlets.security.auth.in-memory.user.name", "user");
  map.put("springlets.security.auth.in-memory.user.password", userPassw);

  MutablePropertySources sources = this.applicationContext.getEnvironment().getPropertySources();
  sources.addLast(new MapPropertySource("springlets", map));

  inMemAuthProvConfigurer.configure(auth);
}
 
Example 3
Source File: AppSecurityModelE.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
@Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// without salt
   //auth.userDetailsService(userDetailsService).passwordEncoder(md5PasswordEncoder());

// with salt
auth.authenticationProvider(authProvider());
auth.eraseCredentials(false);
  }
 
Example 4
Source File: AppSecurityModelE2.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
@Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// without salt
   //auth.userDetailsService(userDetailsService).passwordEncoder(md5PasswordEncoder());

// with salt
auth.authenticationProvider(authProvider());
auth.eraseCredentials(false);
  }
 
Example 5
Source File: AppSecurityModelE.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
@Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// without salt
   //auth.userDetailsService(userDetailsService).passwordEncoder(md5PasswordEncoder());

// with salt
auth.authenticationProvider(authProvider());
auth.eraseCredentials(false);
  }
 
Example 6
Source File: WebSecurityConfig.java    From Spring with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
       auth.inMemoryAuthentication()
               .withUser("user1").password("password1").roles("USER")
               .and()
               .withUser("admin").password("password2").roles("ADMIN");

       auth.eraseCredentials(false);
}
 
Example 7
Source File: WebSecurityConfig.java    From SpringBootLearn with Apache License 2.0 5 votes vote down vote up
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth
            // 设置UserDetailsService
            .userDetailsService(userDetailsService())
            // 使用BCrypt进行密码的hash
            .passwordEncoder(passwordEncoder());
    auth.eraseCredentials(false);
}
 
Example 8
Source File: WebSecurityConfig.java    From spring-security with Apache License 2.0 4 votes vote down vote up
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService()).passwordEncoder(passwordEncoder());
    auth.eraseCredentials(false);
}
 
Example 9
Source File: AppSecurityModelG.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
@Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {    
auth.authenticationProvider(authProvider());
auth.eraseCredentials(false);
  }
 
Example 10
Source File: WebSecurityConfig.java    From hesperides with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void configure(AuthenticationManagerBuilder authManagerBuilder) {
    authManagerBuilder.authenticationProvider(authenticationProvider);
    authManagerBuilder.eraseCredentials(false); // Nécessaire pour LdapUserInfoRepository
}
 
Example 11
Source File: AppSecurityModelD.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
@Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
auth.eraseCredentials(false);
  }
 
Example 12
Source File: AppSecurityModelJ.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
@Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authProvider());
auth.eraseCredentials(false);
  }
 
Example 13
Source File: WebSecurityConfig.java    From spring-security with Apache License 2.0 4 votes vote down vote up
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService()).passwordEncoder(passwordEncoder());
    auth.eraseCredentials(false);
}
 
Example 14
Source File: AppSecurityModelF.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
@Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authProvider());
auth.eraseCredentials(false);
  }
 
Example 15
Source File: AppSecurityModelG.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
@Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {    
auth.authenticationProvider(authProvider());
auth.eraseCredentials(false);
  }
 
Example 16
Source File: WebSecurityConfig.java    From spring-security with Apache License 2.0 4 votes vote down vote up
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService()).passwordEncoder(passwordEncoder());
    auth.eraseCredentials(false);
}
 
Example 17
Source File: AppSecurityModelD.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
@Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
auth.eraseCredentials(false);
  }
 
Example 18
Source File: AppSecurityModelJ.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
@Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authProvider());
auth.eraseCredentials(false);
  }
 
Example 19
Source File: WebSecurityConfig.java    From spring-security with Apache License 2.0 4 votes vote down vote up
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService()).passwordEncoder(passwordEncoder());
    auth.eraseCredentials(false);
}
 
Example 20
Source File: AppSecurityModelF.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
@Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authProvider());
auth.eraseCredentials(false);
  }