星期四, 八月 07, 2008

JSF 访问控制Access Control方法

1.思路,扩展JSF提供的JAAS验证和Navigator 来定制满足自己要求的方法

JSF对安全的支持,是通过web.xml里JAAS相关申明和faces-config.xml里的导航规则说明,
以及在jsp或JSF页面里的相关 rendered标志的控制来做到。
也是 一个MVC的结构.
A.扩展自己的class (Control)
B.配置文件声明(web.xml,faces-config.xml) (Model)
C.jsp或JSF页面里的引用. (View)

web.xml里申明使用的导航配置文件,可以指定多个,用逗号,分开不同的配置文件。除了默认的faces-config.xml意外。
web.xml:
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml,/WEB-INF/faces-beans.xml</param-value>
</context-param>
一个技巧,定义一个网站或一个目录使用的导航规则,使用符号"*",如下
<navigation-rule> </navigation-rule>                        
<from-view-id>*</from-view-id>
<navigation-case> </navigation-case>
<from-outcome>globalhelp</from-outcome>
<to-view-id>/menu/generalHelp.jsp</to-view-id>



在JSP页面使用在faces-config.xml里定义的导航规则:
首先定义一个导航规则:
<navigation-rule>
<from-view-id>/pages/inputname.jsp</from-view-id>
<navigation-case>
<from-outcome><span style="font-weight: bold; color: rgb(255, 0, 0);">sayHello</span></from-outcome>
<to-view-id>/pages/anotherhello.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{GetNameBean.helloAction}</from-action>
<from-outcome>sayHello</from-outcome>
<to-view-id>/pages/hello.jsp</to-view-id>
</navigation-case>

</navigation-rule>

<h:commandbutton id="submit" action="sayHello" value="Submit">
sayHello就是在faces-config.xml里定义的。

http://sunxacml.sourceforge.net/faq.html
http://www.oasis-open.org/committees/xacml/