Project

General

Profile

« Previous | Next » 

Revision 60924

Merge last changes from trunk

View differences:

modules/dnet-openaire-users/branches/prod/src/main/java/eu/dnetlib/openaire/usermanagement/utils/AuthorizationService.java
1 1
package eu.dnetlib.openaire.usermanagement.utils;
2 2

  
3
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
4
import org.springframework.security.core.Authentication;
5
import org.springframework.security.core.GrantedAuthority;
6
import org.springframework.security.core.context.SecurityContextHolder;
3 7
import org.springframework.stereotype.Component;
4 8

  
9
import java.util.ArrayList;
10
import java.util.List;
11

  
5 12
@Component("AuthorizationService")
6 13
public class AuthorizationService {
7 14

  
......
47 54
    public boolean isCommunity(String type) {
48 55
        return mapType(type, false).equals("community");
49 56
    }
57

  
58

  
59
    public List<String> getRoles() {
60
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
61
        if (authentication != null) {
62
            List<GrantedAuthority> authorities = (List<GrantedAuthority>) authentication.getAuthorities();
63
            if (authorities != null) {
64
                List<String> roles = new ArrayList<>();
65
                authorities.forEach((authority) -> {
66
                    roles.add(authority.getAuthority());
67
                });
68
                return roles;
69
            }
70
        }
71
        return null;
72
    }
73

  
74
    public String getAaiId() {
75
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
76
        return authentication instanceof OIDCAuthenticationToken ? ((OIDCAuthenticationToken)authentication).getSub() : null;
77
    }
78

  
79
    public String getEmail() {
80
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
81
        return authentication instanceof OIDCAuthenticationToken ? ((OIDCAuthenticationToken)authentication).getUserInfo().getEmail() : null;
82
    }
50 83
}
modules/dnet-openaire-users/branches/prod/src/main/java/eu/dnetlib/openaire/usermanagement/utils/RegisteredServicesUtils.java
29 29
        if (registeredService == null) {
30 30
            return false; //no harm in accessing nothing
31 31
        }
32
       return registeredService.getOwner().equals(userid);
32
        return registeredService.getOwner().equals(userid);
33 33
    }
34 34

  
35 35
}
modules/dnet-openaire-users/branches/prod/src/main/java/eu/dnetlib/openaire/usermanagement/utils/RegistryCalls.java
8 8
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
9 9
import org.springframework.beans.factory.annotation.Autowired;
10 10
import org.springframework.beans.factory.annotation.Value;
11
import org.springframework.security.access.method.P;
11 12
import org.springframework.security.core.context.SecurityContextHolder;
12 13
import org.springframework.stereotype.Service;
13 14

  
15
import java.util.ArrayList;
14 16
import java.util.HashMap;
17
import java.util.List;
15 18
import java.util.Map;
16 19

  
17 20
@Service
......
70 73
        return null;
71 74
    }
72 75

  
76
    public List<Integer> getCoPersonIdsByEmail(String email) {
77
        List<Integer> coPersonIds = new ArrayList<>();
78
        Map<String, String> params = new HashMap<>();
79
        params.put("coid", coid);
80
        params.put("mail", email);
81
        JsonElement response = httpUtils.get("co_people.json", params);
82
        if(response != null) {
83
            JsonArray coPeople = response.getAsJsonObject().get("CoPeople").getAsJsonArray();
84
            for(int i = 0; i < coPeople.size(); i++) {
85
                coPersonIds.add(coPeople.get(i).getAsJsonObject().get("Id").getAsInt());
86
            }
87
        }
88
        return coPersonIds;
89
    }
90

  
73 91
    /**
74 92
     * 2. Get CoPersonId by AAI identifier
75 93
     */
......
255 273
        JsonArray emails = new JsonArray();
