Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Applet Security issue

  1. #1
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Applet Security issue

    Hey Friends,

    I have an issue in developing a applet whose purpose is to read xml file and show it in to applet.

    For that purpose i was trying to write a program which contains an Text box and a XML read function which read xml file and then set content to Text box.

    What i had done is:

    I had created a jar file consisting of the following files

    jar cfv MyAppletJar.jar DemoTest.class Company.xml

    1) Applet class

    import javax.swing.*;
    import java.io.File;
    import java.awt.*;
     
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
     
     
    public class DemoTest extends JApplet{	
     
     
    	JTextField tf;
     
    	public void init(){
     
    		try {
                		tf = new JTextField(20);
    					add(tf);
    					System.out.println(DemoTest.createTestX("Company.xml"));
     
     
                     } catch (Exception e) { 
                                    System.err.println("createGUI didn't complete successfully"+e);
                     }
     
    	}
     
           public static  String createTestX(String filePath) {
     
                try {
                          File file = new File(filePath);
                          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                          DocumentBuilder db = dbf.newDocumentBuilder();
                          Document doc = db.parse(file);
                         doc.getDocumentElement().normalize();
                          System.out.println("Root element " + doc.getDocumentElement().getNodeName());
                          NodeList nodeLst = doc.getElementsByTagName("employee");
                          System.out.println("Information of all employees");
                          return doc.getDocumentElement().getNodeName();
                 } catch (Exception e) {
                          System.out.println("File Reading error");
                          e.printStackTrace();
            }
     
          return null;
     }
     
     
    }

    2) Xml file


     
    <?xml version="1.0"?>
    <company>
    	<employee>
    		<firstname>Tom</firstname>
    		<lastname>Cruise</lastname>
    	</employee>
    	<employee>
    		<firstname>Paul</firstname>
    		<lastname>Enderson</lastname>
    	</employee>
    	<employee>
    		<firstname>George</firstname>
    		<lastname>Bush</lastname>
    	</employee>
    </company>

    after this i had created an html page embed with applet tag to embed applet.

    <HTML>
    <Head>
    <Title>Test XML </Title>
    <Body>
     
    <APPLET CODE="DemoTest.class" width="100" height="100" archive="MyAppletJar.jar">
    </APPLET>
     
    </Body>
    </HTML>


    But its throwing Java.security.accesscontrolException

    I can understand the problem in reading file from client system , but the file is available within the same jar file in which applet class is available .

    Now i m not getting what to do


    Please help me out.
    Thanks and Regards
    Dan Brown

    Common Java Mistakes


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,541
    My Mood
    Hungover
    Thanks
    145
    Thanked 648 Times in 553 Posts

    Default Re: Applet Security issue

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: Applet Security issue

    Sorry , i already gone through that tutorial but not getting any thing.
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,541
    My Mood
    Hungover
    Thanks
    145
    Thanked 648 Times in 553 Posts

    Default Re: Applet Security issue

    What are you confused about? That tutorial contains example code that loads an image file. It shouldn't be too hard to extrapolate that to load any kind of file.

    If you still aren't sure, then don't be afraid to print out or display the values returned by the methods (there aren't many) discussed in that tutorial.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Question Re: Applet Security issue

    Error message while reading

    java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
    as i read in Code ranch i need to specify permissions to the applet.

    can u please tell what permissions i need to write in policy files.

    I had written one

    grant {
     
      permission java.io.FilePermission 
    	"message.xmlt", "read,write";
    };
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,358
    Thanks
    182
    Thanked 834 Times in 777 Posts
    Blog Entries
    5

    Default Re: Applet Security issue

    Applets have security constraints when doing certain tasks. Sign the applet to remove these constraints. Here's a step by step example: How to sign an applet

Similar Threads

  1. want to implement security key feature in the software
    By javasabin in forum Member Introductions
    Replies: 2
    Last Post: January 8th, 2011, 01:52 AM
  2. sign XML with WS-Security
    By splendes in forum Java SE APIs
    Replies: 1
    Last Post: October 6th, 2010, 09:49 AM
  3. Applet Security Warning & Class Loaders
    By tess in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 2nd, 2010, 02:41 PM
  4. Security in Server
    By madhu_sushmi in forum Java Servlet
    Replies: 6
    Last Post: May 17th, 2010, 03:07 PM
  5. Jar File Security
    By Symbols in forum Java Theory & Questions
    Replies: 1
    Last Post: February 28th, 2010, 10:48 PM