acegi 2.0の勉強.
今日はappfuse 2.02里acegiの配置ファイルを見ました.appfuse公式サイトを見ると、appfuse 2.02に含まれていたacegi 1.0をacegi 2.0にアップグレードしました.同じ1.0は変化が大きいより、名前もspring security 2.0に変更しました.以下は簡単な配置使用手順です.
1、最初のことは次のfilter声明をweb.xmlファイルに添付することです.
2.配置情報はすべてappication-security.xmlに入れて、名前空間を加えます.
<intercept-url pattern=「/*」access=「ROLE USER」/>
これは、私たちがアプリケーションのすべてのURLを保護したいということです.USERキャラクターのユーザーが訪問できます.
たとえば:
4、 データベースとパスワードの暗号化を指定します.
6、Session制御Acegi 2.0のsession制御は本当に簡単です.Jはまずweb.xmlにListenerを加えます.
その後、appication-security.xmlに規則を設定します.
1、最初のことは次のfilter声明をweb.xmlファイルに添付することです.
<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>
2.配置情報はすべてappication-security.xmlに入れて、名前空間を加えます.
<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-2.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.2.xsd">
...
</beans:beans>
3、次にパスで、アドレスにパーミッションを追加します.<intercept-url pattern=「/*」access=「ROLE USER」/>
これは、私たちがアプリケーションのすべてのURLを保護したいということです.USERキャラクターのユーザーが訪問できます.
たとえば:
<http auto-config="true" lowercase-comparisons="false">
<!--intercept-url pattern="/images/*" filters="none"/>
<intercept-url pattern="/styles/*" filters="none"/>
<intercept-url pattern="/scripts/*" filters="none"/-->
<intercept-url pattern="/admin/*" access="ROLE_ADMIN"/>
<intercept-url pattern="/passwordHint.html*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/>
<intercept-url pattern="/signup.html*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/>
<intercept-url pattern="/a4j.res/*.html*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/>
<!-- APF-737, OK to remove line below if you're not using JSF -->
<intercept-url pattern="/**/*.html*" access="ROLE_ADMIN,ROLE_USER"/>
<form-login login-page="/login.jsp" authentication-failure-url="/login.jsp?error=true" login-processing-url="/j_security_check"/>
<remember-me user-service-ref="userDao" key="e37f4b31-0c45-11dd-bd0b-0800200c9a66"/>
</http>
4、 データベースとパスワードの暗号化を指定します.
<authentication-provider user-service-ref="userDao">
<password-encoder ref="passwordEncoder"/>
</authentication-provider>
5、方法授権<global-method-security>
<protect-pointcut expression="execution(* *..service.UserManager.getUsers(..))" access="ROLE_ADMIN"/>
<protect-pointcut expression="execution(* *..service.UserManager.removeUser(..))" access="ROLE_ADMIN"/>
</global-method-security>
6、Session制御Acegi 2.0のsession制御は本当に簡単です.Jはまずweb.xmlにListenerを加えます.
<listener>
<listener-class>
org.springframework.security.ui.session.HttpSessionEventPublisher
</listener-class>
</listener>
その後、appication-security.xmlに規則を設定します.
<http>
<concurrent-session-control max-sessions="1" />
</http>
<http>
<concurrent-session-control max-sessions="1" exception-if-maximum-exceeded="true" />
</http>
説明:両方の構成は一回だけでユーザー登録できます.exception-if-excededはfalseとしてデフォルトです.この値は表示されます.ユーザが第二回ログインした時、前回の登録情報は全部空になりました.exception-if-maxim-exceeded=「true」の場合、システムは第二次登録を拒否します.