Check permission for client request and check in the policy file in java (socket)











up vote
0
down vote

favorite












I have 5 client classes and a server class (mutilthread). I have set the policy file through setProperty method but I'm not sure how to implement. I tried with check permission but it did not work for me. Is there any way that I can implement to check permission for which client has access and who does not based on the policy file?



Policy file



/* AUTOMATICALLY GENERATED ON Thu Nov 08 19:52:58 GST 2018*/
/* DO NOT EDIT */

grant{
permission java.io.FilePermission"D:\Uni\System security\Client
Server Example\ClientServerExample\src\javaapplication2\abc.txt",
"read",signedBy"client1";

permission java.io.FilePermission"D:\Uni\System security\Client Server Example\ClientServerExample\src\javaapplication2\abc.txt","write",signedBy"client2";

};


eg: client1 has access to everything



client2 can only write



client 3 can only read



Server code



public class Server {

@SuppressWarnings("resource")
public static void main( String args ) throws IOException, InterruptedException
{
ServerSocket socket = null;
DataInputStream in;
PrintStream out;
Socket clientSocket1 = null;

System.setProperty( "java.security.policy", "file:/C:/Users/Ali/Desktop/java.policy" );

while ( true )
{
socket = new ServerSocket( 285 );
System.out.println( "Server is Awaiting" );
clientSocket1 = socket.accept();

in = new DataInputStream( ( clientSocket1 ).getInputStream() );//read from client1
BufferedReader fileRead = new BufferedReader( new InputStreamReader( in ) );
String fname = fileRead.readLine();

try
{

BufferedReader contentRead = new BufferedReader( new FileReader( fname ) );
out = new PrintStream( clientSocket1.getOutputStream() );//write to client1
PrintWriter pwrite = new PrintWriter( out, true );

String str;
while ( ( str = contentRead.readLine() ) != null )
{
pwrite.println( str ); // sending each line to client
}

}
catch ( SecurityException e )
{
}
Multi t = new Multi( clientSocket1 );
t.start();
Thread.sleep( 2000 );
socket.close();
}
}}









