Java:SpringSecurityの事始め のバックアップ(No.2)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- ソース を表示
- Java:SpringSecurityの事始め へ行く。
- 1 (2013-12-22 (日) 14:37:25)
- 2 (2013-12-22 (日) 18:27:25)
- 3 (2013-12-23 (月) 16:52:29)
Java:SpringSecurity?の事始め †
SpringSecurity?の事始めです。
SpringMVCを知っている前提です。
デフォルトの認証画面が出るまで †
以下の3つのファイルを編集、作成します。
- pom.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を作成し、以下の内容を追記します。
- 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を追加します。
- web.xml
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:applicationContext.xml classpath:applicationSecurity.xml </param-value> </context-param>
また、同じくweb.xmlにSpringSecurity?のfilter設定等を追加します。
- web.xml
<!-- SpringSecurityのフィルター設定 --> <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>
これで、SpringSecurity?の標準のログイン画面が出ます。