您可以在这里快速查找:


 
您的位置: 编程学习 > java教程 > 200511
文章分类

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02

Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

VB编程
2006: 02

Asp编程
2005: 11 12
2006: 01 02

C++/VC
2005: 10 11 12
2006: 01 02

Delphi
2005: 12
2006: 01 02

其它

 本文章适合所有读者

jboss4+ejb3下使用JAAS

hongbo781202

我们知道,JAAS包括了Authentication和Authorization,下面我们分别看看:

Authentication分析如下:

1)类的annotate如下
@SecurityDomain("other")
public class CalculatorBean implements Calculator
这样将从users.properties中读取Authentication信息:
kabir=validpassword

2)使用的jboss类如下:
import org.jboss.security.SecurityAssociation;
import org.jboss.security.SimplePrincipal;

3)SimplePrincipal用来设置验证原则:
SecurityAssociation.setPrincipal(new SimplePrincipal("kabir"));

4)SecurityAssociation用来根据原则进行验证: 
SecurityAssociation.setCredential("invalidpassword".toCharArray());

5)验证不通过,会抛exception

Authorization分析如下:

1)方法中指明角色
@MethodPermissions({"teacher"})
public int divide(int x, int y)
{
    return x / y;
}
  
2)roles.properties中设置角色
kabir=student

3)运行中判断权限,并提示:
[java] Insufficient method permissions, principal=kabir, interface=org.jboss.ejb3.EJBContainerInvocation, requiredR
oles=[teacher], principalRoles=[student]