-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountServer.java
More file actions
86 lines (74 loc) · 2.39 KB
/
AccountServer.java
File metadata and controls
86 lines (74 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.*;
import java.util.Vector;
public class AccountServer implements Manager
{
static int port = 1576;
static String address = "74.72.221.183";
static Registry registry;
static Vector<Account> accountVector = new Vector<Account>();
Vector<Account> myAccountVector = accountVector;
//add the admin
public AccountServer() throws RemoteException
{
super();
}
public int connect(String userName, String password) throws RemoteException
{
System.out.println("In connect method");
if((userName.equals("admin")) && (password.equals("admin")))
return 2;
//create an account for comparison
Account tempAccount = new Account( userName, password);
for(int i = 0; i < accountVector.size(); i++)
{
if(tempAccount.compareTo(accountVector.elementAt(i)) == 0)
return 1;
}
return 0;
}
public void changePassword(String userName, String oldPass, String newPass) throws RemoteException
{
//create an account for comparison
Account tempAccount = new Account( userName, oldPass);
for(int i = 0; i < accountVector.size(); i++)
{
if(tempAccount.compareTo(accountVector.elementAt(i)) == 0)
{
accountVector.remove(i);
accountVector.add(new Account(userName, newPass));
accountVector.elementAt(i).password = newPass;
break;
}
}
}
public void createAccount(String userName, String password) throws RemoteException
{
System.out.println("In createAccount method");
Account newAccount = new Account(userName, password);
accountVector.add(newAccount);
}
public static void main(String args[])
{
accountVector.add(new Account("admin", "admin"));
System.setProperty("sun.rmi.transport.tcp.responseTimeout", "900000");
System.setProperty("java.security.policy","file:/Users/eliehass/Documents/CS 344/RMI/bin/myPolicy.java.policy");
if(System.getSecurityManager() == null)
{
System.setSecurityManager(new SecurityManager());
}
try{
Manager server = new AccountServer();
Manager stub = (Manager) UnicastRemoteObject.exportObject(server, port);
System.out.println("created admin");
registry = LocateRegistry.createRegistry(port);
System.out.println("created registry");
registry.rebind("AccountServer", stub);
System.out.println("rebinded registry");
}catch(RemoteException ex){
ex.printStackTrace();
}
}
}