@Bean public static UserDetailsService userDetailsService() { return new InMemoryUserDetailsManager(PasswordEncodedUser.user(), PasswordEncodedUser.admin()); } }
@Test public void getAuthenticationWhenUserDetailsServiceBeanThenAuthenticationManagerUsesUserDetailsServiceBean() throws Exception { this.spring.register(UserDetailsServiceBeanConfig.class).autowire(); UserDetailsService uds = this.spring.getContext().getBean(UserDetailsService.class); AuthenticationManager am = this.spring.getContext().getBean(AuthenticationConfiguration.class).getAuthenticationManager(); when(uds.loadUserByUsername("user")).thenReturn(PasswordEncodedUser.user(), PasswordEncodedUser.user()); am.authenticate(new UsernamePasswordAuthenticationToken("user", "password")); assertThatThrownBy(() -> am.authenticate(new UsernamePasswordAuthenticationToken("user", "invalid"))) .isInstanceOf(AuthenticationException.class); }
@Bean public static ReactiveUserDetailsService userDetailsService() { return new MapReactiveUserDetailsService(PasswordEncodedUser.user(), PasswordEncodedUser.admin()); } }
@Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser(PasswordEncodedUser.user()); } }
@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser(PasswordEncodedUser.user()); }
@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser(PasswordEncodedUser.user()); } // @formatter:on
@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser(PasswordEncodedUser.user()); } }
@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser(PasswordEncodedUser.user()); } // @formatter:on
@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser(PasswordEncodedUser.user()); }
protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser(PasswordEncodedUser.user()); } }
@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser(PasswordEncodedUser.user()); }
@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser(PasswordEncodedUser.user()); }
@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser(PasswordEncodedUser.user()); } }
@Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth .eraseCredentials(false) .inMemoryAuthentication() .withUser(PasswordEncodedUser.user()); } }
@Autowired protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser(PasswordEncodedUser.user()) .withUser(PasswordEncodedUser.admin()); }
protected void configure(AuthenticationManagerBuilder auth) throws Exception { // @formatter:off auth .inMemoryAuthentication() .withUser(PasswordEncodedUser.user()) .withUser(PasswordEncodedUser.admin()); // @formatter:on } }
@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser(PasswordEncodedUser.user()) .withUser(PasswordEncodedUser.admin()); } }
protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .jdbcAuthentication() .withDefaultSchema() .withUser(PasswordEncodedUser.user()) .dataSource(this.dataSource); // jdbc-user-service@data-source-ref } }
@Test public void changePasswordWhenUsernameIsNotInLowercase() { UserDetails userNotLowerCase = User.withUserDetails(PasswordEncodedUser.user()) .username("User") .build(); String newPassword = "newPassword"; this.manager.updatePassword(userNotLowerCase, newPassword); assertThat(this.manager.loadUserByUsername(userNotLowerCase.getUsername()).getPassword()).isEqualTo(newPassword); } }
@Test // http@access-denied-page public void configureWhenAccessDeniedPageSetAndRequestForbiddenThenForwardedToAccessDeniedPage() throws Exception { this.spring.register(AccessDeniedPageConfig.class).autowire(); this.mockMvc.perform(get("/admin").with(user(PasswordEncodedUser.user()))) .andExpect(status().isForbidden()) .andExpect(forwardedUrl("/AccessDeniedPage")); }