share|improve this question




























    up vote
    0
    down vote

    favorite












    I have 5 client classes and a server class (mutilthread). I have set the policy file through setProperty method but I'm not sure how to implement. I tried with check permission but it did not work for me. Is there any way that I can implement to check permission for which client has access and who does not based on the policy file?



    Policy file



    /* AUTOMATICALLY GENERATED ON Thu Nov 08 19:52:58 GST 2018*/
    /* DO NOT EDIT */

    grant{
    permission java.io.FilePermission"D:\Uni\System security\Client
    Server Example\ClientServerExample\src\javaapplication2\abc.txt",
    "read",signedBy"client1";

    permission java.io.FilePermission"D:\Uni\System security\Client Server Example\ClientServerExample\src\javaapplication2\abc.txt","write",signedBy"client2";

    };


    eg: client1 has access to everything



    client2 can only write



    client 3 can only read



    Server code



    public class Server {

    @SuppressWarnings("resource")
    public static void main( String args ) throws IOException, InterruptedException
    {
    ServerSocket socket = null;
    DataInputStream in;
    PrintStream out;
    Socket clientSocket1 = null;

    System.setProperty( "java.security.policy", "file:/C:/Users/Ali/Desktop/java.policy" );

    while ( true )
    {
    socket = new ServerSocket( 285 );
    System.out.println( "Server is Awaiting" );
    clientSocket1 = socket.accept();

    in = new DataInputStream( ( clientSocket1 ).getInputStream() );//read from client1
    BufferedReader fileRead = new BufferedReader( new InputStreamReader( in ) );
    String fname = fileRead.readLine();

    try
    {

    BufferedReader contentRead = new BufferedReader( new FileReader( fname ) );
    out = new PrintStream( clientSocket1.getOutputStream() );//write to client1
    PrintWriter pwrite = new PrintWriter( out, true );

    String str;
    while ( ( str = contentRead.readLine() ) != null )
    {
    pwrite.println( str ); // sending each line to client
    }

    }
    catch ( SecurityException e )
    {
    }
    Multi t = new Multi( clientSocket1 );
    t.start();
    Thread.sleep( 2000 );
    socket.close();
    }
    }}









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have 5 client classes and a server class (mutilthread). I have set the policy file through setProperty method but I'm not sure how to implement. I tried with check permission but it did not work for me. Is there any way that I can implement to check permission for which client has access and who does not based on the policy file?



      Policy file



      /* AUTOMATICALLY GENERATED ON Thu Nov 08 19:52:58 GST 2018*/
      /* DO NOT EDIT */

      grant{
      permission java.io.FilePermission"D:\Uni\System security\Client
      Server Example\ClientServerExample\src\javaapplication2\abc.txt",
      "read",signedBy"client1";

      permission java.io.FilePermission"D:\Uni\System security\Client Server Example\ClientServerExample\src\javaapplication2\abc.txt","write",signedBy"client2";

      };


      eg: client1 has access to everything



      client2 can only write



      client 3 can only read



      Server code



      public class Server {

      @SuppressWarnings("resource")
      public static void main( String args ) throws IOException, InterruptedException
      {
      ServerSocket socket = null;
      DataInputStream in;
      PrintStream out;
      Socket clientSocket1 = null;

      System.setProperty( "java.security.policy", "file:/C:/Users/Ali/Desktop/java.policy" );

      while ( true )
      {
      socket = new ServerSocket( 285 );
      System.out.println( "Server is Awaiting" );
      clientSocket1 = socket.accept();

      in = new DataInputStream( ( clientSocket1 ).getInputStream() );//read from client1
      BufferedReader fileRead = new BufferedReader( new InputStreamReader( in ) );
      String fname = fileRead.readLine();

      try
      {

      BufferedReader contentRead = new BufferedReader( new FileReader( fname ) );
      out = new PrintStream( clientSocket1.getOutputStream() );//write to client1
      PrintWriter pwrite = new PrintWriter( out, true );

      String str;
      while ( ( str = contentRead.readLine() ) != null )
      {
      pwrite.println( str ); // sending each line to client
      }

      }
      catch ( SecurityException e )
      {
      }
      Multi t = new Multi( clientSocket1 );
      t.start();
      Thread.sleep( 2000 );
      socket.close();
      }
      }}









      share|improve this question















      I have 5 client classes and a server class (mutilthread). I have set the policy file through setProperty method but I'm not sure how to implement. I tried with check permission but it did not work for me. Is there any way that I can implement to check permission for which client has access and who does not based on the policy file?



      Policy file



      /* AUTOMATICALLY GENERATED ON Thu Nov 08 19:52:58 GST 2018*/
      /* DO NOT EDIT */

      grant{
      permission java.io.FilePermission"D:\Uni\System security\Client
      Server Example\ClientServerExample\src\javaapplication2\abc.txt",
      "read",signedBy"client1";

      permission java.io.FilePermission"D:\Uni\System security\Client Server Example\ClientServerExample\src\javaapplication2\abc.txt","write",signedBy"client2";

      };


      eg: client1 has access to everything



      client2 can only write



      client 3 can only read



      Server code



      public class Server {

      @SuppressWarnings("resource")
      public static void main( String args ) throws IOException, InterruptedException
      {
      ServerSocket socket = null;
      DataInputStream in;
      PrintStream out;
      Socket clientSocket1 = null;

      System.setProperty( "java.security.policy", "file:/C:/Users/Ali/Desktop/java.policy" );

      while ( true )
      {
      socket = new ServerSocket( 285 );
      System.out.println( "Server is Awaiting" );
      clientSocket1 = socket.accept();

      in = new DataInputStream( ( clientSocket1 ).getInputStream() );//read from client1
      BufferedReader fileRead = new BufferedReader( new InputStreamReader( in ) );
      String fname = fileRead.readLine();

      try
      {

      BufferedReader contentRead = new BufferedReader( new FileReader( fname ) );
      out = new PrintStream( clientSocket1.getOutputStream() );//write to client1
      PrintWriter pwrite = new PrintWriter( out, true );

      String str;
      while ( ( str = contentRead.readLine() ) != null )
      {
      pwrite.println( str ); // sending each line to client
      }

      }
      catch ( SecurityException e )
      {
      }
      Multi t = new Multi( clientSocket1 );
      t.start();
      Thread.sleep( 2000 );
      socket.close();
      }
      }}






      java sockets access-control






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 10:26









      Gayan Mettananda

      30116




      30116










      asked Nov 9 at 9:59









      user13412

      73




      73





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53223542%2fcheck-permission-for-client-request-and-check-in-the-policy-file-in-java-socket%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53223542%2fcheck-permission-for-client-request-and-check-in-the-policy-file-in-java-socket%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Schultheiß

          Verwaltungsgliederung Dänemarks

          Liste der Kulturdenkmale in Wilsdruff