001/** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.ken.service.impl; 017 018import org.kuali.rice.ken.bo.NotificationChannelBo; 019import org.kuali.rice.ken.bo.NotificationProducerBo; 020import org.kuali.rice.ken.service.NotificationAuthorizationService; 021import org.kuali.rice.ken.util.NotificationConstants; 022import org.kuali.rice.kim.api.KimConstants; 023import org.kuali.rice.kim.api.group.Group; 024import org.kuali.rice.kim.api.group.GroupService; 025import org.kuali.rice.kim.api.identity.Person; 026import org.kuali.rice.kim.api.services.KimApiServiceLocator; 027 028import java.util.List; 029 030 031/** 032 * NotificationAuthorizationService implementation - this is the default out-of-the-box implementation of the service. 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 */ 035public class NotificationAuthorizationServiceImpl implements NotificationAuthorizationService { 036 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(NotificationAuthorizationServiceImpl.class); 037 038 /** 039 * @see org.kuali.rice.ken.service.NotificationAuthorizationService#isProducerAuthorizedToSendNotificationForChannel(org.kuali.rice.ken.bo.NotificationProducerBo, org.kuali.rice.ken.bo.NotificationChannelBo) 040 */ 041 public boolean isProducerAuthorizedToSendNotificationForChannel(NotificationProducerBo producer, NotificationChannelBo channel) { 042 List<Long> channelIds = producer.getChannelIds(); 043 044 if(channelIds.contains(channel.getId())) { 045 return true; 046 } else { 047 return false; 048 } 049 } 050 051 /** 052 * Implements by calling the is user member of service in KEW's workgroup service, looking for a specific membership 053 * in the "NotificationAdmin" workgroup. 054 * @see org.kuali.rice.ken.service.NotificationAuthorizationService#isUserAdministrator(java.lang.String) 055 */ 056 public boolean isUserAdministrator(String userId) { 057 String groupNameId = NotificationConstants.KEW_CONSTANTS.NOTIFICATION_ADMIN_GROUP_NAME; 058 Person user = KimApiServiceLocator.getPersonService().getPerson(userId); 059 if (user == null) { 060 return false; 061 } 062 063 final GroupService groupService = KimApiServiceLocator.getGroupService(); 064 Group group = groupService.getGroupByNamespaceCodeAndName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, 065 groupNameId); 066 return group == null ? false : groupService.isMemberOfGroup(user.getPrincipalId(), group.getId()); 067 } 068}