We know that JAAS includes authentication and authorization. Let's take a look at them separately:
The authentication analysis is as follows:
1) The annotate of the class is as follows:
@ Securitydomain ("other ")
Public class calculatorbean implements Calculator
In this way, the authentication information will be read from users. properties:
Kabir = validpassword
2) The JBoss class used is as follows:
Import org. JBoss. Security. securityassociation;
Import org. JBoss. Security. simpleprincipal;
3) simpleprincipal is used to set verification principles:
Securityassociation. setprincipal (New simpleprincipal ("Kabir "));
4) securityassociation is used for verification based on principles:
Securityassociation. setcredential ("invalidpassword". tochararray ());
5) if the verification fails, an exception is thrown.
Authorization analysis:
1) specify the role in the Method
@ Methodpermissions ({"teacher "})
Public int divide (int x, int y)
{
Return x/y;
}
2) Set roles in roles. Properties
Kabir = student
3) Check the permission during running and prompt:
[Java] insufficient method permissions, Principal = Kabir, interface = org. JBoss. ejb3.ejbcontainerinvocation, requiredr
Oles = [Teacher], principalroles = [Student]