Revision 62336
Added by Argiro Kokogiannaki almost 2 years ago
ClaimsService.java | ||
---|---|---|
68 | 68 |
@Path("projects/{projectId}/claims") |
69 | 69 |
@Produces(MediaType.APPLICATION_JSON) |
70 | 70 |
public Response getProjectClaims(@PathParam("projectId") String projectId, |
71 |
@DefaultValue("0") @QueryParam("offset") int offset, |
|
72 |
@DefaultValue("20") @QueryParam("limit") int limit, |
|
73 |
@DefaultValue("") @QueryParam("keyword") String keyword, |
|
74 |
@DefaultValue("") @QueryParam("sortby") String orderby, |
|
75 |
@DefaultValue("true") @QueryParam("descending") boolean descending, |
|
76 |
@DefaultValue("") @QueryParam("types") List<String> types, |
|
71 |
@DefaultValue("0") @QueryParam("offset") int offset,
|
|
72 |
@DefaultValue("20") @QueryParam("limit") int limit,
|
|
73 |
@DefaultValue("") @QueryParam("keyword") String keyword,
|
|
74 |
@DefaultValue("") @QueryParam("sortby") String orderby,
|
|
75 |
@DefaultValue("true") @QueryParam("descending") boolean descending,
|
|
76 |
@DefaultValue("") @QueryParam("types") List<String> types,
|
|
77 | 77 |
@HeaderParam("X-XSRF-TOKEN") String token, |
78 | 78 |
@CookieParam("AccessToken") String cookie, |
79 |
@Context HttpServletRequest request) { |
|
79 |
@Context HttpServletRequest request) {
|
|
80 | 80 |
|
81 | 81 |
if(token == null || token.isEmpty() || cookie == null || cookie.isEmpty() || !cookie.equals(token)){ |
82 | 82 |
authorization.logStatus(token,cookie); |
... | ... | |
118 | 118 |
@Path("projects/{projectId}/all_claims") |
119 | 119 |
@Produces(MediaType.APPLICATION_JSON) |
120 | 120 |
public Response getAllProjectClaims(@PathParam("projectId") String projectId, |
121 |
@DefaultValue("-1") @QueryParam("offset") int offset, |
|
122 |
@DefaultValue("-1") @QueryParam("limit") int limit, |
|
123 |
@DefaultValue("") @QueryParam("keyword") String keyword, |
|
124 |
@DefaultValue("") @QueryParam("sortby") String orderby, |
|
125 |
@DefaultValue("true") @QueryParam("descending") boolean descending, |
|
126 |
@DefaultValue("") @QueryParam("types") List<String> types, |
|
127 |
@HeaderParam("X-XSRF-TOKEN") String token, |
|
128 |
@CookieParam("AccessToken") String cookie, |
|
129 |
@Context HttpServletRequest request) { |
|
121 |
@DefaultValue("-1") @QueryParam("offset") int offset,
|
|
122 |
@DefaultValue("-1") @QueryParam("limit") int limit,
|
|
123 |
@DefaultValue("") @QueryParam("keyword") String keyword,
|
|
124 |
@DefaultValue("") @QueryParam("sortby") String orderby,
|
|
125 |
@DefaultValue("true") @QueryParam("descending") boolean descending,
|
|
126 |
@DefaultValue("") @QueryParam("types") List<String> types,
|
|
127 |
@HeaderParam("X-XSRF-TOKEN") String token,
|
|
128 |
@CookieParam("AccessToken") String cookie,
|
|
129 |
@Context HttpServletRequest request) {
|
|
130 | 130 |
|
131 | 131 |
if(token == null || token.isEmpty() || cookie == null || cookie.isEmpty() || !cookie.equals(token)){ |
132 | 132 |
authorization.logStatus(token,cookie); |
... | ... | |
257 | 257 |
@Path("/contexts/{contextId}/claims") |
258 | 258 |
@Produces(MediaType.APPLICATION_JSON) |
259 | 259 |
public Response getContextClaims(@PathParam("contextId") String contextId, |
260 |
@DefaultValue("0") @QueryParam("offset") int offset, |
|
261 |
@DefaultValue("20") @QueryParam("limit") int limit, |
|
262 |
@DefaultValue("") @QueryParam("keyword") String keyword, |
|
263 |
@DefaultValue("") @QueryParam("sortby") String orderby, |
|
264 |
@DefaultValue("true") @QueryParam("descending") boolean descending, |
|
265 |
@DefaultValue("") @QueryParam("types") List<String> types, |
|
260 |
@DefaultValue("0") @QueryParam("offset") int offset,
|
|
261 |
@DefaultValue("20") @QueryParam("limit") int limit,
|
|
262 |
@DefaultValue("") @QueryParam("keyword") String keyword,
|
|
263 |
@DefaultValue("") @QueryParam("sortby") String orderby,
|
|
264 |
@DefaultValue("true") @QueryParam("descending") boolean descending,
|
|
265 |
@DefaultValue("") @QueryParam("types") List<String> types,
|
|
266 | 266 |
@HeaderParam("X-XSRF-TOKEN") String token, |
267 | 267 |
@CookieParam("AccessToken") String cookie, |
268 |
@CookieParam("openAIRESession") String sessionId, |
|
268 | 269 |
@Context HttpServletRequest request) { |
269 | 270 |
// @RequestParam(value="includeStates[]", defaultValue="1,2,3") String[] includeStates |
270 | 271 |
|
... | ... | |
276 | 277 |
} |
277 | 278 |
// logger.debug("Calling API for context with token " + token); |
278 | 279 |
UserInfo userInfo = authorization.getUserHandler().getUserInfo(token); |
279 |
if(authorization.isCommunityCurator(userInfo) || authorization.isClaimCurator(token) || this.emailSender.getManagerUtils().isCommunityManager(contextId, userInfo.email)) { |
|
280 |
if(authorization.isCommunityCurator(userInfo) || authorization.isClaimCurator(token) || this.emailSender.getManagerUtils().isCommunityManager(contextId, userInfo.email, sessionId )) {
|
|
280 | 281 |
|
281 | 282 |
int total = -1; |
282 | 283 |
if (contextId == null || contextId.isEmpty()) { |
... | ... | |
471 | 472 |
@Path("/claims") |
472 | 473 |
@Produces(MediaType.APPLICATION_JSON) |
473 | 474 |
public Response getAllClaims(@DefaultValue("0") @QueryParam("offset") int offset, |
474 |
@DefaultValue("20") @QueryParam("limit") int limit,
|
|
475 |
@DefaultValue("") @QueryParam("keyword") String keyword,
|
|
476 |
@DefaultValue("date") @QueryParam("sortby") String orderby,
|
|
477 |
@DefaultValue("true") @QueryParam("descending") boolean descending,
|
|
478 |
@DefaultValue("") @QueryParam("types") List<String> types,
|
|
475 |
@DefaultValue("20") @QueryParam("limit") int limit, |
|
476 |
@DefaultValue("") @QueryParam("keyword") String keyword, |
|
477 |
@DefaultValue("date") @QueryParam("sortby") String orderby, |
|
478 |
@DefaultValue("true") @QueryParam("descending") boolean descending, |
|
479 |
@DefaultValue("") @QueryParam("types") List<String> types, |
|
479 | 480 |
@HeaderParam("X-XSRF-TOKEN") String token, |
480 | 481 |
@HeaderParam("Origin") String origin, |
481 | 482 |
@CookieParam("AccessToken") String cookie, |
482 |
@Context HttpServletRequest request) {
|
|
483 |
@Context HttpServletRequest request) { |
|
483 | 484 |
|
484 | 485 |
|
485 | 486 |
logger.debug("Header \"Origin\" has value " + origin); |
... | ... | |
513 | 514 |
} |
514 | 515 |
|
515 | 516 |
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access")) |
516 |
.type(MediaType.APPLICATION_JSON) |
|
517 |
.build(); |
|
517 |
.type(MediaType.APPLICATION_JSON)
|
|
518 |
.build();
|
|
518 | 519 |
} |
519 | 520 |
|
520 | 521 |
@DELETE |
... | ... | |
528 | 529 |
|
529 | 530 |
|
530 | 531 |
if(!authorization.hasBasicAuthorization(token, origin, cookie)){ |
531 |
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
|
532 |
.type(MediaType.APPLICATION_JSON)
|
|
533 |
.build();
|
|
534 |
}
|
|
532 |
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered.")) |
|
533 |
.type(MediaType.APPLICATION_JSON) |
|
534 |
.build(); |
|
535 |
} |
|
535 | 536 |
|
536 | 537 |
|
537 | 538 |
ArrayList<String> deletedIds= new ArrayList<String>(); |
... | ... | |
689 | 690 |
code400++; |
690 | 691 |
|
691 | 692 |
} catch (SQLStoreException|Exception e) { |
692 |
logger.error("Fail to add new claim.", e);
|
|
693 |
logger.error("Fail to add new claim.", e); |
|
693 | 694 |
// return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to add new claim.", e)) |
694 | 695 |
// .type(MediaType.APPLICATION_JSON).build(); |
695 | 696 |
jsonObject.addProperty("error", "insertion"); |
... | ... | |
740 | 741 |
for (JsonElement je : jsonArray) { |
741 | 742 |
JsonObject jsonObject = je.getAsJsonObject(); |
742 | 743 |
|
743 |
String id = jsonObject.get("id").getAsString();
|
|
744 |
String id = jsonObject.get("id").getAsString(); |
|
744 | 745 |
logger.info("id " + id); |
745 | 746 |
|
746 | 747 |
Boolean approved = jsonObject.get("approved").getAsBoolean(); |
... | ... | |
837 | 838 |
@Path("/users/notification") |
838 | 839 |
@Produces(MediaType.APPLICATION_JSON) |
839 | 840 |
public Response getUserEmailNotificationPreferences(@QueryParam("communityId") String openaireId, |
840 |
@HeaderParam("X-XSRF-TOKEN") String token, |
|
841 |
@CookieParam("AccessToken") String cookie, |
|
842 |
@Context HttpServletRequest request) { |
|
843 |
|
|
841 |
@HeaderParam("X-XSRF-TOKEN") String token, |
|
842 |
@CookieParam("AccessToken") String cookie, |
|
843 |
@CookieParam("openAIRESession") String sessionId, |
|
844 |
@Context HttpServletRequest request) { |
|
845 |
|
|
844 | 846 |
if(token == null || token.isEmpty() || cookie == null || cookie.isEmpty() || !cookie.equals(token)){ |
845 | 847 |
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered.")) |
846 | 848 |
.type(MediaType.APPLICATION_JSON) |
... | ... | |
868 | 870 |
try { |
869 | 871 |
if(openaireId != null) { |
870 | 872 |
// CommunityUtils communityInfo = this.emailSender.getCommunityUtils().getCommunityInfo(openaireId); |
871 |
if(this.emailSender.getManagerUtils().isCommunityManager(openaireId, userMail) || authorization.isCommunityCurator(userInfo)) { |
|
873 |
if(this.emailSender.getManagerUtils().isCommunityManager(openaireId, userMail, sessionId) || authorization.isCommunityCurator(userInfo)) {
|
|
872 | 874 |
|
873 | 875 |
Notification notification = null; |
874 | 876 |
logger.debug("About to fetch notification"); |
... | ... | |
932 | 934 |
@Produces(MediaType.APPLICATION_JSON) |
933 | 935 |
@Consumes(MediaType.APPLICATION_JSON) |
934 | 936 |
public Response saveOrUpdateUserEmailNotificationPreferences(String input, @Context HttpServletRequest request, |
935 |
@HeaderParam("X-XSRF-TOKEN") String token, |
|
936 |
@HeaderParam("Origin") String origin, |
|
937 |
@CookieParam("AccessToken") String cookie) { |
|
937 |
@HeaderParam("X-XSRF-TOKEN") String token, |
|
938 |
@HeaderParam("Origin") String origin, |
|
939 |
@CookieParam("AccessToken") String cookie, |
|
940 |
@CookieParam("openAIRESession") String sessionId) { |
|
938 | 941 |
|
939 | 942 |
|
940 | 943 |
if(!authorization.hasBasicAuthorization(token, origin, cookie)){ |
... | ... | |
965 | 968 |
EmailValidator emailValidator = EmailValidator.getInstance(); |
966 | 969 |
if (!emailValidator.isValid(userMail)) { |
967 | 970 |
jsonObject.addProperty("error", "user"); |
968 |
return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("User e-mail is invalid."))
|
|
969 |
.type(MediaType.APPLICATION_JSON).build();
|
|
971 |
return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("User e-mail is invalid.")) |
|
972 |
.type(MediaType.APPLICATION_JSON).build(); |
|
970 | 973 |
} |
971 | 974 |
|
972 | 975 |
try { |
... | ... | |
983 | 986 |
continueProcedure = true; |
984 | 987 |
} else { |
985 | 988 |
// CommunityUtils communityInfo = this.emailSender.getCommunityUtils().getCommunityInfo(openaireId); |
986 |
if(this.emailSender.getManagerUtils().isCommunityManager(openaireId, userMail) || authorization.isCommunityCurator(userInfo) ) { |
|
989 |
if(this.emailSender.getManagerUtils().isCommunityManager(openaireId, userMail, sessionId) || authorization.isCommunityCurator(userInfo) ) {
|
|
987 | 990 |
continueProcedure = true; |
988 | 991 |
} |
989 | 992 |
} |
... | ... | |
1169 | 1172 |
return "\"total\": \""+total+"\""; |
1170 | 1173 |
} |
1171 | 1174 |
|
1172 |
public static void main(String[] args) {
|
|
1175 |
public static void main(String[] args) { |
|
1173 | 1176 |
|
1174 | 1177 |
/* |
1175 | 1178 |
EmailValidator emailValidator = EmailValidator.getInstance(); |
Also available in: Unified diff
parse session cookie for the iscommunitymanager function