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.rice.kim.bo.types.dto.AttributeSet; |
22 | |
import org.kuali.rice.kim.service.IdentityManagementService; |
23 | |
import org.kuali.student.common.util.security.SecurityUtils; |
24 | |
import org.kuali.student.core.authorization.ui.client.service.AuthorizationRpcService; |
25 | |
|
26 | |
import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
27 | |
|
28 | 0 | public class AuthorizationRpcGwtServlet extends RemoteServiceServlet implements AuthorizationRpcService{ |
29 | |
|
30 | |
private static final long serialVersionUID = 8568346881191827247L; |
31 | |
private IdentityManagementService 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 | AttributeSet roleQuals = null; |
48 | 0 | if (roleQualifications != null) { |
49 | 0 | roleQuals = new AttributeSet(roleQualifications); |
50 | |
} |
51 | 0 | AttributeSet permDetails = null; |
52 | 0 | if (permissionDetails != null) { |
53 | 0 | permDetails = new AttributeSet(permissionDetails); |
54 | |
} |
55 | 0 | return Boolean.valueOf(permissionService.isAuthorizedByTemplateName(currentUser, namespace, permissionTemplateName, permDetails, roleQuals)); |
56 | |
} |
57 | |
|
58 | |
protected String getCurrentUser() { |
59 | 0 | String username = SecurityUtils.getCurrentPrincipalId(); |
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(IdentityManagementService permissionService) { |
68 | 0 | this.permissionService = permissionService; |
69 | 0 | } |
70 | |
|
71 | |
} |