Revision 59502
Added by Konstantinos Triantafyllou over 3 years ago
VerificationUtils.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import com.google.gson.JsonArray; |
4 | 4 |
import com.google.gson.JsonObject; |
5 |
import eu.dnetlib.openaire.user.pojos.ManagerVerification;
|
|
5 |
import eu.dnetlib.openaire.user.pojos.RoleVerification;
|
|
6 | 6 |
import eu.dnetlib.openaire.user.utils.ManagerVerificationActions; |
7 | 7 |
import org.apache.log4j.Logger; |
8 | 8 |
import org.mitre.openid.connect.model.OIDCAuthenticationToken; |
9 | 9 |
import org.springframework.beans.factory.annotation.Autowired; |
10 | 10 |
import org.springframework.security.core.context.SecurityContextHolder; |
11 |
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
|
12 |
import org.springframework.security.crypto.password.PasswordEncoder; |
|
13 | 11 |
import org.springframework.stereotype.Component; |
14 | 12 |
|
15 | 13 |
import java.sql.Timestamp; |
16 |
import java.util.*; |
|
14 |
import java.util.Date; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Random; |
|
17 | 17 |
|
18 | 18 |
|
19 | 19 |
@Component("VerificationUtils") |
... | ... | |
25 | 25 |
@Autowired |
26 | 26 |
private ManagerVerificationActions actions; |
27 | 27 |
|
28 |
public JsonObject createInvitation(String email, String type, String entity) { |
|
28 |
public JsonObject createManagerInvitation(String email, String type, String entity) { |
|
29 |
RoleVerification roleVerification = actions.getManagerVerification(email, type, entity); |
|
30 |
if(roleVerification == null) { |
|
31 |
String id; |
|
32 |
do { |
|
33 |
id = createId(); |
|
34 |
} while (exists(id)); |
|
35 |
roleVerification = actions.addManagerVerification(id, email, type, entity, createVerificationCode(), new Timestamp(new Date().getTime())); |
|
36 |
} |
|
37 |
JsonObject invitation = new JsonObject(); |
|
38 |
invitation.addProperty("link", roleVerification.getId()); |
|
39 |
invitation.addProperty("code", roleVerification.getVerificationCode()); |
|
40 |
return invitation; |
|
41 |
} |
|
42 |
|
|
43 |
public JsonObject createMemberInvitation(String email, String type, String entity) { |
|
29 | 44 |
String id; |
30 | 45 |
do { |
31 | 46 |
id = createId(); |
32 | 47 |
} while (exists(id)); |
33 |
ManagerVerification managerVerification = actions.addVerificationEntry(id, email, type, entity, createVerificationCode(), new Timestamp(new Date().getTime())); |
|
34 |
JsonObject invitation = new JsonObject(); |
|
35 |
invitation.addProperty("link", managerVerification.getId()); |
|
36 |
invitation.addProperty("code", managerVerification.getVerificationCode()); |
|
48 |
RoleVerification roleVerification = actions.getMemberVerification(email, type, entity); |
|
49 |
if(roleVerification == null) { |
|
50 |
roleVerification = actions.addMemberVerification(id, email, type, entity, createVerificationCode(), new Timestamp(new Date().getTime())); |
|
51 |
} JsonObject invitation = new JsonObject(); |
|
52 |
invitation.addProperty("link", roleVerification.getId()); |
|
53 |
invitation.addProperty("code", roleVerification.getVerificationCode()); |
|
37 | 54 |
return invitation; |
38 | 55 |
} |
39 | 56 |
|
40 |
public void deleteRelatedVerifications(ManagerVerification managerVerification) { |
|
41 |
List<ManagerVerification> related = actions. |
|
42 |
getUserVerificationsForAnEntity(managerVerification.getEmail(), managerVerification.getType(), managerVerification.getEntity()); |
|
43 |
for (ManagerVerification verification : related) { |
|
44 |
deleteVerification(verification.getId()); |
|
57 |
public void deleteManagerVerifications(String email, String type, String entity) { |
|
58 |
RoleVerification roleVerification = actions.getManagerVerification(email, type, entity); |
|
59 |
if (roleVerification != null) { |
|
60 |
deleteVerification(roleVerification.getId()); |
|
45 | 61 |
} |
46 | 62 |
} |
47 | 63 |
|
48 |
public void deleteUserVerifications(String email, String type, String entity) { |
|
49 |
List<ManagerVerification> managerVerifications = actions. |
|
50 |
getUserVerificationsForAnEntity(email, type, entity); |
|
51 |
for (ManagerVerification verification : managerVerifications) { |
|
52 |
deleteVerification(verification.getId()); |
|
64 |
public void deleteMemberVerifications(String email, String type, String entity) { |
|
65 |
RoleVerification roleVerification = actions.getMemberVerification(email, type, entity); |
|
66 |
if (roleVerification != null) { |
|
67 |
deleteVerification(roleVerification.getId()); |
|
53 | 68 |
} |
54 | 69 |
} |
55 | 70 |
|
56 | 71 |
public void deleteVerification(String id) { |
57 |
actions.deleteVerificationEntry(id);
|
|
72 |
actions.delete(id); |
|
58 | 73 |
} |
59 | 74 |
|
60 |
public JsonArray getInvitedUsers(String type, String id) {
|
|
61 |
List<String> emails = actions.getVerificationsForAnEntity(type, id);
|
|
75 |
public JsonArray getInvitedManagers(String type, String id) {
|
|
76 |
List<String> emails = actions.getInvitedManagers(type, id);
|
|
62 | 77 |
JsonArray users = new JsonArray(); |
63 | 78 |
emails.forEach(users::add); |
64 | 79 |
return users; |
65 | 80 |
} |
66 | 81 |
|
67 |
public ManagerVerification getVerification(String id) { |
|
68 |
return actions.getManagerVerification(id); |
|
82 |
public JsonArray getInvitedMembers(String type, String id) { |
|
83 |
List<String> emails = actions.getInviteMembers(type, id); |
|
84 |
JsonArray users = new JsonArray(); |
|
85 |
emails.forEach(users::add); |
|
86 |
return users; |
|
69 | 87 |
} |
70 | 88 |
|
89 |
public RoleVerification getVerification(String id) { |
|
90 |
return actions.get(id); |
|
91 |
} |
|
92 |
|
|
71 | 93 |
public boolean exists(String id) { |
72 |
return actions.verificationEntryExists(id);
|
|
94 |
return actions.exists(id);
|
|
73 | 95 |
} |
74 | 96 |
|
75 | 97 |
public boolean ownedVerification(String id) { |
76 | 98 |
try { |
77 |
ManagerVerification managerVerification = getVerification(id);
|
|
99 |
RoleVerification managerVerification = getVerification(id);
|
|
78 | 100 |
if (managerVerification != null) { |
79 | 101 |
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); |
80 | 102 |
String email = authentication.getUserInfo().getEmail().toLowerCase(); |
Also available in: Unified diff
[Dnet-Users | Trunk]: Add member invitation methods