spring-boot-starter-security
을 사용 중입니다. 내가 WebSecurityConfigation
DaoAuthenticationProvider
공급자와 BCryptPasswordEncoder
인증을 사용하도록 구성했습니다. 또한 UserDetailsService
구현은 password
필드가 실제 해시로 설정된 User
개체를 반환합니다.Java Spring Security의 비밀번호 해시로 인증 할 수있는 이유
잘 작동하는 것 같습니다. 그러나 내가 암호를 또는 해시를 사용하여 성공적으로 인증 할 수있는 것으로 나타났습니다.
예를 들어 암호 자체는 생성 된 UUID 51a80a6a-8618-4583-98d2-d77d103a62c6
이며 $2a$10$u4OSZf7B9yJvQ5UYNNpy7O4f3g0gfUMl2Xmm3h282W.3emSN3WqxO
으로 인코딩되었습니다.
전체 웹 보안 구성 :
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private DemoUserDetailsService userDetailsService;
@Autowired
private DaoAuthenticationProvider authenticationProvider;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider);
auth.userDetailsService(userDetailsService);
auth.inMemoryAuthentication().withUser("user").password("password").roles("SUPER", "BASIC");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/**").hasRole("BASIC").and().httpBasic();
http.csrf().disable();
}
}
@Service
public class DemoUserDetailsService implements UserDetailsService {
@Autowired
private UserRepository userRepository;
@Override
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
UserDAO userDAO = userRepository.findByEmailAndActivated(email);
if (userDAO == null) {
throw new UsernameNotFoundException(String.format("Email %s not found", email));
}
return new User(email, userDAO.getPasswordHash(), getGrantedAuthorities(email));
}
private Collection<? extends GrantedAuthority> getGrantedAuthorities(String email) {
return asList(() -> "ROLE_BASIC");
}
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
authenticationProvider.setUserDetailsService(userDetailsService);
authenticationProvider.setPasswordEncoder(passwordEncoder);
return authenticationProvider;
}
이유는 두 문자열 인증 할 수 있어요? 내가 잘못한 일을하고 있니? 문서에서 아무 것도 찾을 수 없습니다.
확률은 무엇입니까? 그러나 인코딩 된 문자열을 인코딩하여 확인하십시오.이 결과는 동일한 출력이 될 수 있습니다 (나는 그 사실을 의심합니다). 결과 해시가 고유하지 않기 때문에 가능합니다. 가능하지는 않지만 가능하면 – AxelH
이 구성을 표시합니다. bcrypt에 보안을 구현했기 때문에이 사실을 전혀 알지 못합니다. –
@shutdown -h 이제 어떤 구성을 의미합니까? – Tom