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 / March 2006

Tip: Looking for answers? Try searching our database.

Restricting package access when using reflection/casting

Thread view: 
Stu - 03 Mar 2006 16:32 GMT
Here's a scenario.. I have the following interface:

===============================

package com.mypublicpackage;

public interface MyInterface {
    public void foo();
}

===============================

and the following class:

===============================

package com.myprivatepackage;

public class MyClass implements com.mypublicpackage.MyInterface {
   public void foo() {}
   public void bar() {}
}

===============================

I have a method in another class that returns a reference to
MyInterface, eg:

package com.mypublicpackage;

public class MyImplementation {
   public MyInterface getMyInterface() { return new
com.myprivatepackage.MyClass(); }
}

I want to protect applications (loaded with my class loader) from
accessing anything directly in com.myprivatepackage. So if I call
MyImplementation.getMyInterface() then I should NOT be able to cast
MyInterface to MyClass or use reflection to call MyClass.bar() without
getting an AccessControlException etc.

I have my own SecurityManager and Policy implementation so is it just a
question of adding "com.myprivatepackage." to the package.access line
in java.security or is there more to it than that?

Thanks,

Stu
shotwave@gmail.com - 04 Mar 2006 10:15 GMT
this problem can be solved in a number of ways. For example:
you can achieve this by using a DynamicProxy
(http://java.sun.com/j2se/1.5.0/docs/guide/reflection/proxy.html) that
would be implementing MyInterface by means of dynamically (in runtime)
delegating it's calls to MyClass instance. In that case
MyImplmenetation should return this proxy, which wont be downcastable
to MyClass.


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.