001/**
002 * Copyright 2005-2016 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.krms.impl.authorization;
017
018import org.kuali.rice.core.api.util.RiceKeyConstants;
019import org.kuali.rice.kim.api.permission.PermissionService;
020import org.kuali.rice.kim.api.services.KimApiServiceLocator;
021import org.kuali.rice.krad.util.GlobalVariables;
022import org.kuali.rice.krad.util.KRADConstants;
023import org.kuali.rice.krms.api.repository.context.ContextDefinition;
024import org.kuali.rice.krms.impl.repository.ContextBoService;
025import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator;
026
027import java.util.HashMap;
028import java.util.Map;
029
030public class AgendaAuthorizationServiceImpl implements AgendaAuthorizationService {
031
032    static final String NAMESPACE_CODE = "namespaceCode";
033
034    @Override
035    public boolean isAuthorized(String permissionName, String contextId) {
036        String namespace = "";
037        if (contextId != null) {
038            ContextDefinition context = getContextBoService().getContextByContextId(contextId);
039            if (context != null) { // business rules should have already reported this as an error.
040                namespace = context.getNamespace();
041            }
042        }
043
044        Map<String, String> qualification = new HashMap<String, String>();
045        boolean isAuthorized = getPermissionService().isAuthorized(
046                GlobalVariables.getUserSession().getPrincipalId(),
047                namespace,
048                permissionName,
049                qualification);
050        return isAuthorized;
051    }
052
053    /**
054     * return the contextBoService
055     */
056    private ContextBoService getContextBoService() {
057        return KrmsRepositoryServiceLocator.getContextBoService();
058    }
059
060    /**
061     * returns the permissionService
062     */
063    private PermissionService getPermissionService() {
064        return KimApiServiceLocator.getPermissionService();
065    }
066}