[SpringBoot] Spring Security, custom login 반응없음
지금 보고 있는 도서는 아래 도서이다.
- 저자
- 이재환
- 출판
- 비제이퍼블릭
- 출판일
- 2020.11.30
아무래도 출판된지 시간이 되어서 그런지 현재 기준 동작하지 않는 부분이 있다.
스프링 시큐리티도 그 중 하나인데.. 삽질한 내용 정리해본다.
그런데 사실 이번 삽질은 나의 실수.. ㅋㅋ 정말 삽질이다 ㅋㅋㅋ
로그인할 때 노출한 화면 코드이다. (loginForm.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>LoginForm</title>
</head>
<body>
<h1>loginForm.jsp</h1>
<form-login action="<c:url value='j_spring_security_check' />" method="post">
ID : <input type="text" name="j_username"> <br>
PW : <input type="text" name="j_password"> <br>
<input type="submit" value="LOGIN"> <br>
</form-login>
</body>
</html>
그리고 WebSecurityConfigurerAdapter 를 상속해서 구현한 WebSecurityConfig 클래스 중 로그인 처리를 하는 부분이다.
...
http.formLogin()
.loginPage("/loginForm") // 로그인폼 url 지정, default: /login
.loginProcessingUrl("/j_spring_security_check")
.failureUrl("/loginError") // default: /login?error
.defaultSuccessUrl("/member/welcome") // 로그인 성공시 호출할 url. 미지정 시 root(/)로 이동
.usernameParameter("j_username") // default: j_username
.passwordParameter("j_password") // default: j_password
.permitAll();
...
화면 띄우고 ID, PW 입력 후 LOGIN 클릭 시 로그인 성공/실패 수행될 줄 알았으나 아무 동작이 없는 것이다! 뭐지? 왜?
이런저런 삽질을 하다가 <form-login> 태그를 <form> 태그로 수정해보니, 정상 처리 된다!!
다시 책에 있는 코드를 살펴보니 <form-login> 태그가 아니고 <form> 태그로 되어 있다. 내가 미쳤나... 그런데 찾아보니 <form-login> 태그도 있긴하다. spring security 용으로... 그런데 <form-login> 태그에서는 왜 동작하지 않을까? -_-;; 혹시 아시는 분...
추가로 ChatGPT에 물어보니 <form> 태그 사용할 때 action 속성 값으로 <spring:url> 태그를 사용하라고 한다. taglib 추가는 필수..
코드 확인 >>
GitHub - chp320/bjSpringBoot
Contribute to chp320/bjSpringBoot development by creating an account on GitHub.
github.com
참고 >>
Spring Boot spring security 로 로그인을 구현하자!
IntelliJ : 2020.3.2.communityspring boot : 2.6.1springsecurity 를 이용할 것이다.이 전 글에서 회원가입에 대해서 구현해 놓았다.로그인을 하려면 계정 가입된 데이터가 있어야 한다.📌 Spring Boot 회원가입 구
velog.io
https://recordsoflife.tistory.com/248
스프링 Security Form 로그인 사용방법
If you have a few years of experience in the Java ecosystem, and you're interested in sharing that experience with the community (and getting paid for your work of course), have a look at the "Write for Us" page. Cheers. Eugen 1. 소개 이 글은 Login wi
recordsoflife.tistory.com
https://brilliantdevelop.tistory.com/139
Spring security (1) - 퀵 스타트
인증과 인가 인증(Authentication) : 현재 사용자가 누구인지 확인하는 과정. 아이디/암호를 이용해 인증 처리 (네이버에서 로그인 하는 과정) 인가(Authorization) : 현재 사용자가 특정 대상(URL,기능 등)
brilliantdevelop.tistory.com
Spring Security 정리(1) : 로그인 화면
프로젝트를 진행하면서 작성한 내용을 순서대로 정리합니다. 1. pom.xml 작성 org.springframework.security spring-security-core ${spring.security.version} org.springframework.security spring-security-web ${spring.security.version} org
otrodevym.tistory.com