forked from loopccoew/Buffer-4.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigitalIdentityManagementSystem.java.java
225 lines (195 loc) · 9.32 KB
/
DigitalIdentityManagementSystem.java.java
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.regex.*;
public class DigitalIdentityManagementSystem {
// User data storage
private Map<String, UserData> userDataTable;
// Authentication credential storage
private Map<String, AuthenticationCredential> authCredentialTable;
// Permissions management
private Map<String, List<String>> resourcePermissions;
public DigitalIdentityManagementSystem() {
userDataTable = new HashMap<>();
authCredentialTable = new HashMap<>();
resourcePermissions = new HashMap<>();
}
// sign up
public void registerUser(String name, String email, String phone, String password) {
// Check if the user already exists
if (userDataTable.containsKey(email)) {
System.out.println("User already exists.");
return;
}
UserData userData = new UserData(name, email, phone);
// Store the user data in the user data table
userDataTable.put(email, userData);
// Hash the password and store the authentication credential in the auth-credential table
AuthenticationCredential authCredential = new AuthenticationCredential(email, password);
authCredentialTable.put(email, authCredential);
System.out.println(name+" , you have registered successfully.");
}
// Log in an existing user
public boolean login(String email, String password) {
// Check if the user exists
if (!userDataTable.containsKey(email)) {
System.out.println("User does not exist.");
return false;
}
// Retrieve the authentication credential from the auth credential table
AuthenticationCredential authCredential = authCredentialTable.get(email);
if (!(authCredential.getPassword()).equals(password)) {
System.out.println("Invalid password.");
return false;
}
System.out.println("Login successful.");
return true;
}
// Grant access to a resource---give it to manager,ceo
public void grantAccess(String email, String resourceName) {
// Check if the user and resource exist
if (!userDataTable.containsKey(email)) {
System.out.println("User does not exist.");
return;
}
if (!resourcePermissions.containsKey(resourceName)) {
resourcePermissions.put(resourceName, new LinkedList<>());
}
// Add the user to the linked list of users who have permission to access the resource
List<String> users = resourcePermissions.get(resourceName);
if (!users.contains(email)) {
users.add(email);
}
System.out.println("Access granted to " + resourceName + " for " + email);
}
private void permissons(String email){
List<String>manager=new LinkedList<>();
manager.add( "project Management");
manager.add("grant-access");
manager.add("Team management");
manager.add("Resource allocation");////here we can call grant access
manager.add("Technical expertise");
List<String>CEO=new LinkedList<>();
CEO.add("grant-access");
CEO.add( "Strategic planning");
CEO.add("Financial management");
CEO.add("Human resources");
CEO.add("Stakeholder management");
CEO.add("Public relations");
List<String>HR=new LinkedList<>();
HR.add( "Recruitment and staffing");
HR.add("Employee on-boarding and training");
HR.add("Performance management and employee development");
HR.add("Employee relations");
HR.add("Workplace policies and procedures");
List<String>projectLead=new LinkedList<>();
projectLead.add( "Team Management");
projectLead.add("Planning and Strategy");
projectLead.add("Budgeting and Resource");
projectLead.add("Reporting of project");
List<String>softwareEngineer=new LinkedList<>();
softwareEngineer.add( "Requirements gathering");
softwareEngineer.add("Design software architecture");
softwareEngineer.add("Development of program");
softwareEngineer.add("Quality assurance");
if(email.contains("manager")) {
System.out.println("************ MANAGER SECTION ************");
System.out.println("Manager has access to following resources :\n");
for(int i=0;i<manager.size();i++) {
System.out.println((i+1)+"."+manager.get(i));
}
}
else if(email.contains("ceo")) {
System.out.println("************ CEO SECTION ************");
System.out.println("CEO has access to following resources :\n");
for(int i=0;i<CEO.size();i++) {
System.out.println((i+1)+"."+CEO.get(i));
}
}
else if(email.contains("hr")) {
System.out.println("************ HR SECTION ************");
System.out.println("HR has access to following resources :\n");
for(int i=0;i<HR.size();i++) {
System.out.println((i+1)+"."+HR.get(i));
}
}
else if(email.contains("projectlead")) {
System.out.println("************ PROJECT LEAD ************");
System.out.println("ProjectLead has access to following resources :\n");
for(int i=0;i<projectLead.size();i++) {
System.out.println((i+1)+"."+projectLead.get(i));
}
}
else if(email.contains("sde")) {
System.out.println("************ SDE SECTION ************");
System.out.println("Software Engineer has access to following resources :\n");
for(int i=0;i<softwareEngineer.size();i++) {
System.out.println((i+1)+"."+softwareEngineer.get(i));
}
}
return;
}
// Main method
public static void main(String[] args) {
DigitalIdentityManagementSystem system = new DigitalIdentityManagementSystem();
Scanner sc = new Scanner(System.in);
int choice=0;
while (choice!=3) {
System.out.println("************ WELCOME TO PROBUILD SOFTWARE LIMITED COMPANY ************");
System.out.println("\nEnter a command: \n1.sign in\n2.login\n3.exit");
choice=sc.nextInt();
switch(choice) {
case 1:
System.out.println("************ SIGN IN ************");
System.out.println("enter your name");
String name=sc.next();
System.out.println("enter your phone number");
String phone =sc.next();
do{
if(phone.length()!=10) {
System.out.println("Invalid Phone number\nPlease enter valid Phone number");
phone =sc.next();
}
}while(phone.length()!=10);
System.out.println("enter your email");
String empemail=sc.next();
do {
if ((!empemail.contains("@") || !empemail.contains(".com")) || (!empemail.contains("manager") && !empemail.contains("hr") && !empemail.contains("ceo") && !empemail.contains("SDE") && !empemail.contains("projectlead"))) {
System.out.println("Invalid Email adrress\nPlease enter valid email address :");
empemail = sc.next();
}
}while((!empemail.contains("@") || !empemail.contains(".com")) || (!empemail.contains("manager") && !empemail.contains("hr") && !empemail.contains("ceo") && !empemail.contains("SDE") && !empemail.contains("projectlead")));
System.out.println("enter your password");
String emppassword=sc.next();
do{
if(emppassword.length()<4 || emppassword.length()>15) {
System.out.println("Invalid password\nPlease enter password having length between 4 to 15");
emppassword =sc.next();
}
}while(emppassword.length()<4 || emppassword.length()>15);
system.registerUser(name, empemail, phone, emppassword);
break;
case 2:
System.out.println("************ LOG IN ************");
System.out.println("enter your email");
String email=sc.next();
System.out.println("enter your password");
String password=sc.next();
if(system.login(email,password)) {
system.permissons(email);
}
break;
case 3:
System.out.println("Exiting...");
break;
default:
break;
}
}
}
}