spring security 개발환경 설정

뿌이·2022년 1월 20일
0

개발환경설정

목록 보기
7/13

pom.xml

<!-- 시큐리티 관련 기능 https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
		<dependency>
			<groupId>org.springframework.security</groupId>
			<artifactId>spring-security-web</artifactId>
			<version>5.2.10.RELEASE</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
		<dependency>
			<groupId>org.springframework.security</groupId>
			<artifactId>spring-security-config</artifactId>
			<version>5.2.10.RELEASE</version>
		</dependency>

		<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
		<dependency>
			<groupId>org.springframework.security</groupId>
			<artifactId>spring-security-core</artifactId>
			<version>5.2.10.RELEASE</version>
		</dependency>

		<!-- 시큐리티 기능 끝 https://mvnrepository.com/artifact/org.springframework.security/spring-security-taglibs -->
		<dependency>
			<groupId>org.springframework.security</groupId>
			<artifactId>spring-security-taglibs</artifactId>
			<version>5.2.10.RELEASE</version>
		</dependency>

적어주고

web.xml

<!-- spring security web 설정 -->
     <filter-mapping>
           <filter-name>springSecurityFilterChain</filter-name>
           <servlet-name>org.springframework.web.filter.DelegatingFilterProxy</servlet-name>
     </filter-mapping>
     <filter-mapping>
           <filter-name>springSecurityFilterChain</filter-name>
           <servlet-name>/*</servlet-name>
     </filter-mapping>

적어주고

root-context.xml


namespace가서 security 체크
하고

<security:http>
		<security:form-login />
	</security:http>
	<security:authentication-manager></security:authentication-manager>

적어주고 서버실행

하면 나는 안되는데 다른사람들은 됌..

어쨌든 이렇게 하고나서

만들고 이름은 security-context.xml로 만들어준다
위치는
root-context.xml이랑 같은 위치에다가 만든다

그다음
security-context.xml열고

namespace에 체크후

security-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:security="http://www.springframework.org/schema/security"
	xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.2.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<security:http>
		<security:form-login />
	</security:http>
	<security:authentication-manager></security:authentication-manager>
</beans>

이렇게 security 관련 태그를 넣어준다~
위 의 코드는 전체코드임
주의할 점은 위에서 root-context.xml에다가 적어놓은 <security:http> 어쩌고
붙여놓은 것을 옮기는것이다.
그니까 root-context.xml에는 security관련태그가 없어야하고
security-context.xml에 security관련태그가있어야함

root-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:task="http://www.springframework.org/schema/task"
	xmlns:security="http://www.springframework.org/schema/security"
	xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.2.xsd
		http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd
		http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
	
	<!-- Root Context: defines shared resources visible to all other web components -->
		
		

	<!-- ======================================추가한 부분================================================= -->
	<context:component-scan base-package="org.conan.sample"></context:component-scan>
	<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
		<property name="driverClassName"
		value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
		<property name="jdbcUrl" value="jdbc:log4jdbc:mysql://localhost:3306/scottdb?userSSL=false"></property>
		<property name="username" value="scott"></property>
		<property name="password" value="tiger"></property>
	</bean>
	
	<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
	<constructor-arg ref="hikariConfig"></constructor-arg>
	</bean>
	
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource"></property>
	</bean>
	
	<mybatis-spring:scan base-package="org.conan.persistence"/>
	<mybatis-spring:scan base-package="org.conan.mapper"/>
	
	<context:component-scan base-package="org.conan.task"></context:component-scan>
	<task:annotation-driven/>
	
	<context:component-scan base-package="org.conan.service"></context:component-scan>
	<context:component-scan base-package="org.conan.aop"></context:component-scan>
	<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
	
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"></property>
	</bean>
	<tx:annotation-driven></tx:annotation-driven>
	
	<!-- ======================================추가한 부분================================================= -->
</beans>

이렇게 security 관련 코드가 없어야한다.
위의 관련없는 코드들은 무시
이 코드를 따라치라는 것 아님.

그리고 다시 확인해준다 서버 켜서 되는지!!!!!!!
되면 시큐리티 사용 가능

profile
기록이 쌓이면 지식이 된다.

0개의 댓글