Revision 60501
Added by Konstantina Galouni about 3 years ago
CommunityInfo.java | ||
---|---|---|
1 |
package eu.dnetlib.uoaadmintools.handlers.utils; |
|
2 |
|
|
3 |
import com.google.gson.Gson; |
|
4 |
import org.apache.log4j.Logger; |
|
5 |
|
|
6 |
import java.io.BufferedReader; |
|
7 |
import java.io.InputStreamReader; |
|
8 |
import java.io.StringReader; |
|
9 |
import java.net.HttpURLConnection; |
|
10 |
import java.net.URL; |
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.List; |
|
13 |
|
|
14 |
/** |
|
15 |
* Created by argirok on 27/2/2018. |
|
16 |
*/ |
|
17 |
public class CommunityInfo { |
|
18 |
|
|
19 |
List<String> managers = new ArrayList<String>(); |
|
20 |
private final Logger log = Logger.getLogger(this.getClass()); |
|
21 |
|
|
22 |
public List<String> getManagers() { |
|
23 |
return managers; |
|
24 |
} |
|
25 |
|
|
26 |
public void setManagers(List<String> managers) { |
|
27 |
this.managers = managers; |
|
28 |
} |
|
29 |
|
|
30 |
private CommunityInfo getCommunityInfo(String communityAPI, String community) { |
|
31 |
String url = communityAPI + community; |
|
32 |
URL obj = null; |
|
33 |
String responseStr = null; |
|
34 |
log.debug("Community info url is " + url); |
|
35 |
|
|
36 |
try { |
|
37 |
obj = new URL(url); |
|
38 |
HttpURLConnection con = (HttpURLConnection) obj.openConnection(); |
|
39 |
log.debug("User info response code is: " + con.getResponseCode()); |
|
40 |
if (con.getResponseCode() != 200) { |
|
41 |
return null; |
|
42 |
} |
|
43 |
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); |
|
44 |
StringBuffer response = new StringBuffer(); |
|
45 |
String inputLine; |
|
46 |
while ((inputLine = in.readLine()) != null) { |
|
47 |
response.append(inputLine).append("\n"); |
|
48 |
} |
|
49 |
in.close(); |
|
50 |
responseStr = response.toString(); |
|
51 |
} catch (Exception e) { |
|
52 |
log.error("An error occured while trying to fetch user info ", e); |
|
53 |
return null; |
|
54 |
} |
|
55 |
return json2CommunityInfo(community); |
|
56 |
} |
|
57 |
private CommunityInfo json2CommunityInfo(String json){ |
|
58 |
|
|
59 |
log.debug("Try to create CommunityInfo class from json: "+json); |
|
60 |
if (json == null){ |
|
61 |
return null; |
|
62 |
} |
|
63 |
|
|
64 |
BufferedReader br = new BufferedReader(new StringReader(json)); |
|
65 |
//convert the json string back to object |
|
66 |
Gson gson = new Gson(); |
|
67 |
CommunityInfo communityInfo = null; |
|
68 |
try { |
|
69 |
communityInfo = gson.fromJson(br, CommunityInfo.class); |
|
70 |
}catch(Exception e){ |
|
71 |
log.debug("Error in parsing json response. Given json is : "+json, e); |
|
72 |
return null; |
|
73 |
} |
|
74 |
|
|
75 |
log.debug("Original response.........: "+communityInfo.toString()); |
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
return communityInfo; |
|
80 |
} |
|
81 |
} |
|
1 |
//package eu.dnetlib.uoaadmintools.handlers.utils; |
|
2 |
// |
|
3 |
//import com.google.gson.Gson; |
|
4 |
//import org.apache.log4j.Logger; |
|
5 |
// |
|
6 |
//import java.io.BufferedReader; |
|
7 |
//import java.io.InputStreamReader; |
|
8 |
//import java.io.StringReader; |
|
9 |
//import java.net.HttpURLConnection; |
|
10 |
//import java.net.URL; |
|
11 |
//import java.util.ArrayList; |
|
12 |
//import java.util.List; |
|
13 |
// |
|
14 |
///** |
|
15 |
// * Created by argirok on 27/2/2018. |
|
16 |
// */ |
|
17 |
//public class CommunityInfo { |
|
18 |
// |
|
19 |
// List<String> managers = new ArrayList<String>(); |
|
20 |
// private final Logger log = Logger.getLogger(this.getClass()); |
|
21 |
// |
|
22 |
// public List<String> getManagers() { |
|
23 |
// return managers; |
|
24 |
// } |
|
25 |
// |
|
26 |
// public void setManagers(List<String> managers) { |
|
27 |
// this.managers = managers; |
|
28 |
// } |
|
29 |
// |
|
30 |
// private CommunityInfo getCommunityInfo(String communityAPI, String community) { |
|
31 |
// String url = communityAPI + community; |
|
32 |
// URL obj = null; |
|
33 |
// String responseStr = null; |
|
34 |
// log.debug("Community info url is " + url); |
|
35 |
// |
|
36 |
// try { |
|
37 |
// obj = new URL(url); |
|
38 |
// HttpURLConnection con = (HttpURLConnection) obj.openConnection(); |
|
39 |
// log.debug("User info response code is: " + con.getResponseCode()); |
|
40 |
// if (con.getResponseCode() != 200) { |
|
41 |
// return null; |
|
42 |
// } |
|
43 |
// BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); |
|
44 |
// StringBuffer response = new StringBuffer(); |
|
45 |
// String inputLine; |
|
46 |
// while ((inputLine = in.readLine()) != null) { |
|
47 |
// response.append(inputLine).append("\n"); |
|
48 |
// } |
|
49 |
// in.close(); |
|
50 |
// responseStr = response.toString(); |
|
51 |
// } catch (Exception e) { |
|
52 |
// log.error("An error occured while trying to fetch user info ", e); |
|
53 |
// return null; |
|
54 |
// } |
|
55 |
// return json2CommunityInfo(community); |
|
56 |
// } |
|
57 |
// private CommunityInfo json2CommunityInfo(String json){ |
|
58 |
// |
|
59 |
// log.debug("Try to create CommunityInfo class from json: "+json); |
|
60 |
// if (json == null){ |
|
61 |
// return null; |
|
62 |
// } |
|
63 |
// |
|
64 |
// BufferedReader br = new BufferedReader(new StringReader(json)); |
|
65 |
// //convert the json string back to object |
|
66 |
// Gson gson = new Gson(); |
|
67 |
// CommunityInfo communityInfo = null; |
|
68 |
// try { |
|
69 |
// communityInfo = gson.fromJson(br, CommunityInfo.class); |
|
70 |
// }catch(Exception e){ |
|
71 |
// log.debug("Error in parsing json response. Given json is : "+json, e); |
|
72 |
// return null; |
|
73 |
// } |
|
74 |
// |
|
75 |
// log.debug("Original response.........: "+communityInfo.toString()); |
|
76 |
// |
|
77 |
// |
|
78 |
// |
|
79 |
// return communityInfo; |
|
80 |
// } |
|
81 |
//} |
Also available in: Unified diff
[Trunk | Admin Tools]:
1. pom.xml: Added dependency for spring security.
2. UoaAdminToolsApplication.java: Import AuthorizationConfiguration.class | Remove SecurityConfig.class from @EnableConfigurationProperties.
3. UoaAdminToolsConfiguration.java: Comment "addInterceptors()" method calling AuthorizationHandler with SecurityConfig.
4. SecurityConfig.java & AuthorizationHandler.java & AuthorizationUtils.java & CommunityInfo.java & UserInfo.java: Commented all contents of these files (files will be deleted in coming commit).
5. PortalSubscribersController.java: Comment imports from commeted files.
6. Notifications.java: Added field "aaiId" get getters and setters.
7. NotificationsController.java:
a. Method "getNotifications()" is replaced by "getNotificationsForUser()" (/community/{pid}/notifications) - returns notification settings only for user who made the request (uoa-authorization-li$
b. Path changed for method "getNotifications()": /community/{pid}/notifications/all
c. Remove "@RequestBody String email" parameter from method "deleteNotification()" - get email from user who made the request (uoa-authorization-library).
d. In method "saveNotification()" get aaiId and email from user who made the request (uoa-authorization-library).
e. Added checks and throw Exceptions in all methods.
f. Added @PreAuthorize
Portal Admins: "getNotifications()" (/community/{pid}/notifications/all)
Portal Admins - Curators - Managers: "getNotificationsForUser()" (/community/{pid}/notifications), "deleteNotification()" (/community/{pid}/notifications), "saveNotification()" (/communit$
8. ExploreController.java:
a. Added checks and throw Exceptions in all methods.
b. Added @PreAuthorize
Portal Admins: "updateExplore()" (/explore/update), "insertExplore()" (/explore/save), "deleteExplore()" (/explore/delete).
9. ConnectController.java:
a. Added checks and throw Exceptions in all methods.
b. Added @PreAuthorize
Portal Admins: "updateConnect()" (/connect/update), "insertConnect()" (/connect/save), "deleteConnect()" (/connect/delete).
c. Commented methods "getLayoutForConnect()" and "updateLayoutForConnect()" (/connect/{pid}/layout).
10. CommunityController.java:
a. Added checks and throw Exceptions in all methods.
b. Added @PreAuthorize
Portal Admins: "updateCommunity()" (/community/update), "insertCommunity()" (/community/save), "deleteCommunity()" (/community/delete).
Portal Admin - Curators - Managers: "updateLayoutForCommunity()" (/community/{pid}/layout).
11. CuratorController.java:
a. In "insertCurator() (/curator) set _id field with aaiId from user who made the request (uoa-authorization-library).
b. Added @PreAuthorize
Authenticated users: "getCuratorById()" (/curator/{id}), "insertCurator()" (/curator).
Portal Admins: "deleteCurators()" (/curator).