![](/img/trans.png)
[英]Why does my applet get a java.security.AccessControlException: access denied (java.net.SocketPermission …), and how can I avoid it?
[英]Access denied (“java.net.SocketPermission” Error Occurred when i run my CLient Project in NetBeans
java.security.AccessControlException:訪問被拒絕(“ java.net.SocketPermission”“ 127.0.0.1:1099”“ connect,resolve”)
我的服務器端運行正常,服務器上沒有錯誤..當我運行客戶端代碼時,我拒絕了此訪問(“ java.net.SocketPermission”“ 127.0.0.1:1099”“ connect,resolve”)錯誤。
請任何專家幫助我:(
這是我的客戶代碼
/**
*
* @author saqibhussain
*/
public class ChatClient extends UnicastRemoteObject implements ChatClientIF, Runnable {
public ChatClient() throws RemoteException {
}
private ChatServerIF chat;
private String name = null;
protected ChatClient(String name, ChatServerIF chat) throws RemoteException { this.name = name;
this.chat = chat;
chat.RegisterChatClient(this);
}
public void retrieveMessage(String msg) throws RemoteException {
System.out.println(msg);
}
public void run() {
Scanner scaner = new Scanner(System.in);
String message;
while (true) {
try {
message = scaner.nextLine();
chat.broadcastMessage(name + " : " + message);
} catch (RemoteException ex) {
Logger.getLogger(ChatClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public static void main(String[] args) throws NotBoundException, MalformedURLException, RemoteException {
System.setSecurityManager(new RMISecurityManager());
try {
String url = "rmi://localhost/RMIChatServer";
ChatServerIF remoteObject = (ChatServerIF) Naming.lookup(url);
System.out.println("Got remote object");
new Thread(new ChatClient(args[0], remoteObject)).start();
} catch (Exception e) {
System.out.println(e);
}
}
}
將安全策略添加到客戶端應用程序。 您可以從此處下載示例策略: http : //www.comp.lancs.ac.uk/~weerasin/csc253/tutorials/week8code/client.policy
之后,使用以下vm參數啟動客戶端
java -Djava.security.policy==client.policy
在生產環境中要小心,因為給定的策略會授予對客戶端執行的任何操作的權限。
您已經定義了SecurityManager
但尚未授予自己足夠的權限來執行代碼。 通過-Djava.security.policy=...
啟動時,您需要編寫一個策略文件並將其指定給JVM。
或者,只需刪除安全管理器。 除非使用RMI代碼庫功能,否則不需要它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.