Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Erro ao authenticar o usuario

Estou tomando esse erro ao fazer um requisição passando a senha e o email. Oque pode ser? Conferi o codigo e aparentemente esta correto

Hibernate: 
    select
        usuario0_.id as id1_3_,
        usuario0_.email as email2_3_,
        usuario0_.nome as nome3_3_,
        usuario0_.password as password4_3_ 
    from
        Usuario usuario0_ 
    where
        usuario0_.email=?
2021-09-07 22:50:43.944  WARN 72587 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 42122, SQLState: 42S22
2021-09-07 22:50:43.945 ERROR 72587 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : Column "USUARIO0_.PASSWORD" not found; SQL statement:
select usuario0_.id as id1_3_, usuario0_.email as email2_3_, usuario0_.nome as nome3_3_, usuario0_.password as password4_3_ from Usuario usuario0_ where usuario0_.email=? [42122-200]
3 respostas

Oi Emillyn

Envia a classe Usuario, por favor

Essas são minhas classes


@Entity
data class Usuario(
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id: Long? = null,
    val nome: String,
    val email: String,
    val password: String
)

@Service
class UsuarioService(
    private val repository: UsuarioRepository
    ) : UserDetailsService{

    fun buscaPorId(id: Long): Usuario {
        return repository.getById(id)
    }

    override fun loadUserByUsername(username: String?): UserDetails {
        val usuario = repository.findByEmail(username) ?: throw RuntimeException()
        return UserDetail(usuario)
    }

}

@Configuration
@EnableWebSecurity
class SecurityConfiguration(
    private val userDetailsService : UserDetailsService
) : WebSecurityConfigurerAdapter() {
    override fun configure(http: HttpSecurity?) {
        http?.
        authorizeRequests()?.
        anyRequest()?.
        authenticated()?.and()?.
        sessionManagement()?.sessionCreationPolicy(SessionCreationPolicy.STATELESS)?.
        and()?.
        formLogin()?.disable()?.
        httpBasic()
    }
    @Bean
    fun bCryptPasswordEncoder(): BCryptPasswordEncoder{
        return BCryptPasswordEncoder()
    }

    override fun configure(auth: AuthenticationManagerBuilder?) {
        auth?.userDetailsService(userDetailsService)?.passwordEncoder(bCryptPasswordEncoder())
    }
}

ALTER TABLE usuario ADD COLUMN password text
solução!

Consegui resolver, eu coloquei V5_ ao invés de V5__ por causa disso minhas novas migrations não rodaram.