1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
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 | |
|
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 | |
} |