View Javadoc

1   /**
2    * Copyright 2005-2013 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.krms.impl.authorization;
17  
18  import org.kuali.rice.core.api.util.RiceKeyConstants;
19  import org.kuali.rice.kim.api.permission.PermissionService;
20  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
21  import org.kuali.rice.krad.util.GlobalVariables;
22  import org.kuali.rice.krad.util.KRADConstants;
23  import org.kuali.rice.krms.api.repository.context.ContextDefinition;
24  import org.kuali.rice.krms.impl.repository.ContextBoService;
25  import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator;
26  
27  import java.util.HashMap;
28  import java.util.Map;
29  
30  public class AgendaAuthorizationServiceImpl implements AgendaAuthorizationService {
31  
32      static final String NAMESPACE_CODE = "namespaceCode";
33  
34      @Override
35      public boolean isAuthorized(String permissionName, String contextId) {
36          String namespace = "";
37          if (contextId != null) {
38              ContextDefinition context = getContextBoService().getContextByContextId(contextId);
39              if (context != null) { // business rules should have already reported this as an error.
40                  namespace = context.getNamespace();
41              }
42          }
43  
44          Map<String, String> qualification = new HashMap<String, String>();
45          boolean isAuthorized = getPermissionService().isAuthorized(
46                  GlobalVariables.getUserSession().getPrincipalId(),
47                  namespace,
48                  permissionName,
49                  qualification);
50          return isAuthorized;
51      }
52  
53      /**
54       * return the contextBoService
55       */
56      private ContextBoService getContextBoService() {
57          return KrmsRepositoryServiceLocator.getContextBoService();
58      }
59  
60      /**
61       * returns the permissionService
62       */
63      private PermissionService getPermissionService() {
64          return KimApiServiceLocator.getPermissionService();
65      }
66  }