List of usage examples for org.apache.shiro SecurityUtils getSubject
public static Subject getSubject()
From source file:au.org.theark.study.web.component.attachments.form.SearchForm.java
License:Open Source License
@Override protected void onSearch(AjaxRequestTarget target) { target.add(feedbackPanel);/*from w ww .j a va2 s . c o m*/ SubjectFile subjectFile = new SubjectFile(); subjectFile = getModelObject().getSubjectFile(); Collection<SubjectFile> subjectFileList = new ArrayList<SubjectFile>(); try { LinkSubjectStudy linkSubjectStudy = null; Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); linkSubjectStudy = iArkCommonService.getSubject(sessionPersonId, study); subjectFile.setLinkSubjectStudy(linkSubjectStudy); } catch (EntityNotFoundException e1) { this.error("There is no subject selected."); target.add(feedbackPanel); } try { // Look up based on criteria via back end. subjectFileList = iStudyService.searchSubjectFile(subjectFile); if (subjectFileList != null && subjectFileList.size() == 0) { this.info("There are no subject files for the specified search criteria."); target.add(feedbackPanel); } getModelObject().setSubjectFileList(subjectFileList); pageableListView.removeAll(); arkCrudContainerVO.getSearchResultPanelContainer().setVisible(true); target.add(arkCrudContainerVO.getSearchResultPanelContainer()); } catch (EntityNotFoundException e) { log.error(e.getMessage()); } catch (ArkSystemException e) { log.error(e.getMessage()); } }
From source file:au.org.theark.study.web.component.attachments.form.SearchForm.java
License:Open Source License
@Override protected void onBeforeRender() { // TODO Auto-generated method stub super.onBeforeRender(); SecurityManager securityManager = ThreadContext.getSecurityManager(); Subject currentUser = SecurityUtils.getSubject(); if (!securityManager.hasRole(currentUser.getPrincipals(), au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR) && Constants.YES.equalsIgnoreCase(iArkCommonService.getDemoMode().getPropertyValue())) { this.newButton.setEnabled(false); }//from ww w . j a v a2 s . com }
From source file:au.org.theark.study.web.component.attachments.SearchResultListPanel.java
License:Open Source License
private AjaxDeleteButton buildDeleteButton(final SubjectFile subjectFile, final AjaxButton downloadButton) { DeleteButton ajaxButton = new DeleteButton(subjectFile, SearchResultListPanel.this) { private static final long serialVersionUID = 1L; @Override//from w w w . j av a 2 s.c om protected void onSubmit(AjaxRequestTarget target, Form<?> form) { // Attempt to delete upload boolean success = false; if (subjectFile.getId() != null) { try { studyService.delete(subjectFile, (subjectFile.getIsConsentFile() ? au.org.theark.study.web.Constants.ARK_SUBJECT_CONSENT_DIR : au.org.theark.study.web.Constants.ARK_SUBJECT_ATTACHEMENT_DIR)); success = true; } catch (ArkSystemException e) { this.error("An unexpected error occurred. Delete request could not be fulfilled."); log.error("ArkSystemException" + e.getMessage(), e); } catch (EntityNotFoundException e) { this.error("An unexpected error occurred. Delete request could not be fulfilled."); log.error("Entity not found" + e.getMessage(), e); } catch (ArkFileNotFoundException e) { this.error("File not found:" + e.getMessage()); } } if (success) { containerForm.info("Attachment " + subjectFile.getFilename() + " was successfully deleted."); } // Update the result panel // target.add(searchResultContainer); target.add(arkCrudContainerVO.getSearchResultPanelContainer()); target.add(containerForm); } @Override public boolean isVisible() { SecurityManager securityManager = ThreadContext.getSecurityManager(); Subject currentUser = SecurityUtils.getSubject(); boolean flag = false; if (securityManager.isPermitted(currentUser.getPrincipals(), PermissionConstants.DELETE)) { return flag = true; } return flag; } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { this.error("An unexpected error occurred. Delete request could not be fulfilled."); log.error("An unexpected error occurred. Delete request could not be fulfilled."); } }; ajaxButton.setDefaultFormProcessing(false); return ajaxButton; }
From source file:au.org.theark.study.web.component.calendar.form.DetailForm.java
License:Open Source License
public void initialiseDetailForm() { calendarIdTxtFld = new TextField<String>(Constants.STUDY_CALENDAR_ID); calendarIdTxtFld.setEnabled(false);//from w w w . j a va 2 s. c o m calendarNameTxtFld = new TextField<String>(Constants.STUDY_CALENDAR_NAME); calendarNameTxtFld.add(new ArkDefaultFormFocusBehavior()); calendarDescription = new TextArea<String>(Constants.STUDY_CALENDAR_DESCRIPTION); Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(sessionStudyId); List<StudyComp> studyCompList = iArkCommonService.getStudyComponentByStudy(study); ChoiceRenderer<StudyComp> defaultChoiceRenderer = new ChoiceRenderer<StudyComp>(Constants.NAME, Constants.ID); calendarStudyCompDDL = new DropDownChoice<StudyComp>(Constants.STUDY_CALENDAR_STUDY_COMP, studyCompList, defaultChoiceRenderer); calendarStudyCompDDL.setOutputMarkupId(true); studyCalendarStartDateFld = new DateTextField(Constants.STUDY_CALENDAR_START_DATE, new PatternDateConverter(au.org.theark.core.Constants.DD_MM_YYYY, false)); ArkDatePicker startDatePicker = new ArkDatePicker(); startDatePicker.bind(studyCalendarStartDateFld); studyCalendarStartDateFld.add(startDatePicker); studyCalendarEndDateFld = new DateTextField(Constants.STUDY_CALENDAR_END_DATE, new PatternDateConverter(au.org.theark.core.Constants.DD_MM_YYYY, false)); ArkDatePicker endDatePicker = new ArkDatePicker(); endDatePicker.bind(studyCalendarEndDateFld); studyCalendarEndDateFld.add(endDatePicker); overLappingBooking = new CheckBox("studyCalendar.allowOverlapping"); initCustomFieldPalette(); addDetailFormComponents(); attachValidators(); }
From source file:au.org.theark.study.web.component.calendar.form.DetailForm.java
License:Open Source License
private void initCustomFieldPalette() { CompoundPropertyModel<StudyCalendarVo> searchCPM = (CompoundPropertyModel<StudyCalendarVo>) containerForm .getModel();//from ww w .jav a 2 s . com IChoiceRenderer<String> renderer = new ChoiceRenderer<String>("name", "name"); PropertyModel<Collection<CustomField>> selectedCustomFieldsPm = new PropertyModel<Collection<CustomField>>( searchCPM, "selectedCustomFields");// "selectedDemographicFields"); Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Collection<CustomField> availableCustomFields = iStudyService.getStudySubjectCustomFieldList(studyId); containerForm.getModelObject().setAvailableCustomFields(availableCustomFields); PropertyModel<Collection<CustomField>> availableCustomFieldsPm = new PropertyModel<Collection<CustomField>>( searchCPM, "availableCustomFields"); customFieldPalette = new ArkPalette("selectedCustomFields", selectedCustomFieldsPm, availableCustomFieldsPm, renderer, au.org.theark.core.Constants.PALETTE_ROWS, false); customFieldPalette.setOutputMarkupId(true); // IChoiceRenderer<String> renderer = new ChoiceRenderer<String>("name", "name"); // List<CustomField> selectedCustomFieldList = cpModel.getObject().getSelectedCustomFields(); // // PropertyModel<Collection<CustomField>> availablePm = new PropertyModel<Collection<CustomField>>(cpModel, "availableCustomFields"); // Collections.sort((List<CustomField>)availablePm.getObject(), new Comparator<CustomField>(){ // public int compare(CustomField arg0, CustomField arg1) { // return arg0.getId().compareTo(arg1.getId()); // } // }); // customFieldPalette = new ArkPalette("selectedCustomFields", new ListModel(selectedCustomFieldList), availablePm, renderer, au.org.theark.core.Constants.PALETTE_ROWS, false); }
From source file:au.org.theark.study.web.component.calendar.form.DetailForm.java
License:Open Source License
@Override protected void onSave(Form<StudyCalendarVo> containerForm, AjaxRequestTarget target) { target.add(arkCrudContainerVO.getDetailPanelContainer()); Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); study = iArkCommonService.getStudy(studyId); containerForm.getModelObject().getStudyCalendar().setStudy(study); if (containerForm.getModelObject().getStudyCalendar().getId() == null) { iStudyService.saveOrUpdate(containerForm.getModelObject()); this.saveInformation(); //this.info("Study Calendar " + containerForm.getModelObject().getStudyCalendar().getName() + " was created successfully"); processErrors(target);/*www .ja v a 2s . c om*/ } else { iStudyService.saveOrUpdate(containerForm.getModelObject()); this.updateInformation(); //this.info("Study Calendar " + containerForm.getModelObject().getStudyCalendar().getName() + " was updated successfully"); processErrors(target); } onSavePostProcess(target); }
From source file:au.org.theark.study.web.component.calendar.form.SearchForm.java
License:Open Source License
/** * //w w w . j a va2s .com * @param id * @param cpmModel * @param arkCrudContainerVO * @param feedBackPanel * @param listView */ public SearchForm(String id, CompoundPropertyModel<StudyCalendarVo> cpmModel, ArkCrudContainerVO arkCrudContainerVO, FeedbackPanel feedBackPanel, PageableListView<StudyCalendar> listView) { super(id, cpmModel, feedBackPanel, arkCrudContainerVO); this.arkCrudContainerVO = arkCrudContainerVO; this.feedbackPanel = feedBackPanel; this.listView = listView; initialiseSearchForm(); addSearchComponentsToForm(); Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); disableSearchForm(sessionStudyId, "There is no study in context. Please select a Study."); }
From source file:au.org.theark.study.web.component.calendar.SearchResultListPanel.java
License:Open Source License
@SuppressWarnings({ "unchecked", "serial" }) private AjaxLink buildLink(final StudyCalendar studyCalendar) { ArkBusyAjaxLink link = new ArkBusyAjaxLink("studyCalendar.name") { @Override//from ww w . j a v a 2s .co m public void onClick(AjaxRequestTarget target) { StudyCalendarVo studyCalendarVo = containerForm.getModelObject(); studyCalendarVo.setMode(Constants.MODE_EDIT); studyCalendarVo.setStudyCalendar(studyCalendar);// Sets the selected object into the model // Render the UI Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Collection<CustomField> availableCustomFields = iStudyService .getStudySubjectCustomFieldList(studyId); studyCalendarVo.setAvailableCustomFields(availableCustomFields); Collection<CustomField> selectedustomFields = iStudyService .getSelectedCalendarCustomFieldList(studyCalendar); studyCalendarVo.setSelectedCustomFields((ArrayList<CustomField>) selectedustomFields); ArkCRUDHelper.preProcessDetailPanelOnSearchResults(target, arkCrudContainerVO); } }; // Add the label for the link Label nameLinkLabel = new Label("nameLbl", studyCalendar.getName()); link.add(nameLinkLabel); return link; }
From source file:au.org.theark.study.web.component.consent.ConsentContainerPanel.java
License:Open Source License
@Override protected WebMarkupContainer initialiseSearchPanel() { // Get the Person in Context and determine the Person Type Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); try {/*from www .ja v a2 s .c o m*/ // Initialise the phoneList; Collection<Consent> consentList = new ArrayList<Consent>(); // The LinkSubjectStudy item should be fetched and stored in the model Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(sessionStudyId); if (sessionPersonId != null) { LinkSubjectStudy linkSubjectStudy = studyService.getSubjectLinkedToStudy(sessionPersonId, study); containerForm.getModelObject().getConsent().setLinkSubjectStudy(linkSubjectStudy); } // All the phone items related to the person if one found in session or an empty list cpModel.getObject().setConsentList(consentList); searchPanel = new SearchPanel("searchPanel", feedBackPanel, pageableListView, arkCrudContainerVO); searchPanel.initialisePanel(cpModel); arkCrudContainerVO.getSearchPanelContainer().add(searchPanel); } catch (EntityNotFoundException entityNotFoundException) { containerForm.error( "The Person/Subject cannot be found in the system. Please contact the system administrator."); } catch (ArkSystemException arkSystemException) { containerForm.error("A System error/exception has occured. Please contact the system administrator."); } return arkCrudContainerVO.getSearchPanelContainer(); }
From source file:au.org.theark.study.web.component.consent.ConsentContainerPanel.java
License:Open Source License
@Override protected WebMarkupContainer initialiseSearchResults() { // TODO: Should eventually remove containerForm and instead pass over the cpModel SearchResultListPanel searchResultPanel = new SearchResultListPanel("searchResults", containerForm, arkCrudContainerVO, feedBackPanel); iModel = new LoadableDetachableModel<Object>() { private static final long serialVersionUID = 1L; @Override// w w w. j av a 2s. c o m protected Object load() { Collection<Consent> consentList = new ArrayList<Consent>(); Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); try { if (isActionPermitted()) { if (sessionPersonId != null) { Study study = iArkCommonService.getStudy(sessionStudyId); LinkSubjectStudy linkSubjectStudy = studyService .getSubjectLinkedToStudy(sessionPersonId, study); containerForm.getModelObject().getConsent().setLinkSubjectStudy(linkSubjectStudy); containerForm.getModelObject().getConsent().setStudy(study); consentList = studyService.searchConsent(containerForm.getModelObject()); } } } catch (EntityNotFoundException e) { containerForm.error("The subject is not available in the system."); } catch (ArkSystemException e) { containerForm.error("A system error has occurred. Please contact the system administrator."); } pageableListView.removeAll(); return consentList; } }; pageableListView = searchResultPanel.buildPageableListView(iModel); pageableListView.setReuseItems(true); AjaxPagingNavigator pageNavigator = new AjaxPagingNavigator("navigator", pageableListView); searchResultPanel.add(pageNavigator); searchResultPanel.add(pageableListView); searchResultPanel.setOutputMarkupId(true); arkCrudContainerVO.getSearchResultPanelContainer().add(searchResultPanel); return arkCrudContainerVO.getSearchResultPanelContainer(); }