| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kim.web.struts.action; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.apache.struts.action.ActionForm; |
| 20 | |
import org.apache.struts.action.ActionForward; |
| 21 | |
import org.apache.struts.action.ActionMapping; |
| 22 | |
import org.kuali.rice.core.util.RiceConstants; |
| 23 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
| 24 | |
import org.kuali.rice.kew.exception.WorkflowException; |
| 25 | |
import org.kuali.rice.kim.bo.Group; |
| 26 | |
import org.kuali.rice.kim.bo.Role; |
| 27 | |
import org.kuali.rice.kim.bo.entity.KimPrincipal; |
| 28 | |
import org.kuali.rice.kim.bo.entity.dto.KimPrincipalInfo; |
| 29 | |
import org.kuali.rice.kim.bo.group.dto.GroupInfo; |
| 30 | |
import org.kuali.rice.kim.bo.role.dto.KimRoleInfo; |
| 31 | |
import org.kuali.rice.kim.bo.role.impl.KimResponsibilityImpl; |
| 32 | |
import org.kuali.rice.kim.bo.ui.*; |
| 33 | |
import org.kuali.rice.kim.document.IdentityManagementRoleDocument; |
| 34 | |
import org.kuali.rice.kim.lookup.KimTypeLookupableHelperServiceImpl; |
| 35 | |
import org.kuali.rice.kim.rule.event.ui.AddDelegationMemberEvent; |
| 36 | |
import org.kuali.rice.kim.rule.event.ui.AddMemberEvent; |
| 37 | |
import org.kuali.rice.kim.rule.event.ui.AddPermissionEvent; |
| 38 | |
import org.kuali.rice.kim.rule.event.ui.AddResponsibilityEvent; |
| 39 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
| 40 | |
import org.kuali.rice.kim.service.KIMServiceLocatorWeb; |
| 41 | |
import org.kuali.rice.kim.util.KimConstants; |
| 42 | |
import org.kuali.rice.kim.web.struts.form.IdentityManagementRoleDocumentForm; |
| 43 | |
import org.kuali.rice.kns.document.Document; |
| 44 | |
import org.kuali.rice.kns.question.ConfirmationQuestion; |
| 45 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
| 46 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
| 47 | |
import org.kuali.rice.kns.util.GlobalVariables; |
| 48 | |
import org.kuali.rice.kns.util.KNSConstants; |
| 49 | |
import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase; |
| 50 | |
import org.kuali.rice.kns.web.struts.form.KualiTableRenderFormMetadata; |
| 51 | |
import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument; |
| 52 | |
|
| 53 | |
import javax.servlet.http.HttpServletRequest; |
| 54 | |
import javax.servlet.http.HttpServletResponse; |
| 55 | |
import java.sql.Timestamp; |
| 56 | |
import java.util.*; |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
public class IdentityManagementRoleDocumentAction extends IdentityManagementDocumentActionBase { |
| 64 | |
|
| 65 | |
public static final String CHANGE_DEL_ROLE_MEMBER_METHOD_TO_CALL = "changeDelegationRoleMember"; |
| 66 | |
public static final String SWITCH_TO_ROLE_MEMBER_METHOD_TO_CALL = "jumpToRoleMember"; |
| 67 | |
public static final String REMOVE_AFFECTED_DELEGATES_QUESTION_ID = "RemoveAffectedDelegates"; |
| 68 | |
|
| 69 | 0 | protected List<String> methodToCallToUncheckedList = new ArrayList<String>(); |
| 70 | |
{ |
| 71 | 0 | methodToCallToUncheckedList.add(CHANGE_DEL_ROLE_MEMBER_METHOD_TO_CALL); |
| 72 | 0 | methodToCallToUncheckedList.add(CHANGE_MEMBER_TYPE_CODE_METHOD_TO_CALL); |
| 73 | 0 | methodToCallToUncheckedList.add(CHANGE_NAMESPACE_METHOD_TO_CALL); |
| 74 | 0 | methodToCallToUncheckedList.add(SWITCH_TO_ROLE_MEMBER_METHOD_TO_CALL); |
| 75 | |
} |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
public IdentityManagementRoleDocumentAction() { |
| 81 | 0 | super(); |
| 82 | 0 | for(String methodToCallToUncheck: methodToCallToUncheckedList) |
| 83 | 0 | addMethodToCallToUncheckedList(methodToCallToUncheck); |
| 84 | 0 | } |
| 85 | |
|
| 86 | |
public ActionForward sort(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 87 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
| 88 | 0 | this.createDocument(roleDocumentForm); |
| 89 | |
|
| 90 | |
|
| 91 | 0 | Document document = roleDocumentForm.getDocument(); |
| 92 | 0 | KualiWorkflowDocument workflowDocument = roleDocumentForm.getDocument().getDocumentHeader().getWorkflowDocument(); |
| 93 | 0 | roleDocumentForm.populateHeaderFields(workflowDocument); |
| 94 | 0 | roleDocumentForm.setDocId(document.getDocumentNumber()); |
| 95 | 0 | roleDocumentForm.setCanAssignRole(validAssignRole(roleDocumentForm.getRoleDocument())); |
| 96 | |
|
| 97 | 0 | if (KimTypeLookupableHelperServiceImpl.hasDerivedRoleTypeService(roleDocumentForm.getRoleDocument().getKimType())) { |
| 98 | 0 | roleDocumentForm.setCanModifyAssignees(false); |
| 99 | |
} |
| 100 | 0 | GlobalVariables.getUserSession().addObject(KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_SHORT_KEY, roleDocumentForm.getRoleDocument()); |
| 101 | 0 | return refresh(mapping, roleDocumentForm, request, response); |
| 102 | |
} |
| 103 | |
|
| 104 | |
@Override |
| 105 | |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
| 106 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 107 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
| 108 | 0 | if ( roleDocumentForm.getRoleId() == null ) { |
| 109 | 0 | String roleId = request.getParameter(KimConstants.PrimaryKeyConstants.ROLE_ID); |
| 110 | 0 | roleDocumentForm.setRoleId(roleId); |
| 111 | |
} |
| 112 | |
|
| 113 | 0 | String kimTypeId = request.getParameter(KimConstants.PrimaryKeyConstants.KIM_TYPE_ID); |
| 114 | |
|
| 115 | 0 | setKimType(kimTypeId, roleDocumentForm); |
| 116 | |
|
| 117 | 0 | KualiTableRenderFormMetadata memberTableMetadata = roleDocumentForm.getMemberTableMetadata(); |
| 118 | 0 | if (roleDocumentForm.getRoleDocument()!=null && roleDocumentForm.getMemberRows() != null) { |
| 119 | 0 | memberTableMetadata.jumpToPage(memberTableMetadata.getViewedPageNumber(), roleDocumentForm.getMemberRows().size(), roleDocumentForm.getRecordsPerPage()); |
| 120 | |
} |
| 121 | |
|
| 122 | |
|
| 123 | 0 | ActionForward forward = promptForAffectedDelegates(mapping, form, request, response, |
| 124 | |
roleDocumentForm); |
| 125 | |
|
| 126 | 0 | if (forward != null) return forward; |
| 127 | |
|
| 128 | 0 | forward = super.execute(mapping, roleDocumentForm, request, response); |
| 129 | |
|
| 130 | 0 | roleDocumentForm.setCanAssignRole(validAssignRole(roleDocumentForm.getRoleDocument())); |
| 131 | 0 | if(KimTypeLookupableHelperServiceImpl.hasDerivedRoleTypeService(roleDocumentForm.getRoleDocument().getKimType())) { |
| 132 | 0 | roleDocumentForm.setCanModifyAssignees(false); |
| 133 | |
} |
| 134 | 0 | GlobalVariables.getUserSession().addObject(KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_SHORT_KEY, roleDocumentForm.getRoleDocument()); |
| 135 | 0 | return forward; |
| 136 | |
} |
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
@Override |
| 144 | |
protected void loadDocument(KualiDocumentFormBase form) |
| 145 | |
throws WorkflowException { |
| 146 | 0 | super.loadDocument(form); |
| 147 | |
|
| 148 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
| 149 | 0 | setKimType(roleDocumentForm.getRoleDocument().getRoleTypeId(), roleDocumentForm); |
| 150 | 0 | getUiDocumentService().setDelegationMembersInDocument( roleDocumentForm.getRoleDocument() ); |
| 151 | |
|
| 152 | 0 | roleDocumentForm.setMember(roleDocumentForm.getRoleDocument().getBlankMember()); |
| 153 | 0 | roleDocumentForm.setDelegationMember(roleDocumentForm.getRoleDocument().getBlankDelegationMember()); |
| 154 | |
|
| 155 | 0 | KualiTableRenderFormMetadata memberTableMetadata = roleDocumentForm.getMemberTableMetadata(); |
| 156 | 0 | if (roleDocumentForm.getMemberRows() != null) { |
| 157 | 0 | memberTableMetadata.jumpToFirstPage(roleDocumentForm.getMemberRows().size(), roleDocumentForm.getRecordsPerPage()); |
| 158 | |
} |
| 159 | 0 | } |
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
@Override |
| 167 | |
protected void createDocument(KualiDocumentFormBase form) |
| 168 | |
throws WorkflowException { |
| 169 | 0 | super.createDocument(form); |
| 170 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
| 171 | |
|
| 172 | 0 | if ( roleDocumentForm.getRoleId() == null ) { |
| 173 | 0 | roleDocumentForm.getRoleDocument().setKimType(roleDocumentForm.getKimType()); |
| 174 | 0 | roleDocumentForm.getRoleDocument().initializeDocumentForNewRole(); |
| 175 | 0 | roleDocumentForm.setRoleId( roleDocumentForm.getRoleDocument().getRoleId() ); |
| 176 | 0 | roleDocumentForm.setKimType(KIMServiceLocatorWeb.getTypeInfoService().getKimType(roleDocumentForm.getRoleDocument().getRoleTypeId())); |
| 177 | |
} else { |
| 178 | 0 | loadRoleIntoDocument( roleDocumentForm.getRoleId(), roleDocumentForm ); |
| 179 | |
} |
| 180 | |
|
| 181 | 0 | roleDocumentForm.setMember(roleDocumentForm.getRoleDocument().getBlankMember()); |
| 182 | 0 | roleDocumentForm.setDelegationMember(roleDocumentForm.getRoleDocument().getBlankDelegationMember()); |
| 183 | |
|
| 184 | 0 | KualiTableRenderFormMetadata memberTableMetadata = roleDocumentForm.getMemberTableMetadata(); |
| 185 | 0 | if (roleDocumentForm.getMemberRows() != null) { |
| 186 | 0 | memberTableMetadata.jumpToFirstPage(roleDocumentForm.getMemberRows().size(), roleDocumentForm.getRecordsPerPage()); |
| 187 | |
} |
| 188 | 0 | } |
| 189 | |
|
| 190 | |
protected void setKimType(String kimTypeId, IdentityManagementRoleDocumentForm roleDocumentForm){ |
| 191 | 0 | if ( StringUtils.isNotBlank(kimTypeId) ) { |
| 192 | 0 | roleDocumentForm.setKimType(KIMServiceLocatorWeb.getTypeInfoService().getKimType(kimTypeId)); |
| 193 | 0 | if (roleDocumentForm.getRoleDocument() != null) { |
| 194 | 0 | roleDocumentForm.getRoleDocument().setKimType(roleDocumentForm.getKimType()); |
| 195 | |
} |
| 196 | 0 | } else if ( roleDocumentForm.getRoleDocument() != null && StringUtils.isNotBlank( roleDocumentForm.getRoleDocument().getRoleTypeId() ) ) { |
| 197 | 0 | roleDocumentForm.setKimType(KIMServiceLocatorWeb.getTypeInfoService().getKimType( |
| 198 | |
roleDocumentForm.getRoleDocument().getRoleTypeId())); |
| 199 | 0 | roleDocumentForm.getRoleDocument().setKimType(roleDocumentForm.getKimType()); |
| 200 | |
} |
| 201 | 0 | } |
| 202 | |
|
| 203 | |
protected void loadRoleIntoDocument( String roleId, IdentityManagementRoleDocumentForm roleDocumentForm){ |
| 204 | 0 | KimRoleInfo role = KIMServiceLocator.getRoleService().getRole(roleId); |
| 205 | 0 | roleDocumentForm.getRoleDocument().setMemberMetaDataTypeToSort(roleDocumentForm.getMemberTableMetadata().getColumnToSortIndex()); |
| 206 | 0 | getUiDocumentService().loadRoleDoc(roleDocumentForm.getRoleDocument(), role); |
| 207 | 0 | } |
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
public String getActionName(){ |
| 213 | 0 | return KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_ACTION; |
| 214 | |
} |
| 215 | |
|
| 216 | |
protected boolean validAssignRole(IdentityManagementRoleDocument document){ |
| 217 | 0 | boolean rulePassed = true; |
| 218 | 0 | if(StringUtils.isNotEmpty(document.getRoleNamespace())){ |
| 219 | 0 | Map<String,String> additionalPermissionDetails = new HashMap<String,String>(); |
| 220 | 0 | additionalPermissionDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, document.getRoleNamespace()); |
| 221 | 0 | additionalPermissionDetails.put(KimConstants.AttributeConstants.ROLE_NAME, document.getRoleName()); |
| 222 | 0 | if (!getDocumentHelperService().getDocumentAuthorizer(document).isAuthorizedByTemplate( |
| 223 | |
document, |
| 224 | |
KimConstants.NAMESPACE_CODE, |
| 225 | |
KimConstants.PermissionTemplateNames.ASSIGN_ROLE, |
| 226 | |
GlobalVariables.getUserSession().getPrincipalId(), |
| 227 | |
additionalPermissionDetails, null)){ |
| 228 | 0 | rulePassed = false; |
| 229 | |
} |
| 230 | |
} |
| 231 | 0 | return rulePassed; |
| 232 | |
} |
| 233 | |
|
| 234 | |
public ActionForward changeMemberTypeCode(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 235 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
| 236 | 0 | roleDocumentForm.getMember().setMemberId(""); |
| 237 | 0 | return refresh(mapping, roleDocumentForm, request, response); |
| 238 | |
} |
| 239 | |
|
| 240 | |
public ActionForward changeDelegationMemberTypeCode(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 241 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
| 242 | 0 | KimDocumentRoleMember roleMember = roleDocumentForm.getRoleDocument().getMember(roleDocumentForm.getDelegationMember().getRoleMemberId()); |
| 243 | 0 | if(roleMember!=null){ |
| 244 | |
RoleDocumentDelegationMemberQualifier delegationMemberQualifier; |
| 245 | 0 | for(KimDocumentRoleQualifier roleQualifier: roleMember.getQualifiers()){ |
| 246 | 0 | delegationMemberQualifier = roleDocumentForm.getDelegationMember().getQualifier(roleQualifier.getKimAttrDefnId()); |
| 247 | 0 | delegationMemberQualifier.setAttrVal(roleQualifier.getAttrVal()); |
| 248 | |
} |
| 249 | |
} |
| 250 | 0 | return refresh(mapping, roleDocumentForm, request, response); |
| 251 | |
} |
| 252 | |
|
| 253 | |
public ActionForward addResponsibility(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 254 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
| 255 | 0 | KimDocumentRoleResponsibility newResponsibility = roleDocumentForm.getResponsibility(); |
| 256 | 0 | if(newResponsibility!=null && StringUtils.isNotBlank(newResponsibility.getResponsibilityId())){ |
| 257 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
| 258 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.RESPONSIBILITY_ID, newResponsibility.getResponsibilityId()); |
| 259 | 0 | KimResponsibilityImpl responsibilityImpl = (KimResponsibilityImpl) KNSServiceLocator.getBusinessObjectService().findByPrimaryKey(KimResponsibilityImpl.class, criteria); |
| 260 | 0 | newResponsibility.setKimResponsibility(responsibilityImpl); |
| 261 | |
} |
| 262 | |
|
| 263 | 0 | if (KNSServiceLocatorWeb.getKualiRuleService().applyRules(new AddResponsibilityEvent("",roleDocumentForm.getRoleDocument(), newResponsibility))) { |
| 264 | 0 | if (newResponsibility != null) { |
| 265 | 0 | newResponsibility.setDocumentNumber(roleDocumentForm.getDocument().getDocumentNumber()); |
| 266 | |
} |
| 267 | 0 | roleDocumentForm.getRoleDocument().addResponsibility(newResponsibility); |
| 268 | 0 | roleDocumentForm.setResponsibility(new KimDocumentRoleResponsibility()); |
| 269 | 0 | roleDocumentForm.getRoleDocument().updateMembers(newResponsibility); |
| 270 | |
} |
| 271 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 272 | |
} |
| 273 | |
|
| 274 | |
public ActionForward deleteResponsibility(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 275 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
| 276 | 0 | roleDocumentForm.getRoleDocument().getResponsibilities().remove(getLineToDelete(request)); |
| 277 | 0 | roleDocumentForm.getRoleDocument().updateMembers(roleDocumentForm); |
| 278 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 279 | |
} |
| 280 | |
|
| 281 | |
public ActionForward addPermission(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 282 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
| 283 | 0 | KimDocumentRolePermission newPermission = roleDocumentForm.getPermission(); |
| 284 | 0 | if (KNSServiceLocatorWeb.getKualiRuleService().applyRules(new AddPermissionEvent("", roleDocumentForm.getRoleDocument(), newPermission))) { |
| 285 | 0 | newPermission.setDocumentNumber(roleDocumentForm.getDocument().getDocumentNumber()); |
| 286 | 0 | newPermission.setRoleId(roleDocumentForm.getRoleDocument().getRoleId()); |
| 287 | 0 | roleDocumentForm.getRoleDocument().getPermissions().add(newPermission); |
| 288 | 0 | roleDocumentForm.setPermission(new KimDocumentRolePermission()); |
| 289 | |
} |
| 290 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 291 | |
} |
| 292 | |
|
| 293 | |
public ActionForward addMember(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 294 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
| 295 | 0 | KimDocumentRoleMember newMember = roleDocumentForm.getMember(); |
| 296 | |
|
| 297 | |
|
| 298 | 0 | if (StringUtils.isEmpty(newMember.getMemberId()) |
| 299 | |
&& StringUtils.isNotEmpty(newMember.getMemberName()) |
| 300 | |
&& StringUtils.isNotEmpty(newMember.getMemberNamespaceCode()) |
| 301 | |
&& StringUtils.equals(newMember.getMemberTypeCode(), KimConstants.KimGroupMemberTypes.GROUP_MEMBER_TYPE)) { |
| 302 | 0 | GroupInfo tempGroup = KIMServiceLocator.getIdentityManagementService().getGroupByName(newMember.getMemberNamespaceCode(), newMember.getMemberName()); |
| 303 | 0 | if (tempGroup != null) { |
| 304 | 0 | newMember.setMemberId(tempGroup.getGroupId()); |
| 305 | |
} |
| 306 | |
} |
| 307 | |
|
| 308 | |
|
| 309 | 0 | if (StringUtils.isEmpty(newMember.getMemberId()) |
| 310 | |
&& StringUtils.isNotEmpty(newMember.getMemberName()) |
| 311 | |
&& StringUtils.equals(newMember.getMemberTypeCode(), KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE)) { |
| 312 | 0 | KimPrincipalInfo principal = KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(newMember.getMemberName()); |
| 313 | 0 | if (principal != null) { |
| 314 | 0 | newMember.setMemberId(principal.getPrincipalId()); |
| 315 | |
} |
| 316 | |
} |
| 317 | 0 | if(checkKimDocumentRoleMember(newMember) && |
| 318 | |
KNSServiceLocatorWeb.getKualiRuleService().applyRules(new AddMemberEvent("", roleDocumentForm.getRoleDocument(), newMember))){ |
| 319 | 0 | newMember.setDocumentNumber(roleDocumentForm.getDocument().getDocumentNumber()); |
| 320 | 0 | roleDocumentForm.getRoleDocument().addMember(newMember); |
| 321 | 0 | roleDocumentForm.setMember(roleDocumentForm.getRoleDocument().getBlankMember()); |
| 322 | 0 | roleDocumentForm.getMemberTableMetadata().jumpToLastPage(roleDocumentForm.getMemberRows().size(), roleDocumentForm.getRecordsPerPage()); |
| 323 | |
} |
| 324 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 325 | |
} |
| 326 | |
|
| 327 | |
protected boolean checkKimDocumentRoleMember(KimDocumentRoleMember newMember){ |
| 328 | 0 | boolean memberExists = false; |
| 329 | 0 | String memberName = null; |
| 330 | 0 | String memberNamespace = null; |
| 331 | |
|
| 332 | 0 | if(StringUtils.isBlank(newMember.getMemberTypeCode()) || StringUtils.isBlank(newMember.getMemberId())){ |
| 333 | 0 | GlobalVariables.getMessageMap().putError("document.member.memberId", RiceKeyConstants.ERROR_EMPTY_ENTRY, |
| 334 | |
new String[] {"Member Type Code and Member ID"}); |
| 335 | 0 | return false; |
| 336 | |
} |
| 337 | |
|
| 338 | 0 | if(KimConstants.KimUIConstants.MEMBER_TYPE_PRINCIPAL_CODE.equals(newMember.getMemberTypeCode())){ |
| 339 | 0 | KimPrincipal pi = this.getIdentityService().getPrincipal(newMember.getMemberId()); |
| 340 | 0 | if(pi != null){ |
| 341 | 0 | memberExists = true; |
| 342 | 0 | memberName = pi.getPrincipalName(); |
| 343 | 0 | memberNamespace = ""; |
| 344 | |
} |
| 345 | 0 | }else if(KimConstants.KimUIConstants.MEMBER_TYPE_GROUP_CODE.equals(newMember.getMemberTypeCode())){ |
| 346 | 0 | Group gi = KIMServiceLocator.getGroupService().getGroupInfo(newMember.getMemberId()); |
| 347 | 0 | if(gi != null){ |
| 348 | 0 | memberExists = true; |
| 349 | 0 | memberName = gi.getGroupName(); |
| 350 | 0 | memberNamespace = gi.getNamespaceCode(); |
| 351 | |
} |
| 352 | 0 | } else if(KimConstants.KimUIConstants.MEMBER_TYPE_ROLE_CODE.equals(newMember.getMemberTypeCode())){ |
| 353 | 0 | Role ri = KIMServiceLocator.getRoleService().getRole(newMember.getMemberId()); |
| 354 | 0 | if(!validateRole(newMember.getMemberId(), ri, "document.member.memberId", "Role")){ |
| 355 | 0 | return false; |
| 356 | |
}else{ |
| 357 | 0 | memberExists = true; |
| 358 | 0 | memberName = ri.getRoleName(); |
| 359 | 0 | memberNamespace = ri.getNamespaceCode(); |
| 360 | |
} |
| 361 | |
} |
| 362 | |
|
| 363 | 0 | if(!memberExists){ |
| 364 | 0 | GlobalVariables.getMessageMap().putError("document.member.memberId", RiceKeyConstants.ERROR_MEMBERID_MEMBERTYPE_MISMATCH, |
| 365 | |
new String[] {newMember.getMemberId()}); |
| 366 | 0 | return false; |
| 367 | |
} |
| 368 | 0 | newMember.setMemberName(memberName); |
| 369 | 0 | newMember.setMemberNamespaceCode(memberNamespace); |
| 370 | 0 | return true; |
| 371 | |
} |
| 372 | |
|
| 373 | |
public ActionForward deleteMember(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 374 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
| 375 | 0 | KimDocumentRoleMember inactivatedRoleMember = roleDocumentForm.getRoleDocument().getMembers().get(getLineToDelete(request)); |
| 376 | |
|
| 377 | |
|
| 378 | 0 | ActionForward forward = promptForAffectedDelegates(mapping, form, request, response, |
| 379 | |
roleDocumentForm, inactivatedRoleMember); |
| 380 | |
|
| 381 | 0 | if (forward != null) return forward; |
| 382 | |
|
| 383 | 0 | Calendar cal = Calendar.getInstance(); |
| 384 | 0 | inactivatedRoleMember.setActiveToDate(new Timestamp(cal.getTimeInMillis())); |
| 385 | |
|
| 386 | 0 | roleDocumentForm.getRoleDocument().getMembers().set(getLineToDelete(request), inactivatedRoleMember); |
| 387 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 388 | |
} |
| 389 | |
|
| 390 | |
public ActionForward deletePermission(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 391 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
| 392 | 0 | roleDocumentForm.getRoleDocument().getPermissions().remove(getLineToDelete(request)); |
| 393 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 394 | |
} |
| 395 | |
|
| 396 | |
protected boolean checkDelegationMember(RoleDocumentDelegationMember newMember){ |
| 397 | 0 | if(StringUtils.isBlank(newMember.getMemberTypeCode()) || StringUtils.isBlank(newMember.getMemberId())){ |
| 398 | 0 | GlobalVariables.getMessageMap().putError("document.delegationMember.memberId", RiceKeyConstants.ERROR_EMPTY_ENTRY, |
| 399 | |
new String[] {"Member Type Code and Member ID"}); |
| 400 | 0 | return false; |
| 401 | |
} |
| 402 | 0 | if(KimConstants.KimUIConstants.MEMBER_TYPE_PRINCIPAL_CODE.equals(newMember.getMemberTypeCode())){ |
| 403 | 0 | KimPrincipalInfo principalInfo = null; |
| 404 | 0 | principalInfo = getIdentityManagementService().getPrincipal(newMember.getMemberId()); |
| 405 | 0 | if (principalInfo == null) { |
| 406 | 0 | GlobalVariables.getMessageMap().putError("document.delegationMember.memberId", RiceKeyConstants.ERROR_MEMBERID_MEMBERTYPE_MISMATCH, |
| 407 | |
new String[] {newMember.getMemberId()}); |
| 408 | 0 | return false; |
| 409 | |
} |
| 410 | |
else { |
| 411 | 0 | newMember.setMemberName(principalInfo.getPrincipalName()); |
| 412 | |
} |
| 413 | 0 | } else if(KimConstants.KimUIConstants.MEMBER_TYPE_GROUP_CODE.equals(newMember.getMemberTypeCode())){ |
| 414 | 0 | GroupInfo groupInfo = null; |
| 415 | 0 | groupInfo = getIdentityManagementService().getGroup(newMember.getMemberId()); |
| 416 | 0 | if (groupInfo == null) { |
| 417 | 0 | GlobalVariables.getMessageMap().putError("document.delegationMember.memberId", RiceKeyConstants.ERROR_MEMBERID_MEMBERTYPE_MISMATCH, |
| 418 | |
new String[] {newMember.getMemberId()}); |
| 419 | 0 | return false; |
| 420 | |
} |
| 421 | |
else { |
| 422 | 0 | newMember.setMemberName(groupInfo.getGroupName()); |
| 423 | 0 | newMember.setMemberNamespaceCode(groupInfo.getNamespaceCode()); |
| 424 | |
} |
| 425 | 0 | } else if(KimConstants.KimUIConstants.MEMBER_TYPE_ROLE_CODE.equals(newMember.getMemberTypeCode())){ |
| 426 | 0 | KimRoleInfo roleInfo = null; |
| 427 | 0 | roleInfo = KIMServiceLocator.getRoleService().getRole(newMember.getMemberId()); |
| 428 | 0 | if (roleInfo == null) { |
| 429 | 0 | GlobalVariables.getMessageMap().putError("document.delegationMember.memberId", RiceKeyConstants.ERROR_MEMBERID_MEMBERTYPE_MISMATCH, |
| 430 | |
new String[] {newMember.getMemberId()}); |
| 431 | 0 | return false; |
| 432 | |
} |
| 433 | |
else { |
| 434 | 0 | newMember.setMemberName(roleInfo.getRoleName()); |
| 435 | 0 | newMember.setMemberNamespaceCode(roleInfo.getNamespaceCode()); |
| 436 | |
} |
| 437 | |
} |
| 438 | 0 | return true; |
| 439 | |
} |
| 440 | |
|
| 441 | |
public ActionForward addDelegationMember(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 442 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
| 443 | 0 | RoleDocumentDelegationMember newDelegationMember = roleDocumentForm.getDelegationMember(); |
| 444 | |
|
| 445 | |
|
| 446 | 0 | if (StringUtils.isEmpty(newDelegationMember.getMemberId()) |
| 447 | |
&& StringUtils.isNotEmpty(newDelegationMember.getMemberName()) |
| 448 | |
&& StringUtils.isNotEmpty(newDelegationMember.getMemberNamespaceCode()) |
| 449 | |
&& StringUtils.equals(newDelegationMember.getMemberTypeCode(), KimConstants.KimGroupMemberTypes.GROUP_MEMBER_TYPE)) { |
| 450 | 0 | GroupInfo tempGroup = KIMServiceLocator.getIdentityManagementService().getGroupByName(newDelegationMember.getMemberNamespaceCode(), newDelegationMember.getMemberName()); |
| 451 | 0 | if (tempGroup != null) { |
| 452 | 0 | newDelegationMember.setMemberId(tempGroup.getGroupId()); |
| 453 | |
} |
| 454 | |
} |
| 455 | |
|
| 456 | |
|
| 457 | 0 | if (StringUtils.isEmpty(newDelegationMember.getMemberId()) |
| 458 | |
&& StringUtils.isNotEmpty(newDelegationMember.getMemberName()) |
| 459 | |
&& StringUtils.equals(newDelegationMember.getMemberTypeCode(), KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE)) { |
| 460 | 0 | KimPrincipalInfo principal = KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(newDelegationMember.getMemberName()); |
| 461 | 0 | if (principal != null) { |
| 462 | 0 | newDelegationMember.setMemberId(principal.getPrincipalId()); |
| 463 | |
} |
| 464 | |
} |
| 465 | |
|
| 466 | 0 | if (checkDelegationMember(newDelegationMember) && KNSServiceLocatorWeb.getKualiRuleService().applyRules( |
| 467 | |
new AddDelegationMemberEvent("", roleDocumentForm.getRoleDocument(), newDelegationMember))) { |
| 468 | 0 | newDelegationMember.setDocumentNumber(roleDocumentForm.getDocument().getDocumentNumber()); |
| 469 | 0 | roleDocumentForm.getRoleDocument().addDelegationMember(newDelegationMember); |
| 470 | 0 | roleDocumentForm.setDelegationMember(roleDocumentForm.getRoleDocument().getBlankDelegationMember()); |
| 471 | |
} |
| 472 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 473 | |
} |
| 474 | |
|
| 475 | |
public ActionForward deleteDelegationMember(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 476 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
| 477 | |
|
| 478 | 0 | roleDocumentForm.getRoleDocument().getDelegationMembers().remove(getLineToDelete(request)); |
| 479 | 0 | roleDocumentForm.setDelegationMember(roleDocumentForm.getRoleDocument().getBlankDelegationMember()); |
| 480 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 481 | |
} |
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | |
|
| 487 | |
public ActionForward jumpToRoleMember(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 488 | 0 | IdentityManagementRoleDocumentForm idmForm = (IdentityManagementRoleDocumentForm) form; |
| 489 | 0 | String delegationRoleMemberId = getDelegationRoleMemberToJumpTo(request); |
| 490 | 0 | KualiTableRenderFormMetadata memberTableMetadata = idmForm.getMemberTableMetadata(); |
| 491 | 0 | memberTableMetadata.jumpToPage(idmForm.getPageNumberOfRoleMemberId(delegationRoleMemberId), |
| 492 | |
idmForm.getMemberRows().size(), idmForm.getRecordsPerPage()); |
| 493 | 0 | memberTableMetadata.setColumnToSortIndex(memberTableMetadata.getPreviouslySortedColumnIndex()); |
| 494 | 0 | idmForm.setAnchor(delegationRoleMemberId); |
| 495 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 496 | |
} |
| 497 | |
|
| 498 | |
protected String getDelegationRoleMemberToJumpTo(HttpServletRequest request) { |
| 499 | 0 | String delegationRoleMemberIdToJumpTo = ""; |
| 500 | 0 | String parameterName = (String) request.getAttribute(KNSConstants.METHOD_TO_CALL_ATTRIBUTE); |
| 501 | 0 | if (StringUtils.isNotBlank(parameterName)) { |
| 502 | 0 | delegationRoleMemberIdToJumpTo = StringUtils.substringBetween(parameterName, ".dmrmi", "."); |
| 503 | |
} |
| 504 | 0 | return delegationRoleMemberIdToJumpTo; |
| 505 | |
} |
| 506 | |
|
| 507 | |
|
| 508 | |
|
| 509 | |
|
| 510 | |
|
| 511 | |
|
| 512 | |
|
| 513 | |
|
| 514 | |
|
| 515 | |
private ActionForward promptForAffectedDelegates(ActionMapping mapping, |
| 516 | |
ActionForm form, HttpServletRequest request, |
| 517 | |
HttpServletResponse response, |
| 518 | |
IdentityManagementRoleDocumentForm roleDocumentForm, KimDocumentRoleMember ... roleMembersToConsiderInactive) |
| 519 | |
throws Exception { |
| 520 | |
|
| 521 | |
|
| 522 | |
|
| 523 | 0 | List<RoleDocumentDelegationMember> activeDelegatesOfInactiveRoleMembers = |
| 524 | |
getActiveDelegatesOfInactiveRoleMembers(roleDocumentForm, roleMembersToConsiderInactive); |
| 525 | 0 | ActionForward forward = getAffectedDelegatesQuestionActionForward(activeDelegatesOfInactiveRoleMembers, mapping, form, request, |
| 526 | |
response, roleDocumentForm); |
| 527 | |
|
| 528 | 0 | if (forward != null) return forward; |
| 529 | |
|
| 530 | 0 | if (activeDelegatesOfInactiveRoleMembers.size() > 0) { |
| 531 | 0 | Calendar cal = Calendar.getInstance(); |
| 532 | |
|
| 533 | 0 | for (RoleDocumentDelegationMember delegateToDeactivate : activeDelegatesOfInactiveRoleMembers) { |
| 534 | 0 | delegateToDeactivate.setActiveToDate(new Timestamp(cal.getTimeInMillis())); |
| 535 | |
} |
| 536 | |
} |
| 537 | 0 | return null; |
| 538 | |
} |
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
|
| 544 | |
|
| 545 | |
|
| 546 | |
|
| 547 | |
private ActionForward getAffectedDelegatesQuestionActionForward(List<RoleDocumentDelegationMember> activeDelegatesOfInactiveRoleMembers, |
| 548 | |
ActionMapping mapping, ActionForm form, HttpServletRequest request, |
| 549 | |
HttpServletResponse response, |
| 550 | |
IdentityManagementRoleDocumentForm roleDocumentForm) |
| 551 | |
throws Exception { |
| 552 | |
|
| 553 | 0 | if (activeDelegatesOfInactiveRoleMembers.size() > 0) { |
| 554 | 0 | Object question = getQuestion(request); |
| 555 | |
|
| 556 | 0 | if (question == null || !REMOVE_AFFECTED_DELEGATES_QUESTION_ID.equals(question)) { |
| 557 | 0 | return performQuestionWithoutInput(mapping, form, request, response, REMOVE_AFFECTED_DELEGATES_QUESTION_ID, |
| 558 | |
getKualiConfigurationService().getPropertyString(RiceKeyConstants.QUESTION_ACTIVE_DELEGATES_FOR_INACTIVE_MEMBERS), |
| 559 | |
KNSConstants.CONFIRMATION_QUESTION, roleDocumentForm.getMethodToCall(), StringUtils.EMPTY); |
| 560 | |
} |
| 561 | 0 | Object buttonClicked = request.getParameter(KNSConstants.QUESTION_CLICKED_BUTTON); |
| 562 | 0 | if ((REMOVE_AFFECTED_DELEGATES_QUESTION_ID.equals(question)) && ConfirmationQuestion.YES.equals(buttonClicked)) { |
| 563 | |
|
| 564 | |
|
| 565 | |
} else { |
| 566 | |
|
| 567 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 568 | |
} |
| 569 | |
} |
| 570 | |
|
| 571 | 0 | return null; |
| 572 | |
} |
| 573 | |
|
| 574 | |
|
| 575 | |
|
| 576 | |
|
| 577 | |
|
| 578 | |
|
| 579 | |
|
| 580 | |
|
| 581 | |
private List<RoleDocumentDelegationMember> getActiveDelegatesOfInactiveRoleMembers( |
| 582 | |
IdentityManagementRoleDocumentForm roleDocumentForm, KimDocumentRoleMember ... roleMembersToConsiderInactive) { |
| 583 | 0 | List<KimDocumentRoleMember> roleMembers = roleDocumentForm.getMemberRows(); |
| 584 | 0 | List<KimDocumentRoleMember> inactiveRoleMembers = new ArrayList<KimDocumentRoleMember>(); |
| 585 | 0 | List<RoleDocumentDelegationMember> activeDelegatesOfInactivatedRoleMembers = new ArrayList<RoleDocumentDelegationMember>(); |
| 586 | |
|
| 587 | 0 | inactiveRoleMembers.addAll(Arrays.asList(roleMembersToConsiderInactive)); |
| 588 | |
|
| 589 | 0 | if (roleMembers != null) for (KimDocumentRoleMember roleMember : roleMembers) if (roleMember != null) { |
| 590 | 0 | if (!roleMember.isActive()) inactiveRoleMembers.add(roleMember); |
| 591 | |
} |
| 592 | |
|
| 593 | 0 | for (KimDocumentRoleMember inactiveRoleMember : inactiveRoleMembers) { |
| 594 | |
|
| 595 | 0 | List<RoleDocumentDelegationMember> delegationMembers = roleDocumentForm.getRoleDocument().getDelegationMembers(); |
| 596 | 0 | if (delegationMembers != null) for (RoleDocumentDelegationMember delegationMember : delegationMembers) { |
| 597 | 0 | if (delegationMember != null && delegationMember.isActive()) { |
| 598 | |
|
| 599 | 0 | if (delegationMember.getRoleMemberId().equals(inactiveRoleMember.getRoleMemberId())) { |
| 600 | 0 | activeDelegatesOfInactivatedRoleMembers.add(delegationMember); |
| 601 | |
} |
| 602 | |
} |
| 603 | |
} |
| 604 | 0 | } |
| 605 | 0 | return activeDelegatesOfInactivatedRoleMembers; |
| 606 | |
} |
| 607 | |
|
| 608 | |
|
| 609 | |
|
| 610 | |
|
| 611 | |
|
| 612 | |
|
| 613 | |
|
| 614 | |
|
| 615 | |
|
| 616 | |
protected boolean validateRole( String roleId, Role role, String propertyName, String message){ |
| 617 | 0 | if ( role == null ) { |
| 618 | 0 | GlobalVariables.getMessageMap().putError(propertyName, RiceKeyConstants.ERROR_INVALID_ROLE, roleId ); |
| 619 | 0 | return false; |
| 620 | |
} |
| 621 | 0 | return true; |
| 622 | |
} |
| 623 | |
|
| 624 | |
|
| 625 | |
} |