org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder Java Examples

The following examples show how to use org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder. 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: CrustConfigurerAdapter.java    From Milkomeda with MIT License 6 votes vote down vote up
@Override
public void configure(AuthenticationManagerBuilder auth) {
    CrustAuthenticationProvider authenticationProvider = new CrustAuthenticationProvider(props, passwordEncoder);
    configureProvider(authenticationProvider);
    // 添加自定义身份验证组件
    auth.authenticationProvider(authenticationProvider);
}
 
Example #2
Source File: SecurityConfiguration.java    From e-commerce-microservice with Apache License 2.0 5 votes vote down vote up
public SecurityConfiguration(AuthenticationManagerBuilder authenticationManagerBuilder, UserDetailsService userDetailsService, TokenProvider tokenProvider, CorsFilter corsFilter, SecurityProblemSupport problemSupport) {
    this.authenticationManagerBuilder = authenticationManagerBuilder;
    this.userDetailsService = userDetailsService;
    this.tokenProvider = tokenProvider;
    this.corsFilter = corsFilter;
    this.problemSupport = problemSupport;
}
 
Example #3
Source File: SecurityConfiguration.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
/**
 * 模拟数据库查询,判断尝试登陆用户是否满足认证条件
 *
 * @param auth AuthenticationManagerBuilder
 * @throws Exception 异常
 */
@Override
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication()
        .withUser("user1").password(passwordEncoder().encode("123456")).roles("USER")
        .and()
        .withUser("user2").password(passwordEncoder().encode("qweasd")).roles("USER")
        .and()
        .withUser("admin").password(passwordEncoder().encode("admin")).roles("ADMIN");
}
 
Example #4
Source File: SecurityConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.jdbcAuthentication()
        .dataSource(dataSource)
        .usersByUsernameQuery("select email,password,enabled "
            + "from bael_users "
            + "where email = ?")
        .authoritiesByUsernameQuery("select email,authority "
            + "from authorities "
            + "where email = ?");
}
 
Example #5
Source File: WebServerSecurityConfig.java    From SpringCloud with Apache License 2.0 5 votes vote down vote up
/**
 * 注入自定义的userDetailsService实现,获取用户信息,设置密码加密方式
 *
 * @param authenticationManagerBuilder
 * @throws Exception
 */
@Override
protected void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
    authenticationManagerBuilder
            .userDetailsService(userDetailsService)
            .passwordEncoder(passwordEncoder());
    // 设置手机验证码登陆的AuthenticationProvider
    authenticationManagerBuilder.authenticationProvider(mobileAuthenticationProvider());
}
 
Example #6
Source File: PersonApplication.java    From blog with Apache License 2.0 5 votes vote down vote up
/**
 * Registers the KeycloakAuthenticationProvider with the authentication manager.
 */
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();

    // adding proper authority mapper for prefixing role with "ROLE_"
    keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(new SimpleAuthorityMapper());

    auth.authenticationProvider(keycloakAuthenticationProvider);
}
 
Example #7
Source File: SecurityConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication()
        .passwordEncoder(passwordEncoder())
        .withUser("user1")
        .password(passwordEncoder().encode("user"))
        .roles("USER")
        .and()
        .withUser("admin")
        .password(passwordEncoder().encode("admin"))
        .roles("ADMIN");
}
 
Example #8
Source File: OAuthConfiguration.java    From spring-boot-microservices with Apache License 2.0 5 votes vote down vote up
/**
 * Setup 2 users with different roles
 */
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
	// @formatter:off
	auth.jdbcAuthentication().dataSource(dataSource).withUser("dave")
			.password("secret").roles("USER");
	auth.jdbcAuthentication().dataSource(dataSource).withUser("anil")
			.password("password").roles("ADMIN");
	// @formatter:on
}
 
Example #9
Source File: StateApiSecurityConfig.java    From gaia with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
    logger.info(String.format("%n%nUsing generated security password for state API: %s%n", properties().getPassword()));

    // configure default backend user
    auth
            .inMemoryAuthentication()
            .withUser(properties().getUsername()).password(bCrypt.encode(properties().getPassword())).authorities("ROLE_STATE");
}
 
