Source:
<code>public void checkUpdateDataPermission(HttpServletRequest request) throws InsufficientPermissionException { Boolean auth = true; UserAccountBean userBean =(UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME); StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study"); int currentStudyParentId; if(currentStudy.getParentStudyId() == 0){ currentStudyParentId = currentStudy.getId(); }else{ currentStudyParentId = currentStudy.getParentStudyId(); } ArrayList userRoles = userBean.getRoles(); String submitted =(String) request.getParameter("submitted"); String checkInputs = (String)request.getParameter("checkInputs"); if(submitted !=null && submitted.equals("1") && checkInputs!=null && checkInputs.equals("1")) { for (int i = 0; i < userRoles.size(); i++) { StudyUserRoleBean studyRole = (StudyUserRoleBean) userRoles.get(i); if(studyRole.getRole().equals(Role.MONITOR) && studyRole.getStudyId() == currentStudy.getId()) { auth = false; break; } } String studyId = (String)request.getParameter("sid"); <START> if(studyId !=null && Integer.parseInt(studyId) != currentStudyParentId && Integer.parseInt(studyId) != currentStudy.getId()) { <END> auth = false; } } if(!auth) { addPageMessage(respage.getString("you_not_have_permission_update_a_CRF"), request); throw new InsufficientPermissionException(Page.MENU_SERVLET, resexception.getString("no_permission_to_perform_data_entry"), "1"); } }</code><technical_language>Consider this scenario 1. User A is study level for study X tabs open - tab 1 a form opened tab 2 some other page. 2. User A logs out of tab 2 3. User B logs in tab 2 4. User B switches a site study 5. User B tab 1 enters data for study X logic above, if condition evaluate false allow User B enter data form. I need determine if "studyId" is a study a site id check current study/site ids</technical_language>

Target:
public void checkUpdateDataPermission(HttpServletRequest request) throws InsufficientPermissionException { Boolean auth = true; UserAccountBean userBean =(UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME); StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study"); ArrayList userRoles = userBean.getRoles(); String submitted =(String) request.getParameter("submitted"); String checkInputs = (String)request.getParameter("checkInputs"); if(submitted !=null && submitted.equals("1") && checkInputs!=null && checkInputs.equals("1")) { for (int i = 0; i < userRoles.size(); i++) { StudyUserRoleBean studyRole = (StudyUserRoleBean) userRoles.get(i); if(studyRole.getRole().equals(Role.MONITOR) && studyRole.getStudyId() == currentStudy.getId()) { auth = false; break; } } boolean currentStudyIsStudy = false; if(currentStudy.getParentStudyId() == 0){ currentStudyIsStudy = true; } String studyId = (String)request.getParameter("sid"); StudyDAO studydao = new StudyDAO(getDataSource()); StudyBean studyIdStudy = (StudyBean)studydao.findByPK(Integer.parseInt(studyId)); boolean studyIdIsStudy = false; if(studyIdStudy.getParentStudyId() == 0){ studyIdIsStudy = true; } if(currentStudyIsStudy && studyIdIsStudy){ if(currentStudy.getId() != studyIdStudy.getId()){ auth = false; } }else if(!currentStudyIsStudy && studyIdIsStudy){ if(currentStudy.getParentStudyId() != studyIdStudy.getId()){ auth = false; } }else if(currentStudyIsStudy && !studyIdIsStudy){ if(currentStudy.getId() != studyIdStudy.getParentStudyId()){ auth = false; } }else{ if(currentStudy.getParentStudyId() != studyIdStudy.getParentStudyId()){ auth = false; } } } if(!auth) { addPageMessage(respage.getString("you_not_have_permission_update_a_CRF"), request); throw new InsufficientPermissionException(Page.MENU_SERVLET, resexception.getString("no_permission_to_perform_data_entry"), "1"); } }