Using Jaas under JBOSS4+EJB3

Source: Internet
Author: User
Tags throw exception jboss

We know that Jaas includes authentication and authorization, and here's a look at each of the following:

Authentication analysis is as follows:

1) The annotate of the class are as follows

@SecurityDomain ("other")

public class Calculatorbean implements Calculator

This will read the authentication information from the 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 the validation principle:

Securityassociation.setprincipal (New Simpleprincipal ("Kabir"));

4) Securityassociation is used to verify according to the principle:

Securityassociation.setcredential ("Invalidpassword". ToCharArray ());

5) Verification does not pass, will throw exception

Authorization analysis is as follows:

1) The role specified in the method

@MethodPermissions ({"Teacher"})

public int divide(int x, int y)
{
return x / y;
}

2) Setting roles in Roles.properties

Kabir=student

3 Run the right to judge, and prompted:

[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.