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) throws OperationFailedException { |
61 | 0 | HashMap<String,Boolean> screenPermissions = new HashMap<String,Boolean>(); |
62 | 0 | for (String screenName:screens){ |
63 | 0 | boolean hasAccess = hasScreenPermission(screenName); |
64 | 0 | screenPermissions.put(screenName, hasAccess); |
65 | 0 | } |
66 | |
|
67 | 0 | return screenPermissions; |
68 | |
} |
69 | |
|
70 | |
@Override |
71 | |
public HashMap<String, Boolean> getPermissions(ArrayList<String> permissionNames) throws OperationFailedException{ |
72 | 0 | String principalId = SecurityUtils.getCurrentPrincipalId(); |
73 | |
|
74 | 0 | LOG.debug("Retreiving permissions for permission name: " + permissionNames + " for " + principalId); |
75 | |
|
76 | |
|
77 | 0 | HashMap<String,Boolean> permissions = new HashMap<String,Boolean>(); |
78 | 0 | for (String permissionName:permissionNames){ |
79 | 0 | boolean hasAccess = getPermissionService().isAuthorized(principalId, "KS-SYS", permissionName, null, null); |
80 | 0 | permissions.put(permissionName, hasAccess); |
81 | 0 | } |
82 | |
|
83 | 0 | return permissions; |
84 | |
} |
85 | |
|
86 | |
@Override |
87 | |
public Boolean hasScreenPermission(String screenName) throws OperationFailedException { |
88 | 0 | String principalId = SecurityUtils.getCurrentPrincipalId(); |
89 | |
|
90 | 0 | LOG.debug("Retreiving screen permission " + screenName + " for " + principalId); |
91 | |
|
92 | 0 | AttributeSet permDetails = new AttributeSet(); |
93 | 0 | permDetails.put(StudentIdentityConstants.SCREEN_COMPONENT, screenName); |
94 | 0 | boolean hasAccess = false; |
95 | 0 | hasAccess = getPermissionService().isAuthorizedByTemplateName(principalId, |
96 | |
PermissionType.USE_SCREEN.getPermissionNamespace(), |
97 | |
PermissionType.USE_SCREEN.getPermissionTemplateName(), permDetails, |
98 | |
permDetails); |
99 | |
|
100 | 0 | LOG.debug(principalId + " access : " + hasAccess); |
101 | |
|
102 | 0 | return hasAccess; |
103 | |
} |
104 | |
|
105 | |
|
106 | |
@Override |
107 | |
public Boolean hasPermissionByPermissionName(String permissionName) throws OperationFailedException { |
108 | 0 | String principalId = SecurityUtils.getCurrentPrincipalId(); |
109 | |
|
110 | 0 | LOG.debug("Retreiving permissions for permission name: " + permissionName + " for " + principalId); |
111 | |
|
112 | |
|
113 | 0 | boolean hasAccess = false; |
114 | 0 | hasAccess = getPermissionService().isAuthorized(principalId, "KS-SYS", permissionName, null, null); |
115 | |
|
116 | 0 | LOG.debug(principalId + " access : " + hasAccess); |
117 | |
|
118 | 0 | return hasAccess; |
119 | |
} |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
@SuppressWarnings("unchecked") |
127 | |
@Override |
128 | |
public ArrayList<String> getPermissionsByType(PermissionType permissionType) throws OperationFailedException { |
129 | 0 | ArrayList<String> matchingPermissions = new ArrayList<String>(); |
130 | |
|
131 | 0 | String principalId = SecurityUtils.getCurrentPrincipalId(); |
132 | |
|
133 | 0 | LOG.debug("Retreiving permissions for template: " + permissionType.getPermissionTemplateName() + " for " + principalId); |
134 | |
|
135 | 0 | List<KimPermissionInfo> permissions = (List<KimPermissionInfo>)getPermissionService().getAuthorizedPermissionsByTemplateName( |
136 | |
principalId, permissionType.getPermissionNamespace(), permissionType.getPermissionTemplateName(), null, null); |
137 | |
|
138 | |
|
139 | 0 | for (KimPermissionInfo permissionInfo:permissions){ |
140 | 0 | matchingPermissions.add(permissionInfo.getName()); |
141 | |
} |
142 | |
|
143 | 0 | return matchingPermissions; |
144 | |
} |
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
@SuppressWarnings("unchecked") |
152 | |
@Override |
153 | |
public ArrayList<String> getPermissionsByType(PermissionType permissionType, HashMap<String,String> attributes) throws OperationFailedException { |
154 | 0 | ArrayList<String> matchingPermissions = new ArrayList<String>(); |
155 | 0 | AttributeSet attributeSet = new AttributeSet(attributes); |
156 | 0 | String principalId = SecurityUtils.getCurrentPrincipalId(); |
157 | |
|
158 | 0 | LOG.debug("Retreiving permissions for template: " + permissionType.getPermissionTemplateName() + " for " + principalId +" with details: "+attributes!=null?attributes.toString():"null"); |
159 | |
|
160 | 0 | List<KimPermissionInfo> permissions = (List<KimPermissionInfo>)getPermissionService().getAuthorizedPermissionsByTemplateName( |
161 | |
principalId, permissionType.getPermissionNamespace(), permissionType.getPermissionTemplateName(), attributeSet, attributeSet); |
162 | |
|
163 | |
|
164 | 0 | for (KimPermissionInfo permissionInfo:permissions){ |
165 | 0 | matchingPermissions.add(permissionInfo.getName()); |
166 | |
} |
167 | |
|
168 | 0 | return matchingPermissions; |
169 | |
} |
170 | |
|
171 | |
public void setPermissionService(IdentityManagementService permissionService) { |
172 | 0 | this.permissionService = permissionService; |
173 | 0 | } |
174 | |
|
175 | |
public IdentityManagementService getPermissionService()throws OperationFailedException{ |
176 | 0 | if(permissionService==null){ |
177 | 0 | throw new OperationFailedException("Permission Service is unavailable"); |
178 | |
} |
179 | |
|
180 | 0 | return permissionService; |
181 | |
} |
182 | |
|
183 | |
|
184 | |
} |