トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS

Java:SpringSecurityの事始め のバックアップ(No.1)


Java:SpringSecurity?の事始め

SpringSecurity?の事始めです。

SpringMVCを知っている前提です。

デフォルトの認証画面が出るまで

以下の3つのファイルを編集、作成します。

  • pom.xml
  • applicationCntext.xml
  • applicationScurity.xml(新規作成)
  • web.xml

それぞれのファイルの編集内容を見ていきます。

まず、pom.xmlにSpringSecurity?の依存関係を追加します。

  • pom.xml
           <!-- Security -->
           <dependency>
               <groupId>org.springframework.security</groupId>
               <artifactId>spring-security-core</artifactId>
               <version>3.1.0.RELEASE</version>
           </dependency>
           <dependency>
               <groupId>org.springframework.security</groupId>
               <artifactId>spring-security-web</artifactId>
               <version>3.1.0.RELEASE</version>
           </dependency>
           <dependency>
               <groupId>org.springframework.security</groupId>
               <artifactId>spring-security-config</artifactId>
               <version>3.1.0.RELEASE</version>
           </dependency>

次に、applicationScurity.xmlを作成し、以下の内容を追記します。

?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/beans
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-3.1.xsd">
 
    <http auto-config="true">
        <intercept-url pattern="/**" access="ROLE_USER" />
    </http>
 
    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="test" password="test" authorities="ROLE_USER" />
            </user-service>
        </authentication-provider>
    </authentication-manager>

</beans:beans>

次に、web.xmlのContext.xmlの設定の読み込み設定にapplicationSecurity.xmlを追加します。

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
            classpath:applicationContext.xml classpath:applicationSecurity.xml
        </param-value>
	</context-param>

また、同じくweb.xmlにSpringSecurity?のfilter設定等を追加します。