Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Security / November 2003

Tip: Looking for answers? Try searching our database.

LinkDemand equivalent in Java?

Thread view: 
Abdullah Kauchali - 23 Nov 2003 09:05 GMT
I have two classes from two different packages:

Package1.Class1.myMethod1()

and

Package2.Class2.myMethod2()

I would like to ensure that myMethod2() can *ONLY* be invoked by
myMethod1().

If myMethod2() is invoked directly from any *other* source, it should raise
a security exception.

What is the most efficient/practical method of doing this in Java without
doing a complete "stack walk" from myMethod2() (so, only one stack
inspection up should be sufficient)?

(In .NET this is implemented by something called LinkDemand where a complete
stack walk is avoided and only the immediate caller's activities are
inspected:
http://tinyurl.com/w6js).  There has to be something like this in Java.

Kind regards

Abdullah
Michael Amling - 23 Nov 2003 20:04 GMT
> I have two classes from two different packages:
>
[quoted text clipped - 13 lines]
> doing a complete "stack walk" from myMethod2() (so, only one stack
> inspection up should be sufficient)?

  If you have control of the source of Class1, not just Class2, you can
use serialization on a private object. Note: myMth2 accepts (recursive)
calls from any methods that it calls.

package pkg1;
import pkg2.Cls2;
public final class Cls1 {
  private Object srlzr=new Object();
  void myMth1(Cls2 whom) {
    ...
    synchronized(srlzr) {
      // Only pkg1.Cls1.myMth1 synchronizes on srlzr.
      whom.myMth2(this, ...);
    }
    ...
  }
  public void isItReallyYou() {
    // Throws Exception if not synchronized on srlzr.
    // If caller synchronized on srlzr, does nothing.
    srlzr.notify();
  }
}
--------------------
package pkg2;
import pkg1.Cls1;
public class Cls2 {
  public void myMth2(Cls1 which, ...) {
    // isItReallyYou throws an Exception unless myMth2
    // was called from pkg1.Cls1.myMth1.
    try {
      which.isItReallyYou();
    } catch (IllegalMonitorStateException m) {
      throw SecurityException();
    }
    ...
  }
}

--Mike Amling


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.