@Bean public UserDetailsService userDetailsService() { return userName -> { UserDTO user = userAuthenticationProvider.userService.findByLogin(userName.toLowerCase()); if (user == null) { throw new UsernameNotFoundException(userName); } Set<SimpleGrantedAuthority> userAuthorities = new HashSet<>(); List<Role> roles = user.getRoles(); if (roles != null) { for (Role role : roles) { userAuthorities.add(new SimpleGrantedAuthority(role.toString())); } } return new User(userName, userName /* TODO use password */, userAuthorities); }; }
@Bean public UserDetailsService userDetailsService() { return new UserDetailsService() { public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { User user = dao.getUserByEmail(email); if(user != null) { return new org.springframework.security.core.userdetails.User( user.getEmail(), user.getPassword(), user.valid(), true, true, true, AuthorityUtils.createAuthorityList(user.fetchAuthorities()) ); } else { throw new UsernameNotFoundException("Could not find that user"); } } }; }
@Autowired public SpringSecurityUserContext(final CalendarService calendarService, final UserDetailsService userDetailsService) { if (calendarService == null) { throw new IllegalArgumentException("calendarService cannot be null"); } if (userDetailsService == null) { throw new IllegalArgumentException("userDetailsService cannot be null"); } this.calendarService = calendarService; this.userDetailsService = userDetailsService; }
@Bean UserDetailsService userDetailsService() { return new InMemoryUserDetailsManager( User .withUsername("user") .password("password") .roles("USER").build()); }
@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(); }); }
public UaaWebSecurityConfiguration(UserDetailsService userDetailsService, AuthenticationManagerBuilder authenticationManagerBuilder, @Qualifier("authenticationProviderResolver") AuthenticationProviderResolver authenticationProviderResolver, @Lazy PasswordEncoder passwordEncoder) { this.userDetailsService = userDetailsService; this.authenticationManagerBuilder = authenticationManagerBuilder; this.authenticationProviderResolver = authenticationProviderResolver; this.passwordEncoder = passwordEncoder; }
@Bean public DaoAuthenticationProvider daoAuthenticationProvider(UserDetailsService userDetailsService, PasswordEncoder passwordEncoder) { DaoAuthenticationProvider provider = new DaoAuthenticationProvider(); provider.setUserDetailsService(userDetailsService); provider.setPasswordEncoder(passwordEncoder); return provider; }
@Autowired public SpringSecurityUserContext(CalendarService calendarService,UserDetailsService userDetailsService) { if (calendarService == null) { throw new IllegalArgumentException("calendarService cannot be null"); } if (userDetailsService == null) { throw new IllegalArgumentException("userDetailsService cannot be null"); } this.calendarService = calendarService; this.userDetailsService = userDetailsService; }
public SecurityConfiguration(AuthenticationManagerBuilder authenticationManagerBuilder, UserDetailsService userDetailsService, TokenProvider tokenProvider, CorsFilter corsFilter) { this.authenticationManagerBuilder = authenticationManagerBuilder; this.userDetailsService = userDetailsService; this.tokenProvider = tokenProvider; this.corsFilter = corsFilter; }
@Autowired public AuthServiceImpl( AuthenticationManager authenticationManager, UserDetailsService userDetailsService, JwtTokenUtil jwtTokenUtil, UserRepository userRepository, RoleRepository roleRepository) { this.authenticationManager = authenticationManager; this.userDetailsService = userDetailsService; this.jwtTokenUtil = jwtTokenUtil; this.userRepository = userRepository; this.roleRepository = roleRepository; }
public SecurityConfiguration(AuthenticationManagerBuilder authenticationManagerBuilder, UserDetailsService userDetailsService, CorsFilter corsFilter, UnauthorisedEntryPoint unauthorisedEntryPoint, TokenAuthenticationFilter tokenAuthenticationFilter) { this.authenticationManagerBuilder = authenticationManagerBuilder; this.userDetailsService = userDetailsService; this.corsFilter = corsFilter; this.unauthorisedEntryPoint = unauthorisedEntryPoint; this.tokenAuthenticationFilter = tokenAuthenticationFilter; }
public OAuthConfig() throws Exception { ClientDetailsService csvc = new InMemoryClientDetailsServiceBuilder() .withClient("mobile").authorizedGrantTypes("password") .authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT") .scopes("read","write").resourceIds("prublisher") .accessTokenValiditySeconds(3600).and().build(); UserDetailsService svc = new InMemoryUserDetailsManager( Arrays.asList( User.create("publisher", "publisher", MobileClient.ROLE_PUBLISHER), User.create("subscriber", "subscriber", MobileClient.ROLE_SUBSCRIBER))); combinedService_ = new ClientAndUserDetailsService(csvc,svc); }
@Autowired public AccountController(UserDetailsService userDetailsService) { if (userDetailsService == null) { throw new IllegalArgumentException("userDetailsService cannot be null"); } this.userDetailsService = userDetailsService; }
@Autowired public SpringSecurityUserContext(CalendarService calendarService, UserDetailsService userDetailsService) { if (calendarService == null) { throw new IllegalArgumentException("calendarService cannot be null"); } if (userDetailsService == null) { throw new IllegalArgumentException("userDetailsService cannot be null"); } this.calendarService = calendarService; this.userDetailsService = userDetailsService; }
private UsernamePasswordAuthenticationToken authentication(ServletContext servletContext) { ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); UserDetailsService userDetailsService = userDetailsService(context); UserDetails userDetails = userDetailsService.loadUserByUsername(this.username); return new UsernamePasswordAuthenticationToken( userDetails, userDetails.getPassword(), userDetails.getAuthorities()); }
public void afterPropertiesSet() throws Exception { Collection<UserDetailsService> userDetailsServices=this.getApplicationContext().getBeansOfType(UserDetailsService.class).values(); if(userDetailsServices.size()==0){ throw new RuntimeException("You must implementation["+UserDetailsService.class.getName()+"] interface and config it in spring context when use bdf2-jbpm4 module"); } userDetailsService=userDetailsServices.iterator().next(); senders=this.getApplicationContext().getBeansOfType(IMessageSender.class).values(); }
@Bean public UserDetailsService userDetailsService(final UserRepository repository) { return new UserDetailsService() { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { return new UserDetailsImpl(repository.findByUsername(username)); } }; }
@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(); }); }
@Override public void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(new UserDetailsService() { @Override public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException { return readerRepository.findOne(userName); } }); }