Example #10
Source File: BaseWebSecurityConfig.java    From jump-the-queue with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("javadoc")
@Inject
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

  auth.inMemoryAuthentication().withUser("waiter").password(this.passwordEncoder.encode("waiter")).roles("Waiter")
      .and().withUser("cook").password(this.passwordEncoder.encode("cook")).roles("Cook").and().withUser("barkeeper")
      .password(this.passwordEncoder.encode("barkeeper")).roles("Barkeeper").and().withUser("chief")
      .password(this.passwordEncoder.encode("chief")).roles("Chief");
}
 
Example #11
Source File: BasicAuthConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth
      .inMemoryAuthentication()
      .withUser("user")
      .password("password")
      .roles("USER");
}
 
Example #12
Source File: SecurityConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
	auth.jdbcAuthentication()
   		.passwordEncoder(new BCryptPasswordEncoder())
	    .dataSource(dataSource())
	    .usersByUsernameQuery("select name, password, enabled from t_account where name=?")
	    .authoritiesByUsernameQuery("select name, role from t_account_role where name=?");
}
 
Example #13
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 #14
Source File: SecurityConfiguration.java    From Full-Stack-Development-with-JHipster with MIT License 5 votes vote down vote up
public SecurityConfiguration(AuthenticationManagerBuilder authenticationManagerBuilder, UserDetailsService userDetailsService,TokenProvider tokenProvider,CorsFilter corsFilter, SecurityProblemSupport problemSupport) {
    this.authenticationManagerBuilder = authenticationManagerBuilder;
    this.userDetailsService = userDetailsService;
    this.tokenProvider = tokenProvider;
    this.corsFilter = corsFilter;
    this.problemSupport = problemSupport;
}
 
Example #15
Source File: WebSecurityConfigurer.java    From spring-microservices-in-action with Apache License 2.0 5 votes vote down vote up
@Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// Store in memory
//        auth
//                .inMemoryAuthentication()
//                .withUser("john.carnell").password("password1").roles("USER")                 // Define the first user: john.carnell with the password "password1" and the role "USER"
//                .and()
//                .withUser("william.woodward").password("password2").roles("USER", "ADMIN");   // Define the second user: william.woodward with the password "password2" and the role "ADMIN"

// Store in databse
    	auth.jdbcAuthentication().dataSource(dataSource).passwordEncoder(passwordEncoder);
    }
 
Example #16
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 #17
Source File: PatronsAuthConfig.java    From Hands-On-RESTful-API-Design-Patterns-and-Best-Practices with MIT License 5 votes vote down vote up
@Override
protected void configure(AuthenticationManagerBuilder authMgrBldr) throws Exception {
	authMgrBldr.inMemoryAuthentication()
			.passwordEncoder(org.springframework.security.crypto.password.NoOpPasswordEncoder.getInstance())
			.withUser(DEFAULT_USER_ID).password(DEFAULT_USER_SECRET).authorities(DEFAULT_USER_ROLE).and()
			.withUser(DEFAULT_ADMIN_ID).password(DEFAULT_ADMIN_SECRET)
			.authorities(DEFAULT_USER_ROLE, DEFAULT_ADMIN_ROLE);
}
 
Example #18
Source File: SecurityConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
	PasswordEncoder pwdEncoder = new BCryptPasswordEncoder();
	auth.inMemoryAuthentication() 
	    .passwordEncoder(pwdEncoder)
			.withUser("admin") 
			    .password(pwdEncoder.encode("admin12345678"))
			    .roles("ADMIN", "MEMBER")
		.and()
			.withUser("caterpillar")
			    .password(pwdEncoder.encode("12345678"))
			    .roles("MEMBER");
}
 
Example #19
Source File: SecurityConfig.java    From JiwhizBlogWeb with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(AuthenticationManagerBuilder builder) throws Exception{
    builder
    	.authenticationProvider(socialAuthenticationProvider())
    	.authenticationProvider(rememberMeAuthenticationProvider())
    	.userDetailsService(userAccountService);
}
 