256 274
        infos.forEach(info -> {
257 275
            JsonObject user = new JsonObject();
258
            user.addProperty("email", info.getAsJsonObject().get("Mail").getAsString());
259
            user.addProperty("memberSince", info.getAsJsonObject().get("Created").getAsString());
260
            emails.add(user);
276
            boolean add = true;
277
            String email = info.getAsJsonObject().get("Mail").getAsString();
278
            for(JsonElement element : emails) {
279
                if(element.getAsJsonObject().get("email").getAsString().equals(email)) {
280
                    add = false;
281
                }
282
            }
283
            if(add) {
284
                user.addProperty("email", email);
285
                user.addProperty("memberSince", info.getAsJsonObject().get("Created").getAsString());
286
                emails.add(user);
287
            }
261 288
        });
262 289
        return emails;
263 290
    }
......
284 311
    }
285 312

  
286 313
    /**
287
     * 14. Assign a member role to a User
314
     * 14. Get Users' identifiers of a Cou
288 315
     */
316
    public JsonArray getUserIdByCouId(Integer couId, boolean admin) {
317
        Map<String, String> params = new HashMap<>();
318
        params.put("couid", couId.toString());
319
        if (admin) {
320
            params.put("admin", "true");
321
        }
322
        JsonElement response = httpUtils.get("identifiers.json", params);
323
        JsonArray infos = (response != null) ? response.getAsJsonObject().get("Identifiers").getAsJsonArray() : new JsonArray();
324
        JsonArray emails = new JsonArray();
325
        infos.forEach(info -> {
326
            JsonObject user = new JsonObject();
327
            user.addProperty("id", info.getAsJsonObject().get("Identifier").getAsString());
328
            user.addProperty("memberSince", info.getAsJsonObject().get("Created").getAsString());
329
            emails.add(user);
330
        });
331
        return emails;
332
    }
333

  
334
    /**
335
     * 15. Assign a member role to a User
336
     */
