스프링 시큐리티 1(로그인)

김보미·2023년 2월 15일
0

스프링

목록 보기
2/2

STS3를 사용하여 로그인 구현

만났던 오류들..

  1. BeanFactory not initialized or already closed - call 'refresh'
  2. No Bean Named ‘springSecurityFilterChain’ is Defined
    -> pom.xml에 있는 스프링 버전을 아래와 같이 맞춰주니 제대로 동작 되었다.
<org.springframework-version>4.3.4.RELEASE</org.springframework-version>

pom.xml 추가

<!-- Spring Security -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>4.2.1.RELEASE</version>
        </dependency>
        
		<dependency>
		    <groupId>org.springframework.security</groupId>
		    <artifactId>spring-security-web</artifactId>
		    <version>4.2.1.RELEASE</version>
		</dependency>
		
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>4.2.1.RELEASE</version>
        </dependency>

security-context

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
        
    <!-- 검사 URL -->
    <http>
        <intercept-url pattern="/**" access="hasRole('USER')" />
        <form-login />
        <logout />
    </http>
    
    <!--  provider  -->
    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="user" password="password" authorities="ROLE_USER" />
            </user-service>
        </authentication-provider>
    </authentication-manager>
    
</beans:beans>

home.jsp 로그아웃 구현

<form action="${pageContext.request.contextPath}/logout" method="POST">
 	<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
    <input type="submit" value="로그아웃222" />
	</form>

로그인 화면

로그아웃 화면

profile
🎉🎉

0개의 댓글