Example #20
Source File: CustomWebSecurityConfigurerAdapter.java    From tutorials with MIT License 5 votes vote down vote up
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth
      .inMemoryAuthentication()
      .withUser("user1")
      .password(passwordEncoder().encode("user1Pass"))
      .authorities("ROLE_USER");
}
 
Example #21
Source File: SecurityConfig.java    From openvidu with Apache License 2.0 4 votes vote down vote up
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
	auth.inMemoryAuthentication().withUser("OPENVIDUAPP").password("{noop}" + openviduConf.getOpenViduSecret())
			.roles("ADMIN");
}
 
Example #22
Source File: SecurityConfig.java    From Spring-Boot-Blog with MIT License 4 votes vote down vote up
@Override
protected void configure(AuthenticationManagerBuilder auth)
        throws Exception {
    auth.authenticationProvider(authenticationProvider());
}
 
Example #23
Source File: SecurityConfig.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
/**
 * Configure AuthenticationManager with inMemory credentials.
 *
 * NOTE:
 * Due to a known limitation with JavaConfig:
 * <a href="https://jira.spring.io/browse/SPR-13779">
 *     https://jira.spring.io/browse/SPR-13779</a>
 *
 * We cannot use the following to expose a {@link UserDetailsManager}
 * <pre>
 *     http.authorizeRequests()
 * </pre>
 *
 * In order to expose {@link UserDetailsManager} as a bean, we must create  @Bean
 *
 * @see {@link super.userDetailsService()}
 * @see {@link com.packtpub.springsecurity.service.DefaultCalendarService}
 *
 * @param auth       AuthenticationManagerBuilder
 * @throws Exception Authentication exception
 */
@Override
public void configure(final AuthenticationManagerBuilder auth) throws Exception {
    auth
            .ldapAuthentication()
            .userSearchBase("")
            .userSearchFilter("(uid={0})")
            .groupSearchBase("ou=Groups")
            .groupSearchFilter("(uniqueMember={0})")
            .userDetailsContextMapper(new InetOrgPersonContextMapper())
            .contextSource(contextSource())
            .passwordCompare()
                // Supports {SHA} and {SSHA}
                .passwordEncoder(new LdapShaPasswordEncoder())
                .passwordAttribute("userPassword")
    ;
}
 
Example #24
Source File: SecurityConfig.java    From Using-Spring-Oauth2-to-secure-REST with MIT License 4 votes vote down vote up
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth
            .userDetailsService(userDetailsService)
            .passwordEncoder(passwordEncoder);
}
 
Example #25
Source File: UaaWebSecurityConfiguration.java    From cubeai with Apache License 2.0 4 votes vote down vote up
public UaaWebSecurityConfiguration(UserDetailsService userDetailsService, AuthenticationManagerBuilder authenticationManagerBuilder) {
    this.userDetailsService = userDetailsService;
    this.authenticationManagerBuilder = authenticationManagerBuilder;
}
 
Example #26
Source File: SecurityConfiguration.java    From SpringMvcStepByStep with MIT License 4 votes vote down vote up
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth)
		throws Exception {
	auth.inMemoryAuthentication().withUser("in28Minutes").password("dummy")
			.roles("USER", "ADMIN");
}
 
Example #27
Source File: SecurityConfiguration.java    From pcf-crash-course-with-spring-boot with MIT License 4 votes vote down vote up
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth)
        throws Exception {
    auth.inMemoryAuthentication().withUser("in28minutes").password("{noop}dummy")
            .roles("USER", "ADMIN");
}
 
Example #28
Source File: SecurityConfig.java    From QuizZz with MIT License 4 votes vote down vote up
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth, UserDetailsService userDetailsService,
		PasswordEncoder encoder) throws Exception {
	auth.userDetailsService(userDetailsService).passwordEncoder(encoder);
}
 
Example #29
Source File: WebSecurityConfig.java    From tutorials with MIT License 4 votes vote down vote up
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.authenticationProvider(kerberosAuthenticationProvider())
      .authenticationProvider(kerberosServiceAuthenticationProvider());
}
 
Example #30
Source File: SecurityConfig.java    From microservices-platform with Apache License 2.0 4 votes vote down vote up
/**
 * 全局用户信息
 */
@Autowired
public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception {
	auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder);
}