001 /** 002 * Copyright 2005-2012 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 */ 016 package org.kuali.rice.ken.service.impl; 017 018 import org.kuali.rice.core.framework.persistence.dao.GenericDao; 019 import org.kuali.rice.ken.bo.NotificationChannel; 020 import org.kuali.rice.ken.bo.NotificationProducer; 021 import org.kuali.rice.ken.service.NotificationAuthorizationService; 022 import org.kuali.rice.ken.util.NotificationConstants; 023 import org.kuali.rice.kim.api.KimConstants; 024 import org.kuali.rice.kim.api.group.Group; 025 import org.kuali.rice.kim.api.group.GroupService; 026 import org.kuali.rice.kim.api.identity.Person; 027 import org.kuali.rice.kim.api.services.KimApiServiceLocator; 028 029 import java.util.List; 030 031 032 /** 033 * NotificationAuthorizationService implementation - this is the default out-of-the-box implementation of the service. 034 * @author Kuali Rice Team (rice.collab@kuali.org) 035 */ 036 public class NotificationAuthorizationServiceImpl implements NotificationAuthorizationService { 037 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(NotificationAuthorizationServiceImpl.class); 038 039 private GenericDao businessObjectDao; 040 041 /** 042 * Constructs a NotificationAuthorizationServiceImpl class instance. 043 * @param businessObjectDao 044 */ 045 public NotificationAuthorizationServiceImpl(GenericDao businessObjectDao) { 046 this.businessObjectDao = businessObjectDao; 047 } 048 049 /** 050 * @see org.kuali.rice.ken.service.NotificationAuthorizationService#isProducerAuthorizedToSendNotificationForChannel(org.kuali.rice.ken.bo.NotificationProducer, org.kuali.rice.ken.bo.NotificationChannel) 051 */ 052 public boolean isProducerAuthorizedToSendNotificationForChannel(NotificationProducer producer, NotificationChannel channel) { 053 List channels = producer.getChannels(); 054 055 if(channels.contains(channel)) { 056 return true; 057 } else { 058 return false; 059 } 060 } 061 062 /** 063 * Implements by calling the is user member of service in KEW's workgroup service, looking for a specific membership 064 * in the "NotificationAdmin" workgroup. 065 * @see org.kuali.rice.ken.service.NotificationAuthorizationService#isUserAdministrator(java.lang.String) 066 */ 067 public boolean isUserAdministrator(String userId) { 068 String groupNameId = NotificationConstants.KEW_CONSTANTS.NOTIFICATION_ADMIN_GROUP_NAME; 069 Person user = KimApiServiceLocator.getPersonService().getPerson(userId); 070 if (user == null) { 071 return false; 072 } 073 074 final GroupService groupService = KimApiServiceLocator.getGroupService(); 075 Group group = groupService.getGroupByNamespaceCodeAndName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, 076 groupNameId); 077 return group == null ? false : groupService.isMemberOfGroup(user.getPrincipalId(), group.getId()); 078 } 079 }