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();
}
}}
java sockets access-control
add a comment |
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();
}
}}
java sockets access-control
add a comment |
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();
}
}}
java sockets access-control
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
java sockets access-control
edited Nov 9 at 10:26
Gayan Mettananda
30116
30116
asked Nov 9 at 9:59
user13412
73
73
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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