java类org.springframework.security.core.userdetails.ReactiveUserDetailsService的实例源码

WebfluxSecurityConfig.java 文件源码 项目:AngularAndSpring 阅读 23 收藏 0 点赞 0 评论 0
@Bean
public ReactiveUserDetailsService userDetailsRepository() {
    return new ReactiveUserDetailsService() {

        @Override
        public Mono<UserDetails> findByUsername(String username) {
            Query query = new Query();
            query.addCriteria(Criteria.where("userId").is(username));
            return operations.findOne(query, UserDetails.class);
        }
    };
}
UserDetailsServiceConfigurationTest.java 文件源码 项目:configurable-single-user-spring-boot-starter 阅读 19 收藏 0 点赞 0 评论 0
@Test
public void configuresADefaultUser() {
    contextRunner
            .withPropertyValues("singleuser.name=michael")
            .withConfiguration(AutoConfigurations.of(SecurityAutoConfiguration.class, SingleUserAutoConfiguration.class))
            .run(context -> {
                assertThat(context.getBean(UserDetailsService.class).loadUserByUsername("michael")).isNotNull();
                assertThat(context).getBean(ReactiveUserDetailsService.class).isNull();
            });
}
ReactiveUserDetailsServiceConfigurationTest.java 文件源码 项目:configurable-single-user-spring-boot-starter 阅读 20 收藏 0 点赞 0 评论 0
@Test
public void configuresADefaultUser() {

    contextRunner
            .withUserConfiguration(TestConfig.class)
            .withPropertyValues("singleuser.name=michael")
            .withConfiguration(AutoConfigurations.of(ReactiveSecurityAutoConfiguration.class, SingleUserAutoConfiguration.class))
            .run(context -> {
                assertThat(context.getBean(ReactiveUserDetailsService.class).findByUsername("michael").block()).isNotNull();
                assertThat(context).getBean(UserDetailsService.class).isNull();
            });
}
ReactiveUserDetailsServiceConfigurationTest.java 文件源码 项目:configurable-single-user-spring-boot-starter 阅读 19 收藏 0 点赞 0 评论 0
@Test
public void configuresNoDefaultUserWhenUserDetailsServicePresent() {
    contextRunner
            .withUserConfiguration(TestConfig.class, UserDetailsRepositoryIsPresent.class)
            .withConfiguration(AutoConfigurations.of(ReactiveSecurityAutoConfiguration.class, SingleUserAutoConfiguration.class))
            .run(context -> {
                assertThat(context.getBean(ReactiveUserDetailsService.class).findByUsername("bob").block()).isNotNull();
                assertThat(context.getBean(ReactiveUserDetailsService.class).findByUsername("michael").block()).isNull();
                assertThat(context).getBean(UserDetailsService.class).isNull();
            });
}
SecurityConfig.java 文件源码 项目:spring-reactive-sample 阅读 22 收藏 0 点赞 0 评论 0
@Bean
public ReactiveUserDetailsService userDetailsService(UserRepository users) {
    return (username) -> users.findByUsername(username).cast(UserDetails.class);
}
ReactiveUserDetailsServiceConfiguration.java 文件源码 项目:configurable-single-user-spring-boot-starter 阅读 18 收藏 0 点赞 0 评论 0
@Bean
public ReactiveUserDetailsService singleUserDetailsService(
        final SingleUserProperties singleUserProperties
) {
    return new MapReactiveUserDetailsService(singleUserProperties.asUser());
}
ReactiveUserDetailsServiceConfigurationTest.java 文件源码 项目:configurable-single-user-spring-boot-starter 阅读 16 收藏 0 点赞 0 评论 0
@Bean
public ReactiveUserDetailsService userDetailsService() {
    return new MapReactiveUserDetailsService(User.withUsername("Bob").password("bobby").roles("USER").build());
}


问题


面经


文章

微信
公众号

扫码关注公众号