[error]로그인이 안된다
- register되어 DB에 들어가있는 상태
- 하지만 login창에서, 해당 username과 password를 아무리 입력해도 되지 않는다.
- 그렇다고 console에 어떤 error가 뜨고 있지도 않다.
- 인증 관련 부분에서 문제가 생긴 것 같다.
인증과 관련 쿼리는 날아오고 있었다
- Mysql workbench에서 server의 client connection을 확인하였다. ---> 인증과 관련된 쿼리인, 사용자가 입력한 username을 db의 table에 존재하는지에 대한 쿼리는 날아오고 있다.
- 그리고는 그 이후의 inner join 쿼리는 날아오고 있지 않다. 즉 위의 쿼리에서 뭔가 문제가 생겼다는 것.
- 여기서 문제를 발견함.
- 현재 나의 rest db에서 유저 테이블명은 users인데 위의 쿼리를 보면 user에 대한 select문을 날리고 있다
이는
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)
throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.passwordEncoder(passwordEncoder())
.usersByUsernameQuery("select username, password, enabled "
+ "from user "
+ "where username = ?")
.authoritiesByUsernameQuery("select u.username, r.name "
+ "from user_role ur inner join user u on ur.user_id = u.id "
+ "inner join role r on ur.role_id = r.id "
+ "where u.username = ?");
}
여기가 잘못되었기 때문이다.
위의 쿼리를 수정함
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)
throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.passwordEncoder(passwordEncoder())
.usersByUsernameQuery("select username, password, enabled "
+ "from users "
+ "where username = ?")
.authoritiesByUsernameQuery("select u.username, r.name "
+ "from user_role ur inner join user u on ur.user_id = u.id "
+ "inner join role r on ur.role_id = r.id "
+ "where u.username = ?");
}
- 즉
("select username, password, enabled "
+ "from users "
+ "where username = ?")
에서 from user였던 부분을 from users로 수정하였다.
- ⭕ 이제는 inner query 까지는 날아간다.
- ❌ 근데 여전리 Invalid username과 passowrd라는 alert가 뜬다..
원인: 쿼리의 table 명 오타.....
- 위의 캡쳐에서 info내용은 다음과 같다.
select u.username, r.name from user_role ur inner join user u on ur.user_id = u.id inner join role r on ur.role_id = r.id where u.username = 'b' - 즉
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)
throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.passwordEncoder(passwordEncoder())
.usersByUsernameQuery("select username, password, enabled "
+ "from users "
+ "where username = ?")
.authoritiesByUsernameQuery("select u.username, r.name "
+ "from user_role ur inner join user u on ur.user_id = u.id "
+ "inner join role r on ur.role_id = r.id "
+ "where u.username = ?");
}
- 즉
("select username, password, enabled "
+ "from users "
+ "where username = ?")
에서 username으로 권한을 확인하는 쿼리부분과 같다.
...... 위의 쿼리는 하드코딩된 쿼리로서 MySQL 문법과 내가 사용한 table 명을 정확하게 써줘야 했다.
user -> user 로 role -> role로 바꿔줘야 한다.
- 새벽에 해서 그런가 혼자 jpql이라고 착각하고 있었다
Author And Source
이 문제에 관하여([error]로그인이 안된다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@ynoolee/error로그인이-안된다저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)