View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * NotificationAuthorizationService implementation - this is the default out-of-the-box implementation of the service.
33   * @author Kuali Rice Team (rice.collab@kuali.org)
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       * @see org.kuali.rice.ken.service.NotificationAuthorizationService#isProducerAuthorizedToSendNotificationForChannel(org.kuali.rice.ken.bo.NotificationProducerBo, org.kuali.rice.ken.bo.NotificationChannelBo)
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       * Implements by calling the is user member of service in KEW's workgroup service, looking for a specific membership
53       * in the "NotificationAdmin" workgroup.
54       * @see org.kuali.rice.ken.service.NotificationAuthorizationService#isUserAdministrator(java.lang.String)
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  }