회사는 정말 싫어욧

http://websystique.com/spring-security/spring-security-4-hello-world-annotation-xml-example/ 참고




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>

<!-- 인코딩 필터만 추가!!! -->

<filter>

<filter-name>encodingFilter</filter-name>

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

<init-param>

<param-name>encoding</param-name>

<param-value>UTF-8</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>encodingFilter</filter-name>

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

</filter-mapping>



root-context (namespace security 체크)


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

        <security:intercept-url pattern="/" access="permitAll" />

        <security:intercept-url pattern="/home" access="permitAll" />

        <security:intercept-url pattern="/admin**" access="hasRole('ADMIN')" />

        <security:intercept-url pattern="/dba**" access="hasRole('ADMIN') or hasRole('DBA')" />

        <security:form-login  authentication-failure-url="/Access_Denied" />

    </security:http>

  

    <security:authentication-manager >

        <security:authentication-provider>

            <security:user-service>

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

                <security:user name="admin" password="root123" authorities="ROLE_ADMIN" />

                <security:user name="dba"   password="root123" authorities="ROLE_ADMIN,ROLE_DBA" />

            </security:user-service>

        </security:authentication-provider>

    </security:authentication-manager>


pom.xml

<properties>

<org.springframework-version>4.1.6.RELEASE</org.springframework-version>

<springsecurity-version>4.0.1.RELEASE</springsecurity-version>

</properties>


<dependency>

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

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

            <version>${springsecurity-version}</version>

        </dependency>

        <dependency>

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

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

            <version>${springsecurity-version}</version>

        </dependency>