1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.common.ui.server.gwt; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.HashMap; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import org.apache.log4j.Logger; |
23 | |
import org.kuali.rice.kim.bo.role.dto.KimPermissionInfo; |
24 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
25 | |
import org.kuali.rice.kim.service.IdentityManagementService; |
26 | |
import org.kuali.student.common.rice.StudentIdentityConstants; |
27 | |
import org.kuali.student.common.rice.authorization.PermissionType; |
28 | |
import org.kuali.student.common.ui.client.service.SecurityRpcService; |
29 | |
import org.kuali.student.common.ui.client.service.exceptions.OperationFailedException; |
30 | |
import org.kuali.student.common.util.security.SecurityUtils; |
31 | |
|
32 | |
import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class SecurityRpcGwtServlet extends RemoteServiceServlet implements SecurityRpcService{ |
47 | |
|
48 | 0 | final Logger LOG = Logger.getLogger(SecurityRpcGwtServlet.class); |
49 | |
|
50 | |
private static final long serialVersionUID = 1L; |
51 | |
|
52 | |
private IdentityManagementService permissionService; |
53 | |
|
54 | |
@Override |
55 | |
public String getPrincipalUsername(){ |
56 | 0 | return SecurityUtils.getCurrentPrincipalName(); |
57 | |
} |
58 | |
|
59 | |
@Override |
60 | |
public HashMap<String, Boolean> getScreenPermissions(ArrayList<String> screens) { |
61 | |
|
62 | 0 | return null; |
63 | |
} |
64 | |
|
65 | |
@Override |
66 | |
public HashMap<String, Boolean> getPermissions(ArrayList<String> permissionNames) throws OperationFailedException{ |
67 | 0 | String principalId = SecurityUtils.getCurrentPrincipalId(); |
68 | |
|
69 | 0 | LOG.debug("Retreiving permissions for permission name: " + permissionNames + " for " + principalId); |
70 | |
|
71 | |
|
72 | 0 | HashMap<String,Boolean> permissions = new HashMap<String,Boolean>(); |
73 | 0 | for (String permissionName:permissionNames){ |
74 | 0 | boolean hasAccess = getPermissionService().isAuthorized(principalId, "KS-SYS", permissionName, null, null); |
75 | 0 | permissions.put(permissionName, hasAccess); |
76 | 0 | } |
77 | |
|
78 | 0 | return permissions; |
79 | |
} |
80 | |
|
81 | |
@Override |
82 | |
public Boolean hasScreenPermission(String screenName) throws OperationFailedException { |
83 | 0 | String principalId = SecurityUtils.getCurrentPrincipalId(); |
84 | |
|
85 | 0 | LOG.debug("Retreiving screen permission " + screenName + " for " + principalId); |
86 | |
|
87 | 0 | AttributeSet permDetails = new AttributeSet(); |
88 | 0 | permDetails.put(StudentIdentityConstants.SCREEN_COMPONENT, screenName); |
89 | 0 | boolean hasAccess = false; |
90 | 0 | hasAccess = getPermissionService().isAuthorizedByTemplateName(principalId, |
91 | |
PermissionType.USE_SCREEN.getPermissionNamespace(), |
92 | |
PermissionType.USE_SCREEN.getPermissionTemplateName(), permDetails, |
93 | |
permDetails); |
94 | |
|
95 | 0 | LOG.debug(principalId + " access : " + hasAccess); |
96 | |
|
97 | 0 | return hasAccess; |
98 | |
} |
99 | |
|
100 | |
|
101 | |
@Override |
102 | |
public Boolean hasPermissionByPermissionName(String permissionName) throws OperationFailedException { |
103 | 0 | String principalId = SecurityUtils.getCurrentPrincipalId(); |
104 | |
|
105 | 0 | LOG.debug("Retreiving permissions for permission name: " + permissionName + " for " + principalId); |
106 | |
|
107 | |
|
108 | 0 | boolean hasAccess = false; |
109 | 0 | hasAccess = getPermissionService().isAuthorized(principalId, "KS-SYS", permissionName, null, null); |
110 | |
|
111 | 0 | LOG.debug(principalId + " access : " + hasAccess); |
112 | |
|
113 | 0 | return hasAccess; |
114 | |
} |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
@SuppressWarnings("unchecked") |
122 | |
@Override |
123 | |
public ArrayList<String> getPermissionsByType(PermissionType permissionType) throws OperationFailedException { |
124 | 0 | ArrayList<String> matchingPermissions = new ArrayList<String>(); |
125 | |
|
126 | 0 | String principalId = SecurityUtils.getCurrentPrincipalId(); |
127 | |
|
128 | 0 | LOG.debug("Retreiving permissions for template: " + permissionType.getPermissionTemplateName() + " for " + principalId); |
129 | |
|
130 | 0 | List<KimPermissionInfo> permissions = (List<KimPermissionInfo>)getPermissionService().getAuthorizedPermissionsByTemplateName( |
131 | |
principalId, permissionType.getPermissionNamespace(), permissionType.getPermissionTemplateName(), null, null); |
132 | |
|
133 | |
|
134 | 0 | for (KimPermissionInfo permissionInfo:permissions){ |
135 | 0 | matchingPermissions.add(permissionInfo.getName()); |
136 | |
} |
137 | |
|
138 | 0 | return matchingPermissions; |
139 | |
} |
140 | |
|
141 | |
|
142 | |
public void setPermissionService(IdentityManagementService permissionService) { |
143 | 0 | this.permissionService = permissionService; |
144 | 0 | } |
145 | |
|
146 | |
public IdentityManagementService getPermissionService()throws OperationFailedException{ |
147 | 0 | if(permissionService==null){ |
148 | 0 | throw new OperationFailedException("Permission Service is unavailable"); |
149 | |
} |
150 | |
|
151 | 0 | return permissionService; |
152 | |
} |
153 | |
|
154 | |
|
155 | |
} |