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.core.framework.persistence.dao.GenericDao;
19 import org.kuali.rice.ken.bo.NotificationChannel;
20 import org.kuali.rice.ken.bo.NotificationProducer;
21 import org.kuali.rice.ken.service.NotificationAuthorizationService;
22 import org.kuali.rice.ken.util.NotificationConstants;
23 import org.kuali.rice.kim.api.KimConstants;
24 import org.kuali.rice.kim.api.group.Group;
25 import org.kuali.rice.kim.api.group.GroupService;
26 import org.kuali.rice.kim.api.identity.Person;
27 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
28
29 import java.util.List;
30
31
32
33
34
35
36 public class NotificationAuthorizationServiceImpl implements NotificationAuthorizationService {
37 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(NotificationAuthorizationServiceImpl.class);
38
39 private GenericDao businessObjectDao;
40
41
42
43
44
45 public NotificationAuthorizationServiceImpl(GenericDao businessObjectDao) {
46 this.businessObjectDao = businessObjectDao;
47 }
48
49
50
51
52 public boolean isProducerAuthorizedToSendNotificationForChannel(NotificationProducer producer, NotificationChannel channel) {
53 List channels = producer.getChannels();
54
55 if(channels.contains(channel)) {
56 return true;
57 } else {
58 return false;
59 }
60 }
61
62
63
64
65
66
67 public boolean isUserAdministrator(String userId) {
68 String groupNameId = NotificationConstants.KEW_CONSTANTS.NOTIFICATION_ADMIN_GROUP_NAME;
69 Person user = KimApiServiceLocator.getPersonService().getPerson(userId);
70 if (user == null) {
71 return false;
72 }
73
74 final GroupService groupService = KimApiServiceLocator.getGroupService();
75 Group group = groupService.getGroupByNameAndNamespaceCode(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE,
76 groupNameId);
77 return group == null ? false : groupService.isMemberOfGroup(user.getPrincipalId(), group.getId());
78 }
79 }