289 337
    public void assignMemberRole(Integer coPersonId, Integer couId, Integer id) {
290 338
        if (id != null) {
291 339
            httpUtils.put("co_person_roles/" + id.toString() + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Active"));
......
295 343
    }
296 344

  
297 345
    /**
298
     * 15. Remove a member role from a User
346
     * 16. Remove a member role from a User
299 347
     */
300 348
    public void removeMemberRole(Integer coPersonId, Integer couId, Integer id) {
301
        httpUtils.put("co_person_roles/" + id.toString() + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Deleted"));
349
        if(id != null) {
350
            httpUtils.put("co_person_roles/" + id.toString() + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Deleted"));
351
        }
302 352
    }
303 353

  
304 354
    /**
305
     * 16. Create a new role
355
     * 17. Create a new role
306 356
     */
307 357
    public void createRole(Role role) {
308 358
        httpUtils.post("cous.json", jsonUtils.createNewCou(role));
309 359
    }
310 360

  
311 361
    /**
312
     * 17. Get User's email
362
     * 18. Get User's email
313 363
     */
314 364
    public String getUserEmail(Integer coPersonId) {
315 365
        Map<String, String> params = new HashMap<>();
......
320 370
    }
321 371

  
322 372
    /**
323
     * 18. Get User's names
373
     * 19. Get User's names
324 374
     */
325 375
    public String getUserNames(Integer coPersonId) {
326 376
        Map<String, String> params = new HashMap<>();
......
331 381
    }
332 382

  
333 383
    /**
334
     * 14. Assign an admin role to a User
384
     * 20. Get User's identifier
335 385
     */
386
    public String getUserId(Integer coPersonId) {
387
        Map<String, String> params = new HashMap<>();
388
        params.put("copersonid", coPersonId.toString());
389
        JsonElement response = httpUtils.get("identifiers.json", params);
390
        JsonObject info = (response != null) ? response.getAsJsonObject().get("Identifiers").getAsJsonArray().get(0).getAsJsonObject() : null;
391
        return (info != null) ? info.getAsJsonObject().get("Identifier").getAsString() : null;
392
    }
393

  
394
    /**
395
     * 21. Assign an admin role to a User
396
     */
336 397
    public void assignAdminRole(Integer coPersonId, Integer couId) {
337 398
        JsonObject group = getCouAdminGroup(couId);
338 399
        if (group != null) {
......
341 402
    }
342 403

  
343 404
    /**
344
     * 15. Remove an admin role from a User
405
     * 22. Remove an admin role from a User
345 406
     */
346 407
    public void removeAdminRole(Integer coPersonId, Integer couId) {
347 408
        JsonObject adminGroup = this.getCouAdminGroup(couId);
modules/dnet-openaire-users/branches/prod/src/main/java/eu/dnetlib/openaire/usermanagement/RegisterServlet.java
50 50

  
51 51
    private static Logger logger = Logger.getLogger(RegisterServlet.class);
52 52

  
53
        @Override
53
    @Override
54 54
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
55 55
        response.setContentType("text/html");
56 56
        PrintWriter printWriter = response.getWriter();
modules/dnet-openaire-users/branches/prod/src/main/java/eu/dnetlib/openaire/usermanagement/api/RegistryService.java
15 15
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
16 16
import org.springframework.beans.factory.annotation.Autowired;
17 17
import org.springframework.http.HttpStatus;
18
import org.springframework.security.access.method.P;
18 19
import org.springframework.security.access.prepost.PreAuthorize;
19 20
import org.springframework.security.core.authority.SimpleGrantedAuthority;
20 21
import org.springframework.security.core.context.SecurityContextHolder;
......
27 28
import javax.ws.rs.core.Response;
28 29
import java.util.Collection;
29 30
import java.util.HashSet;
31
import java.util.List;
30 32

  
31 33
@Component(value = "RegistryService")
32 34
@Path("/registry")
......
52 54
    @Autowired
53 55
    private AuthorizationService authorizationService;
54 56

  
55
    private String sendEmail() {
56
        OIDCAuthenticationToken authenticationToken = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
57
        return authenticationToken.getUserInfo().getEmail();
58
    }
59

  
60 57
    /**
61 58
     * Subscribe to a type(Community, etc.) with id(ee, egi, etc.)
62 59
     */
......
70 67
        if (couId != null) {
71 68
            Integer role = calls.getRoleId(coPersonId, couId);
72 69
            calls.assignMemberRole(coPersonId, couId, role);
73
            authoritiesUpdater.update(sendEmail(), old -> {
70
            authoritiesUpdater.update(authorizationService.getEmail(), old -> {
74 71
                HashSet<SimpleGrantedAuthority> authorities = new HashSet<>((Collection<? extends SimpleGrantedAuthority>) old);
75 72
                authorities.add(new SimpleGrantedAuthority(authorizationService.member(type, id)));
76 73
                return authorities;
......
97 94
            if (role != null) {
98 95
                calls.removeAdminRole(coPersonId, couId);
99 96
                calls.removeMemberRole(coPersonId, couId, role);
100
                authoritiesUpdater.update(sendEmail(), old -> {
97
                authoritiesUpdater.update(authorizationService.getEmail(), old -> {
101 98
                    HashSet<SimpleGrantedAuthority> authorities = new HashSet<>((Collection<? extends SimpleGrantedAuthority>) old);
102 99
                    authorities.remove(new SimpleGrantedAuthority(authorizationService.manager(type, id)));
103 100
                    authorities.remove(new SimpleGrantedAuthority(authorizationService.member(type, id)));
......
120 117
    @Consumes(MediaType.APPLICATION_JSON)
121 118
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
122 119
    public Response createRole(@RequestBody Role role) {
123
        if(calls.getCouId(role.getName()) == null) {
124
        calls.createRole(role);
125
        return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Role has been created").toString()).type(MediaType.APPLICATION_JSON).build();
120
        if (calls.getCouId(role.getName()) == null) {
121
            calls.createRole(role);
122
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Role has been created").toString()).type(MediaType.APPLICATION_JSON).build();
126 123
        } else {
127 124
            return Response.status(HttpStatus.CONFLICT.value()).entity(jsonUtils.createResponse("Role has already existed").toString()).type(MediaType.APPLICATION_JSON).build();
128 125
        }
129 126
    }
130 127

  
131 128
    /**
132
     *
133 129
     * Invite user with email to manage a type(Community, etc.) with id(ee, egi, etc.)
134 130
     * Auto generated link and code will be sent as response.
135 131
     */
......
184 180
    }
185 181

  
186 182
    private Response sendEmail(JsonObject details, JsonObject email, Integer coPersonId, JsonObject invitation) {
187
        String name = (coPersonId != null)?calls.getUserNames(coPersonId):"User";
183
        String name = (coPersonId != null) ? calls.getUserNames(coPersonId) : "User";
188 184
        String link = details.get("link").getAsString() + invitation.get("link").getAsString();
189 185
        String subject = email.get("subject").getAsString();
190 186
        String message = email.get("body").getAsString().
......
273 269
    public Response getVerification(@PathParam("id") String id) {
274 270
        RoleVerification verification = verificationUtils.getVerification(id);
275 271
        if (verification != null) {
276
            if (calls.getCoPersonIdByEmail(verification.getEmail()).equals(calls.getCoPersonIdByIdentifier())) {
272
            if (verification.getEmail().equalsIgnoreCase(authorizationService.getEmail())) {
277 273
                return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(jsonUtils.createVerification(verification)).toString()).type(MediaType.APPLICATION_JSON).build();
278 274
            } else {
279 275
                return Response.status(HttpStatus.FORBIDDEN.value()).entity(jsonUtils.createResponse("Forbidden verification").toString()).type(MediaType.APPLICATION_JSON).build();
......
310 306
    public Response verifyManager(@PathParam("id") String id, @RequestBody String code) {
311 307
        RoleVerification verification = verificationUtils.getVerification(id);
312 308
        if (verification != null && verification.getVerificationType().equals("manager")) {
313
            Integer coPersonId = calls.getCoPersonIdByEmail(verification.getEmail());
309
            Integer coPersonId = calls.getCoPersonIdByIdentifier();
314 310
            if (coPersonId != null) {
315
                if (coPersonId.equals(calls.getCoPersonIdByIdentifier())) {
311
                if (verification.getEmail().equalsIgnoreCase(authorizationService.getEmail())) {
316 312
                    if (verification.getVerificationCode().equals(code)) {
317 313
                        Integer couId = calls.getCouId(verification.getType(), verification.getEntity());
318 314
                        if (couId != null) {
319 315
                            Integer role = calls.getRoleId(coPersonId, couId);
320 316
                            calls.assignMemberRole(coPersonId, couId, role);
321
                            verificationUtils.deleteMemberVerifications(verification.getEmail(), verification.getType(), verification.getEntity());
317
                            if (verification.getType().equals("community") || verification.getType().equals("ri")) {
318
                                Integer riCouId = calls.getCouId("ri", verification.getEntity(), false);
319
                                if (riCouId != null) {
320
                                    calls.assignMemberRole(coPersonId, riCouId, calls.getRoleId(coPersonId, riCouId));
321
                                    verificationUtils.deleteMemberVerifications(verification.getEmail(), "community", verification.getEntity());
322
                                    verificationUtils.deleteMemberVerifications(verification.getEmail(), "ri", verification.getEntity());
323
                                } else {
324
                                    verificationUtils.deleteMemberVerifications(verification.getEmail(), "community", verification.getEntity());
325
                                }
326
                            } else {
327
                                verificationUtils.deleteMemberVerifications(verification.getEmail(), verification.getType(), verification.getEntity());
328
                            }
322 329
                            if (calls.getUserAdminGroup(coPersonId, couId) == null) {
323
                                verificationUtils.deleteManagerVerifications(verification.getEmail(), verification.getType(), verification.getEntity());
330
                                if (verification.getType().equals("community") || verification.getType().equals("ri")) {
331
                                    verificationUtils.deleteManagerVerifications(verification.getEmail(), "community", verification.getEntity());
332
                                    verificationUtils.deleteManagerVerifications(verification.getEmail(), "ri", verification.getEntity());
333
                                } else {
334
                                    verificationUtils.deleteManagerVerifications(verification.getEmail(), verification.getType(), verification.getEntity());
335
                                }
324 336
                                calls.assignAdminRole(coPersonId, couId);
325 337
                                authoritiesUpdater.update(verification.getEmail(), old -> {
326 338
                                    HashSet<SimpleGrantedAuthority> authorities = new HashSet<>((Collection<? extends SimpleGrantedAuthority>) old);
......
336 348
                            return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
337 349
                        }
338 350
                    } else {
339
                        return Response.status(HttpStatus.FORBIDDEN.value()).entity(jsonUtils.createResponse("Verification code is wrong").toString()).type(MediaType.APPLICATION_JSON).build();
351
                        return Response.status(HttpStatus.BAD_REQUEST.value()).entity(jsonUtils.createResponse("Verification code is wrong").toString()).type(MediaType.APPLICATION_JSON).build();
340 352
                    }
341 353
                } else {
342 354
                    return Response.status(HttpStatus.FORBIDDEN.value()).entity(jsonUtils.createResponse("Forbidden verification").toString()).type(MediaType.APPLICATION_JSON).build();
......
360 372
    public Response verifyMember(@PathParam("id") String id, @RequestBody String code) {
361 373
        RoleVerification verification = verificationUtils.getVerification(id);
362 374
        if (verification != null && verification.getVerificationType().equals("member")) {
363
            Integer coPersonId = calls.getCoPersonIdByEmail(verification.getEmail());
375
            Integer coPersonId = calls.getCoPersonIdByIdentifier();
364 376
            if (coPersonId != null) {
365
                if (coPersonId.equals(calls.getCoPersonIdByIdentifier())) {
377
                if (verification.getEmail().equalsIgnoreCase(authorizationService.getEmail())) {
366 378
                    if (verification.getVerificationCode().equals(code)) {
367 379
                        Integer couId = calls.getCouId(verification.getType(), verification.getEntity(), false);
368 380
                        if (couId != null) {
......
402 414
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN, @AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
403 415
    public Response removeManagerRole(@PathParam("type") String type, @PathParam("id") String
404 416
            id, @PathParam("email") String email) {
405
        Integer coPersonId = calls.getCoPersonIdByEmail(email);
406
        if (coPersonId != null) {
417
        List<Integer> coPersonIds = calls.getCoPersonIdsByEmail(email);
418
        if (coPersonIds.size() > 0) {
407 419
            Integer couId = calls.getCouId(type, id);
408 420
            if (couId != null) {
409
                calls.removeAdminRole(coPersonId, couId);
421
                coPersonIds.forEach(coPersonId -> {
422
                    calls.removeAdminRole(coPersonId, couId);
423
                });
410 424
                authoritiesUpdater.update(email, old -> {
411 425
                    HashSet<SimpleGrantedAuthority> authorities = new HashSet<>((Collection<? extends SimpleGrantedAuthority>) old);
412 426
                    authorities.remove(new SimpleGrantedAuthority(authorizationService.manager(type, id)));
......
431 445
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN, @AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
432 446
    public Response removeMemberRole(@PathParam("type") String type, @PathParam("id") String
433 447
            id, @PathParam("email") String email) {
434
        Integer coPersonId = calls.getCoPersonIdByEmail(email);
435
        if (coPersonId != null) {
448
        List<Integer> coPersonIds = calls.getCoPersonIdsByEmail(email);
449
        if (coPersonIds.size() > 0) {
436 450
            Integer couId = calls.getCouId(type, id, false);
437
            Integer role = null;
438
            if(couId != null) {
439
                role = calls.getRoleId(coPersonId, couId);
440
            }
441
            if (couId != null && role != null) {
442
                calls.removeAdminRole(coPersonId, couId);
443
                calls.removeMemberRole(coPersonId, couId, role);
451
            if (couId != null) {
452
                coPersonIds.forEach(coPersonId -> {
453
                    Integer role = calls.getRoleId(coPersonId, couId);
454
                    calls.removeAdminRole(coPersonId, couId);
455
                    calls.removeMemberRole(coPersonId, couId, role);
456
                });
444 457
                authoritiesUpdater.update(email, old -> {
445 458
                    HashSet<SimpleGrantedAuthority> authorities = new HashSet<>((Collection<? extends SimpleGrantedAuthority>) old);
446 459
                    authorities.remove(new SimpleGrantedAuthority(authorizationService.manager(type, id)));
......
465 478
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN," +
466 479
            "@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
467 480
    public Response getMembers(@PathParam("type") String type, @PathParam("id") String id) {
468
        Integer couId = calls.getCouId(type, id,false);
469
        if(couId != null) {
481
        Integer couId = calls.getCouId(type, id, false);
482
        if (couId != null) {
470 483
            JsonArray members = calls.getUserNamesByCouId(couId, false);
471 484
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build();
472 485
        } else {
......
484 497
            "@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
485 498
    public Response getMembersEmail(@PathParam("type") String type, @PathParam("id") String id) {
486 499
        Integer couId = calls.getCouId(type, id, false);
487
        if(couId != null) {
500
        if (couId != null) {
488 501
            JsonArray members = calls.getUserEmailByCouId(couId, false);
489 502
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build();
490 503
        } else {
......
493 506
    }
494 507

  
495 508
    /**
509
     * Get the Identifiers of the members of a type(Community, etc.) with id(ee, egi, etc.)
510
     */
511
    @Path("/{type}/{id}/members/id")
512
    @GET
513
    @Produces(MediaType.APPLICATION_JSON)
514
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN," +
515
            "@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
516
    public Response getMembersId(@PathParam("type") String type, @PathParam("id") String id) {
517
        Integer couId = calls.getCouId(type, id, false);
518
        if (couId != null) {
519
            JsonArray members = calls.getUserIdByCouId(couId, false);
520
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build();
521
        } else {
522
            return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
523
        }
524
    }
525

  
526
    /**
496 527
     * Get the number of the members of a type(Community, etc.) with id(ee, egi, etc.)
497 528
     */
498 529
    @Path("/{type}/{id}/members/count")
......
501 532
    public Response getMembersCount(@PathParam("type") String type, @PathParam("id") String id) {
502 533
        Integer couId = calls.getCouId(type, id, false);
503 534
        int count = 0;
504
        if(couId != null) {
535
        if (couId != null) {
505 536
            count = calls.getUserNamesByCouId(couId, false).size();
506 537
        }
507 538
        return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(count).toString()).type(MediaType.APPLICATION_JSON).build();
......
515 546
    @Produces(MediaType.APPLICATION_JSON)
516 547
    public Response getManagers(@PathParam("type") String type, @PathParam("id") String id) {
517 548
        Integer couId = calls.getCouId(type, id);
518
        if(couId != null) {
549
        if (couId != null) {
519 550
            JsonArray managers = calls.getUserNamesByCouId(couId, true);
520 551
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build();
521 552
        } else {
......
531 562
    @Produces(MediaType.APPLICATION_JSON)
532 563
    public Response getManagersEmail(@PathParam("type") String type, @PathParam("id") String id) {
533 564
        Integer couId = calls.getCouId(type, id);
534
        if(couId != null) {
565
        if (couId != null) {
535 566
            JsonArray managers = calls.getUserEmailByCouId(couId, true);
536 567
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build();
537 568
        } else {
538 569
            return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
539 570
        }
540 571
    }
572

  
573
    /**
574
     * Get the Identifiers of the managers of a type(Community, etc.) with id(ee, egi, etc.)
575
     */
576
    @Path("/{type}/{id}/managers/id")
577
    @GET
578
    @Produces(MediaType.APPLICATION_JSON)
579
    public Response getManagersId(@PathParam("type") String type, @PathParam("id") String id) {
580
        Integer couId = calls.getCouId(type, id);
581
        if (couId != null) {
582
            JsonArray managers = calls.getUserIdByCouId(couId, true);
583
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build();
584
        } else {
585
            return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
586
        }
587
    }
541 588
}

Also available in: Unified diff