반응형

프레임워크 : 특정한 목적에 맞게 프로그래밍을 쉽게 하기 위한 약속, 라이브러리와 다르게 개발 패턴 등을 프레임워크가 의존하여 정의(InversionOfControl)

 

Spring Framework : 자바 언어를 기반으로, 다양한 어플리케이션을 제작하기 위한 약속된 일종의 프로그래밍 틀 -> 프레임워크

* 내가 생각하기에 우선적으로 알아야할 것

1) 스프링을 알기위해서 MVC, MODEL1에 대한 개념이 선행 되어야함
- 기존 mvc1 개념으로 jsp나 서블릿에 대해서 선행되어야함

2) DI(Dependency Injection)와 IOC컨테이너 = spring이라고 할 정도로 핵심 개념임
- 스프링 프레임워크이 핵심 기능, 붕어빵에 단팥빵같은 존재!

 

3) A객체는 B/C 객체에 의존한다

  ->(방법1) A객체가 B/C객체를 직접 생성한다.

  ->(방법2) B/C객체 외부에 생성하여 A객체에 넣어준다.=> 이것이 Spring기법 -> IoC개념이라고 볼수있음

즉, 구현해보면 알겠지만, java 어플리케이션 처럼 main흐름을 main문에서 하는게 아니라, 프레임워크에서 가져가서 주체가 된다.

 

4) 인터페이스를 통한 부품화
- 스프링에서 제공하는 인터페이스등을 어떻게 정의하고 사용하느냐가 핵심

=> 결국 스프링이란? 부품을 생성하고 조립하는 라이브러리 집합체라고 할 수 있습니다.

728x90
반응형

1. 스프링 시큐리티란?

스프링 시큐리티는 스프링 기반의 어플리케이션의 보안(인증과 권한)을 담당하는 프레임워크이다. 만약 스프링시큐리티를 사용하지 않았다면, 자체적으로 세션을 체크하고 redirect 등을 해야할 것이다. 스프링 시큐리티는 보안과 관련해서 체계적으로 많은 옵션들로 이를 지원해준다. spring security는 filter 기반으로 동작하기 때문에 spring MVC 와 분리되어 관리 및 동작한다. 참고로 security 3.2부터는 XML로 설정하지 않고도 자바 bean 설정으로 간단하게 설정할 수 있도록 지원한다.

여기서는 현재기준 최신버전인 스프링 4.3.18과 시큐리티 4.2.7을 가지고 진행했다.

보안관련 용어부터 정리하자

  • 접근 주체(Principal) : 보호된 대상에 접근하는 유저
  • 인증(Authenticate) : 현재 유저가 누구인지 확인(ex. 로그인)
    • 애플리케이션의 작업을 수행할 수 있는 주체임을 증명
  • 인가(Authorize) : 현재 유저가 어떤 서비스, 페이지에 접근할 수 있는 권한이 있는지 검사
  • 권한 : 인증된 주체가 애플리케이션의 동작을 수행할 수 있도록 허락되있는지를 결정
    • 권한 승인이 필요한 부분으로 접근하려면 인증 과정을 통해 주체가 증명 되어야만 한다
    • 권한 부여에도 두가지 영역이 존재하는데 웹 요청 권한, 메소드 호출 및 도메인 인스턴스에 대한 접근 권한 부여

2. spring security 의 구조

2-1. 인증관련 architecture



출처: https://sjh836.tistory.com/165 [빨간색코딩]


3. 실습

1. pom.xml 에 depencency 추가 

<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-config</artifactId>

<version>3.2.5.RELEASE</version>

</dependency>


<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-core</artifactId>

<version>3.2.5.RELEASE</version>

</dependency>


<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-web</artifactId>

<version>3.2.5.RELEASE</version>

</dependency>


<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-taglibs</artifactId>

<version>3.2.4.RELEASE</version>

</dependency>

2. web.xml > context 추가 &  filter 작성

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>

/WEB-INF/spring/root-context.xml

/WEB-INF/spring/appServlet/security-context.xml

</param-value>

</context-param>           

<filter>

        <filter-name>springSecurityFilterChain</filter-name>

        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

    </filter>

    <filter-mapping>

        <filter-name>springSecurityFilterChain</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

3. 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/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/security

http://www.springframework.org/schema/security/spring-security-3.2.xsd">


<security:http auto-config="true">

<security:form-login login-page="/loginForm.html"/>

<security:intercept-url pattern="/login.html*" access="ROLE_USER"/>

<security:intercept-url pattern="/welcome.html*" access="ROLE_ADMIN"/>

</security:http>

<security:authentication-manager>

<security:authentication-provider>

<security:user-service>

<security:user name="user" password="123" authorities="ROLE_USER"/>

<security:user name="admin" password="123" authorities="ROLE_ADMIN,ROLE_USER"/>

</security:user-service>

</security:authentication-provider>

</security:authentication-manager>


</beans>



[출처]https://seouliotcenter.tistory.com/89?category=663840

728x90

+ Recent posts