JAAS authorization

I am developing a JAAS module and have some questions about how authorization is done.

1)

If I use the default security manager (run the code with -Djava.security.manager), what will be checked automatically? I mean without calling any of the SecurityManager's check...() methods? Is it only when you make your own permissions you have to write something like this:

SecurityManager sm = System.getSecurityManager()

if(sm!=0){

sm.checkPermission(new MyPermission(name));

}

When you call

Subject.doAs(subj,new SomeAction());

Do you have to call the SecurityManager to check the actions you do in the SomeAction()'s run()-method? Or how does this work?

I am very confused, pleas help me. I don't see how I can make this module at independet of the application that will use it as possible.

2)

How can I make support for hierarchical roles in JAAS? I want for instance subjects with RolePrincipal "emploee" to get all the rights subjects with RolePrincipal "user" have. I know it is possible to write a large policy file or to give Subjects multiple RolePrincipals, but is there any other way?

3)

I want to be able to use wild cards in principal names in my policy file, ex:

grant SomePrincipal"hei*"{...};

I want this to mach all names that starts with "hei". How can I do that? In the equals(Object o) method in the class SomePrincipal?

[1674 byte] By [riamloa] at [2007-10-1 16:57:39]
# 1
2) og 3) If I let my Class RolePrincipal implement the com.sun.security.auth.PrincipalComparator interface in addition to the java.security.Principal interface, can I use the implies method to solve my problems?
riamloa at 2007-7-11 1:30:03 > top of Java-index,Security,Other Security APIs, Tools, and Issues...
# 2

There are already existing checks made in the runtime libraries (rt.jar). For example, java.io.FileInputStream has a check to protect against unauthorized access to files. All of these existing checks are turned on when you set the SecurityManager. And yes, you can add custom checks into your own code as you described.

As far as hierarchical roles are concerned, your best bet until more formal RBAC support is added to the default Policy implementation is to implement com.sun.security.auth.PrincipalComparator.

And I think by coincidence, I answered you question about Principal wildcarding here:

http://forum.java.sun.com/thread.jspa?threadID=640593

charlie.laia at 2007-7-11 1:30:03 > top of Java-index,Security,Other Security APIs, Tools, and Issues...
# 3
Thank you!
riamloa at 2007-7-11 1:30:03 > top of Java-index,Security,Other Security APIs, Tools, and Issues...