Coverage Report - org.kuali.student.core.authorization.ui.server.gwt.AuthorizationRpcGwtServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
AuthorizationRpcGwtServlet
0%
0/19
0%
0/10
2.2
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.core.authorization.ui.server.gwt;
 17  
 
 18  
 import java.util.Map;
 19  
 
 20  
 import org.apache.commons.lang.StringUtils;
 21  
 import org.kuali.student.common.util.security.SecurityUtils;
 22  
 import org.kuali.student.core.authorization.ui.client.service.AuthorizationRpcService;
 23  
 
 24  
 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
 25  
 import java.util.LinkedHashMap;
 26  
 import org.kuali.rice.kim.api.permission.PermissionService;
 27  
 
 28  0
 public class AuthorizationRpcGwtServlet extends RemoteServiceServlet implements AuthorizationRpcService{
 29  
 
 30  
         private static final long serialVersionUID = 8568346881191827247L;
 31  
         private PermissionService permissionService;
 32  
 
 33  
         @Override
 34  
         public Boolean isAuthorizedForPermission(String namespace, String permissionTemplateName) {
 35  0
                 return isAuthorizedForPermissionWithDetailsAndQualifications(namespace, permissionTemplateName, null, null);
 36  
         }
 37  
 
 38  
         public Boolean isAuthorizedForPermissionWithQualifications(String namespace, String permissionTemplateName, Map<String,String> roleQualifications) {
 39  0
                 return isAuthorizedForPermissionWithDetailsAndQualifications(namespace, permissionTemplateName, roleQualifications, null);
 40  
         }
 41  
 
 42  
         public Boolean isAuthorizedForPermissionWithDetailsAndQualifications(String namespace, String permissionTemplateName, Map<String,String> roleQualifications, Map<String,String> permissionDetails) {
 43  0
                 String currentUser = getCurrentUser();
 44  0
                 if (StringUtils.isBlank(currentUser)) {
 45  0
                         throw new RuntimeException("Unable to find current user or backdoor user.");
 46  
                 }
 47  0
                 Map<String,String> roleQuals = null;
 48  0
                 if (roleQualifications != null) {
 49  0
                         roleQuals = new LinkedHashMap<String,String>(roleQualifications);
 50  
                 }
 51  0
                 Map<String,String> permDetails = null;
 52  0
                 if (permissionDetails != null) {
 53  0
                         permDetails = new LinkedHashMap<String,String>(permissionDetails);
 54  
                 }
 55  0
                 return  Boolean.valueOf(permissionService.isAuthorizedByTemplate(currentUser, namespace, permissionTemplateName, permDetails, roleQuals));
 56  
         }
 57  
 
 58  
         protected String getCurrentUser() {
 59  0
                 String username = SecurityUtils.getCurrentUserId();
 60  
                 //backdoorId is only for convenience
 61  0
                 if(username==null&&this.getThreadLocalRequest().getSession().getAttribute("backdoorId")!=null){
 62  0
                         username=(String)this.getThreadLocalRequest().getSession().getAttribute("backdoorId");
 63  
         }
 64  0
                 return username;
 65  
         }
 66  
 
 67  
         public void setPermissionService(PermissionService permissionService) {
 68  0
                 this.permissionService = permissionService;
 69  0
         }
 70  
 
 71  
 }