View Javadoc

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