Use JAAS in jboss4 + ejb3

Source: Internet
Author: User
Tags jboss

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.