기초/spring framework2015. 7. 10. 10:03


1. http://www.mvnrepository.com 에서 security 검색해서 아래항목을 4.01버전을 받아준다 그리고 pom.xml에 추가해준다


        <!-- security core -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>4.0.1.RELEASE</version>
        </dependency>

        <!-- security web -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>4.0.1.RELEASE</version>
        </dependency>
       
        <!-- security config -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>4.0.1.RELEASE</version>
        </dependency>
       
        <!-- securty taglibs -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>4.0.1.RELEASE</version>
        </dependency>


한번씩 properties와 충돌이 나면 버전을 수정해준다


<properties>
        <java-version>1.6</java-version>
        <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
    </properties>



오류 예제


<properties>
        <java-version>1.6</java-version>
        <org.springframework-version>4.1.6.RELEASE</org.springframework-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
    </properties>






2. /SpringMVCSecurity/src/main/webapp/WEB-INF/spring/appServlet 에서 Spring Bean Configuration File로

securty-context.xml을 생성해준다






3. web.xml에 context-param애 securty-context.xml을 등록해준다




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




4. web.xml에 security 필터추가


    <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>
   





5. security-context.xml에 설정 추가


    <security:http auto-config="true">
        <security:intercept-url pattern="/login" access="ROLE_USER"/>
        <security:intercept-url pattern="/welcome" access="ROLE_ADMIN"/>
    </security:http>
   
    <security:authentication-manager>
        <security:authentication-provider>
            <security:user-service>
                <security:user name="member01" password="1234" authorities="ROLE_USER"/>
                <security:user name="admin" password="1234" authorities="ROLE_ADMIN,ROLE_USER"/>
            </security:user-service>
        </security:authentication-provider>
    </security:authentication-manager>




6. controller


@RequestMapping("/login")
    public String login(){
        return "login";
    }
   
    @RequestMapping("/welcome")
    public String welcome(){
        return "welcome";
    }


'기초 > spring framework' 카테고리의 다른 글

spring security  (0) 2015.07.10
mybatis  (0) 2015.07.08
spring utf-8 설정  (0) 2015.07.08
Spring JDBC  (0) 2015.07.06
한글처리  (0) 2015.07.02
profile 사용하기  (0) 2015.06.25
Posted by ICT 기술 블로그

댓글을 달아 주세요