A question about java.policy.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    A question about java.policy.

    I want to permit the java application only to read any local file but i don't want any application to update a local file.
    Is this related to java.policy?
    Please suggest ....!
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by dmjpro
    I want to permit the java application only to read any local file but i don't want any application to update a local file.
    Is this related to java.policy?
    Please suggest ....!
    No.
    You can only control only what your Java program can read using policy files.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by r035198x
      No.
      You can only control only what your Java program can read using policy files.
      If I change something odd in java.policy then what happens?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by dmjpro
        If I change something odd in java.policy then what happens?
        Google knows

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by r035198x
          Google knows
          No no don't misunderstand me .... I want to discuss this over here instead of looking for Google.
          What I did with this file that is, i changed a line permission java.security.F ilePermission within grant block for applet to do have acces to it's local file system.
          That's why i asking about, if i want to change permission settings in java application which runs from the local except Applet code what i need to do.
          Please have a discussion over here ..this is my earnest request to all of you experts .... :-)

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            Originally posted by dmjpro
            No no don't misunderstand me .... I want to discuss this over here instead of looking for Google.
            What I did with this file that is, i changed a line permission java.security.F ilePermission within grant block for applet to do have acces to it's local file system.
            That's why i asking about, if i want to change permission settings in java application which runs from the local except Applet code what i need to do.
            Please have a discussion over here ..this is my earnest request to all of you experts .... :-)

            Sorry r035198x ... I went for details and now the picture is cleared to me. :-)

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by dmjpro
              Sorry r035198x ... I went for details and now the picture is cleared to me. :-)
              Care to share what you found out?

              Comment

              • dmjpro
                Top Contributor
                • Jan 2007
                • 2476

                #8
                Originally posted by r035198x
                Care to share what you found out?
                What you told that's right.
                The java.policy can't be changed just you can edit it through Program.
                A code snippet is given below ..
                [code=java]
                System.setSecur ityManager(new SecurityManager (){
                @Override
                public void checkWrite(Stri ng file){
                throw new SecurityExcepti on("File write not allowed..!!!");
                }
                });

                FileWriter file = new FileWriter("d:/test.txt");
                file.write("My name is Debasis Jana");
                file.close();
                [/code]
                Here i am getting the security exception.
                Now after main thread terminates the default permission set.

                Now tell me r035198x, how java.policy works ..could you tell me in details? :-)

                Comment

                • dmjpro
                  Top Contributor
                  • Jan 2007
                  • 2476

                  #9
                  Originally posted by dmjpro
                  What you told that's right.
                  The java.policy can't be changed just you can edit it through Program.
                  A code snippet is given below ..
                  [code=java]
                  System.setSecur ityManager(new SecurityManager (){
                  @Override
                  public void checkWrite(Stri ng file){
                  throw new SecurityExcepti on("File write not allowed..!!!");
                  }
                  });

                  FileWriter file = new FileWriter("d:/test.txt");
                  file.write("My name is Debasis Jana");
                  file.close();
                  [/code]
                  Here i am getting the security exception.
                  Now after main thread terminates the default permission set.

                  Now tell me r035198x, how java.policy works ..could you tell me in details? :-)
                  I come back again here.
                  Actually still it's not clear how java.policy works?
                  When it's read up..Please tell me in brief. :-)

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by dmjpro
                    I come back again here.
                    Actually still it's not clear how java.policy works?
                    When it's read up..Please tell me in brief. :-)
                    Which part is not clear? Did you read these links?
                    Link 1
                    Link 2

                    Comment

                    • dmjpro
                      Top Contributor
                      • Jan 2007
                      • 2476

                      #11
                      Originally posted by r035198x
                      Which part is not clear? Did you read these links?
                      Link 1
                      Link 2
                      There is a long story ..lolz!
                      Ok let me read then I ll ask if something remains misunderstood.

                      Comment

                      • dmjpro
                        Top Contributor
                        • Jan 2007
                        • 2476

                        #12
                        Originally posted by dmjpro
                        There is a long story ..lolz!
                        Ok let me read then I ll ask if something remains misunderstood.

                        Ok ..let's start with something.
                        When i am setting the SecurityManager like....
                        [code=java]
                        System.setSecur ityManager(new SecurityManager (){
                        //my code goes here
                        });
                        [/code]
                        It means i am simply overriding the default implementation of java policy.
                        Once I start this then how long it alives unless i set it to default SecurityManager .
                        Please explain!

                        Comment

                        • dmjpro
                          Top Contributor
                          • Jan 2007
                          • 2476

                          #13
                          Originally posted by dmjpro
                          Ok ..let's start with something.
                          When i am setting the SecurityManager like....
                          [code=java]
                          System.setSecur ityManager(new SecurityManager (){
                          //my code goes here
                          });
                          [/code]
                          It means i am simply overriding the default implementation of java policy.
                          Once I start this then how long it alives unless i set it to default SecurityManager .
                          Please explain!

                          Where are you r035198x?
                          Please Help!

                          Comment

                          • r035198x
                            MVP
                            • Sep 2006
                            • 13225

                            #14
                            Use this method instead as explained in one of those links
                            Code:
                              java -Djava.security.manager -Djava.security.policy=yourPolicy YourApp
                            It's much safer that way.

                            Comment

                            • JosAH
                              Recognized Expert MVP
                              • Mar 2007
                              • 11453

                              #15
                              Originally posted by dmjpro
                              Where are you r035198x?
                              Please Help!
                              Look what happens if you attempt to constuct a SecurityManager :

                              Originally posted by JavaDoc SecurityManager
                              If there is a security manager already installed, this method first calls the security manager's checkPermission method with the RuntimePermissi on("createSecur ityManager") permission to ensure the calling thread has permission to create a new security manager. This may result in throwing a SecurityExcepti on.
                              kind regards,

                              Jos

                              ps. and please don't yell for attention.

                              Comment

                              Working...