List of usage examples for org.apache.shiro SecurityUtils getSubject
public static Subject getSubject()
From source file:au.org.theark.study.web.component.mydetails.form.MyDetailsForm.java
License:Open Source License
private boolean isStudyContexSelected() { Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); return (sessionStudyId != null); }
From source file:au.org.theark.study.web.component.mydetails.MyDetails.java
License:Open Source License
public MyDetails(String id, ArkUserVO arkUserVO, final FeedbackPanel feedBackPanel, ModalWindow modalWindow) { super(id);/* w w w .j av a 2 s . co m*/ /* Initialise the CPM */ arkUserModelCpm = new CompoundPropertyModel<ArkUserVO>(arkUserVO); MyDetailsForm myDetailForm = new MyDetailsForm(Constants.USER_DETAILS_FORM, arkUserModelCpm, feedBackPanel, modalWindow) { private static final long serialVersionUID = -8858977824290273852L; protected void onSave(AjaxRequestTarget target) { ArkUserVO arkUser = getModelObject(); Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); if (sessionStudyId != null) { arkUser.setStudy(iArkCommonService.getStudy(sessionStudyId)); } if ((arkUser.getPassword() != null && arkUser.getConfirmPassword() != null) && (!arkUser.getPassword().isEmpty() && !arkUser.getConfirmPassword().isEmpty())) { // Temporary allow the user to select if he wants to change it arkUser.setChangePassword(true); } try { userService.updateArkUser(arkUser); this.info("Details for user: " + arkUser.getUserName() + " were successfully updated."); processFeedback(target, feedBackPanel); } catch (ArkSystemException arkSystemException) { log.error("Exception occurred while performing an update on the user details in LDAP " + arkSystemException.getMessage()); this.error( "An error has occurred. The user details could not be updated. Please contact the system administrator."); processFeedback(target, feedBackPanel); // add custom error message to feedback panel. } catch (Exception ex) { // Handle all other type of exceptions this.error( "An error has occurred while saving the user details. Please contact the system administrator."); processFeedback(target, feedBackPanel); log.error("An exception occurred when saving user details " + ex.getMessage()); } } protected void processFeedback(AjaxRequestTarget target, FeedbackPanel feedbackPanel) { target.add(feedbackPanel); } protected void onCancel(AjaxRequestTarget target) { this.setVisible(false); } }; myDetailForm.initialiseForm(); if (arkUserVO.getMode() == Constants.MODE_EDIT) { myDetailForm.getUserNameTxtField().setEnabled(false); } add(myDetailForm); }
From source file:au.org.theark.study.web.component.phone.form.DetailForm.java
License:Open Source License
@Override protected void onSave(Form<PhoneVO> containerForm, AjaxRequestTarget target) { // Persist the phone number to the backend, associate the person in context with the phone object Long personSessionId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); // Get the person and set it on the Phone object. try {/* ww w . ja v a 2 s . com*/ boolean saveOk = true; Person person = studyService.getPerson(personSessionId); containerForm.getModelObject().getPhone().setPerson(person); /* // Make the area code mandatory only for landline phone (home/work) entries String phType = containerForm.getModelObject().getPhone().getPhoneType().getName().toLowerCase(); if (!phType.equals("mobile")) { // must be landline if (containerForm.getModelObject().getPhone().getAreaCode() == null || containerForm.getModelObject().getPhone().getAreaCode().length() < 1) { this.error("An area code must be entered for landline numbers"); saveOk = false; } } */ if (saveOk) { // Ok to save... String personType = (String) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_TYPE); if (personType != null && personType.equalsIgnoreCase(au.org.theark.core.Constants.PERSON_CONTEXT_TYPE_SUBJECT)) { Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); LinkSubjectStudy subjectInContext = iArkCommonService.getSubject(personSessionId, study);// This is fetched basically to display the // info // message along with the Subject UID or Contact ID if (containerForm.getModelObject().getPhone().getId() == null) { studyService.create(containerForm.getModelObject().getPhone()); this.saveInformation(); //this.info("Phone number was added and linked to Subject UID: " + subjectInContext.getSubjectUID()); } else { studyService.update(containerForm.getModelObject().getPhone()); this.updateInformation(); //this.info("Phone number was updated and linked to Subject UID: " + subjectInContext.getSubjectUID()); } } else if (personType != null && personType.equalsIgnoreCase(au.org.theark.core.Constants.PERSON_CONTEXT_TYPE_CONTACT)) { // TODO: Contact Interface implementation } processErrors(target); onSavePostProcess(target); } else { processErrors(target); } } catch (ArkUniqueException aue) { this.error(aue.getMessage()); } catch (EntityNotFoundException e) { this.error("The subject/participant is no lobger available in the system."); } catch (ArkSystemException e) { this.error("A system exception has occurred. Please contact the system administrator."); } }
From source file:au.org.theark.study.web.component.phone.form.SearchForm.java
License:Open Source License
public SearchForm(String id, CompoundPropertyModel<PhoneVO> cpmModel, ArkCrudContainerVO arkCrudContainerVO, FeedbackPanel feedBackPanel, PageableListView<Phone> listView) { super(id, cpmModel, feedBackPanel, arkCrudContainerVO); this.arkCrudContainerVO = arkCrudContainerVO; this.feedbackPanel = feedBackPanel; Label generalTextLbl = new Label("generalLbl", new StringResourceModel("search.panel.text", new Model())); add(generalTextLbl);/*from w w w .jav a2 s . c o m*/ resetButton.setVisible(false); searchButton.setVisible(false); // initialiseSearchForm(); Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); disableSearchForm(sessionPersonId, "There is no subject selected. Please select a subject or contact."); }
From source file:au.org.theark.study.web.component.phone.form.SearchForm.java
License:Open Source License
@Override protected void onSearch(AjaxRequestTarget target) { target.add(feedbackPanel);// w w w .j a va2 s . c o m Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); try { Phone phone = getModelObject().getPhone(); phone.setPerson(studyService.getPerson(sessionPersonId)); Collection<Phone> phones = studyService.getPersonPhoneList(sessionPersonId, getModelObject().getPhone()); if (phones != null && phones.size() == 0) { this.info("No records match the specified search criteria."); target.add(feedbackPanel); } getModelObject().setPhoneList(phones); pageableListView.removeAll(); arkCrudContainerVO.getSearchResultPanelContainer().setVisible(true); target.add(arkCrudContainerVO.getSearchResultPanelContainer()); } catch (EntityNotFoundException entityNotFoundException) { this.warn("There are no phone items available for the specified searcg criteria."); target.add(feedbackPanel); } catch (ArkSystemException arkException) { this.error("The Ark Application has encountered a system error."); target.add(feedbackPanel); } }
From source file:au.org.theark.study.web.component.phone.PhoneContainerPanel.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 {/*w w w . j av a 2 s. c o m*/ // Initialise the phoneList; Collection<Phone> personPhoneList = new ArrayList<Phone>(); if (sessionPersonId != null) { containerForm.getModelObject().getPhone().setPerson(studyService.getPerson(sessionPersonId));// Can be a Subject or Contact personPhoneList = studyService.getPersonPhoneList(sessionPersonId, containerForm.getModelObject().getPhone()); } // All the phone items related to the person if one found in session or an empty list cpModel.getObject().setPhoneList(personPhoneList); searchPanel = new SearchPanel("searchComponentPanel", arkCrudContainerVO, feedBackPanel, pageableListView); searchPanel.initialisePanel(cpModel); arkCrudContainerVO.getSearchPanelContainer().add(searchPanel); } catch (EntityNotFoundException entityNotFoundException) { // Report this to the user } catch (ArkSystemException arkSystemException) { // Logged by the back end. Report this to the user } return arkCrudContainerVO.getSearchPanelContainer(); }
From source file:au.org.theark.study.web.component.phone.PhoneContainerPanel.java
License:Open Source License
@Override protected WebMarkupContainer initialiseSearchResults() { SearchResultListPanel searchResultPanel = new SearchResultListPanel("searchResults", arkCrudContainerVO, containerForm);//from w w w. java2 s . c om iModel = new LoadableDetachableModel<Object>() { private static final long serialVersionUID = 1L; @Override protected Object load() { // Get the PersonId from session and get the phoneList from backend Collection<Phone> personPhoneList = new ArrayList<Phone>(); try { Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); if (isActionPermitted() && sessionPersonId != null) { personPhoneList = studyService.getPersonPhoneList(sessionPersonId, containerForm.getModelObject().getPhone()); } } catch (ArkSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } pageableListView.removeAll(); return personPhoneList; } }; pageableListView = searchResultPanel.buildPageableListView(iModel); pageableListView.setReuseItems(true); PagingNavigator pageNavigator = new PagingNavigator("phoneNavigator", pageableListView); searchResultPanel.add(pageNavigator); searchResultPanel.add(pageableListView); arkCrudContainerVO.getSearchResultPanelContainer().add(searchResultPanel); return arkCrudContainerVO.getSearchResultPanelContainer(); }
From source file:au.org.theark.study.web.component.studycomponent.form.DetailForm.java
License:Open Source License
@Override protected void onSave(Form<StudyCompVo> containerForm, AjaxRequestTarget target) { target.add(arkCrudContainerVO.getDetailPanelContainer()); try {//from ww w . j a va 2s . co m Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); study = iArkCommonService.getStudy(studyId); containerForm.getModelObject().getStudyComponent().setStudy(study); if (containerForm.getModelObject().getStudyComponent().getId() == null) { iStudyService.create(containerForm.getModelObject().getStudyComponent()); // this.info("Study Component " + containerForm.getModelObject().getStudyComponent().getName() + " was created successfully"); this.saveInformation(); processErrors(target); } else { iStudyService.update(containerForm.getModelObject().getStudyComponent()); // this.info("Study Component " + containerForm.getModelObject().getStudyComponent().getName() + " was updated successfully"); this.updateInformation(); processErrors(target); } onSavePostProcess(target); } catch (EntityExistsException e) { this.error("A study component with the same name already exists in this study."); processErrors(target); } catch (UnAuthorizedOperation e) { this.error("You are not authorised to manage study components for the given study " + study.getName()); processErrors(target); } catch (ArkSystemException e) { this.error("A system error occurred. Please contact the system administrator."); processErrors(target); } }
From source file:au.org.theark.study.web.component.studycomponent.form.SearchForm.java
License:Open Source License
/** * /*from w w w . j a v a2 s.co m*/ * @param id * @param cpmModel * @param arkCrudContainerVO * @param feedBackPanel * @param listView */ public SearchForm(String id, CompoundPropertyModel<StudyCompVo> cpmModel, ArkCrudContainerVO arkCrudContainerVO, FeedbackPanel feedBackPanel, PageableListView<StudyComp> 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 selected. Please select a study."); }
From source file:au.org.theark.study.web.component.studycomponent.StudyComponentContainerPanel.java
License:Open Source License
protected WebMarkupContainer initialiseSearchResults() { searchResultPanel = new SearchResultListPanel("searchResults", arkCrudContainerVO, containerForm, feedBackPanel);/*from w w w .j a v a 2 s. c o m*/ iModel = new LoadableDetachableModel<Object>() { private static final long serialVersionUID = 1L; @Override protected Object load() { try { Long studySessionId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); if (isActionPermitted() && studySessionId != null) { Study studyInContext = iArkCommonService.getStudy(studySessionId); containerForm.getModelObject().getStudyComponent().setStudy(studyInContext); containerForm.getModelObject().setStudyCompList( studyService.searchStudyComp(containerForm.getModelObject().getStudyComponent())); } } catch (ArkSystemException e) { containerForm .error("A system exception has occurred. Please contact the system administrator."); } pageableListView.removeAll(); return containerForm.getModelObject().getStudyCompList(); } }; 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(); }