1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ken.service.impl;
17
18 import org.kuali.rice.ken.bo.NotificationChannelBo;
19 import org.kuali.rice.ken.bo.NotificationProducerBo;
20 import org.kuali.rice.ken.service.NotificationAuthorizationService;
21 import org.kuali.rice.ken.util.NotificationConstants;
22 import org.kuali.rice.kim.api.KimConstants;
23 import org.kuali.rice.kim.api.group.Group;
24 import org.kuali.rice.kim.api.group.GroupService;
25 import org.kuali.rice.kim.api.identity.Person;
26 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
27
28 import java.util.List;
29
30
31
32
33
34
35 public class NotificationAuthorizationServiceImpl implements NotificationAuthorizationService {
36 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(NotificationAuthorizationServiceImpl.class);
37
38
39
40
41 public boolean isProducerAuthorizedToSendNotificationForChannel(NotificationProducerBo producer, NotificationChannelBo channel) {
42 List<Long> channelIds = producer.getChannelIds();
43
44 if(channelIds.contains(channel.getId())) {
45 return true;
46 } else {
47 return false;
48 }
49 }
50
51
52
53
54
55
56 public boolean isUserAdministrator(String userId) {
57 String groupNameId = NotificationConstants.KEW_CONSTANTS.NOTIFICATION_ADMIN_GROUP_NAME;
58 Person user = KimApiServiceLocator.getPersonService().getPerson(userId);
59 if (user == null) {
60 return false;
61 }
62
63 final GroupService groupService = KimApiServiceLocator.getGroupService();
64 Group group = groupService.getGroupByNamespaceCodeAndName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE,
65 groupNameId);
66 return group == null ? false : groupService.isMemberOfGroup(user.getPrincipalId(), group.getId());
67 }
68 }