List of usage examples for org.apache.shiro SecurityUtils getSubject
public static Subject getSubject()
From source file:au.org.theark.study.web.component.manageuser.form.DetailForm.java
License:Open Source License
public void enableOrDisableRemoveButton() { Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(sessionStudyId); try {//from w w w .ja va 2 s .co m ArkUserVO arkUserVO = iUserService.lookupArkUser(containerForm.getModelObject().getUserName(), study); if (!arkUserVO.isArkUserPresentInDatabase()) { deleteButton.setEnabled(false); } else { deleteButton.setEnabled(true); } } catch (ArkSystemException e) { e.printStackTrace(); } }
From source file:au.org.theark.study.web.component.manageuser.form.DetailForm.java
License:Open Source License
/** * /* w w w.jav a 2s .c o m*/ * @param arkUserVOFromBackend */ private void prePopulateArkUserRoleList(ArkUserVO arkUserVOFromBackend) { Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(sessionStudyId); // Get a List of ArkModules and associated ArkRoles linked to the study Collection<ArkModuleVO> listOfModulesAndRolesForStudy = iArkCommonService .getArkModulesAndRolesLinkedToStudy(study); // Note:Ideally using a Hibernate Criteria we should be able to get a List of Modules for (ArkModuleVO arkModuleVO : listOfModulesAndRolesForStudy) { boolean moduleFoundFlag = false; ArkModule module = arkModuleVO.getArkModule(); for (ArkUserRole arkUserRole : arkUserVOFromBackend.getArkUserRoleList()) { ArkModule arkModule = arkUserRole.getArkModule(); if (module.equals(arkModule)) { moduleFoundFlag = true; break; } } if (!moduleFoundFlag) { ArkUserRole userRole = new ArkUserRole(); userRole.setStudy(study); userRole.setArkModule(module); arkUserVOFromBackend.getArkUserRoleList().add(userRole); } } }
From source file:au.org.theark.study.web.component.manageuser.form.SearchForm.java
License:Open Source License
/** * Constructor//from ww w . j av a 2s . c o m * * @param id * @param cpmModel * @param containerForm */ public SearchForm(String id, CompoundPropertyModel<ArkUserVO> cpmModel, ArkCrudContainerVO arkCrudContainerVO, FeedbackPanel feedbackPanel, ContainerForm containerForm, PageableListView<ArkUserVO> pageableListView) { super(id, cpmModel, feedbackPanel, arkCrudContainerVO); this.pageableListView = pageableListView; this.arkCrudContainerVO = arkCrudContainerVO; this.containerForm = containerForm; this.feedbackPanel = feedbackPanel; 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.manageuser.form.SearchForm.java
License:Open Source License
private void prePopulateArkUserRoleList() { Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(sessionStudyId); Collection<ArkModuleVO> listArkModuleVO = iArkCommonService.getArkModulesAndRolesLinkedToStudy(study); for (ArkModuleVO arkModuleVO : listArkModuleVO) { ArkUserRole arkUserRole = new ArkUserRole(); arkUserRole.setStudy(study);//from w w w . jav a2s . co m arkUserRole.setArkModule(arkModuleVO.getArkModule()); containerForm.getModelObject().getArkUserRoleList().add(arkUserRole); } // Available child studies List<Study> availableChildStudies = new ArrayList<Study>(0); if (study.getParentStudy() != null && study.getParentStudy() == study) { availableChildStudies = iStudyService.getChildStudyListOfParent(study); } containerForm.getModelObject().setStudy(study); containerForm.getModelObject().setAvailableChildStudies(availableChildStudies); }
From source file:au.org.theark.study.web.component.manageuser.SearchResultListPanel.java
License:Open Source License
private AjaxLink buildLink(final ArkUserVO arkUserVo, final WebMarkupContainer searchResultsContainer) { AjaxLink link = new AjaxLink("userName") { private static final long serialVersionUID = 1L; @Override/*from w ww . ja v a 2s. c o m*/ public void onClick(AjaxRequestTarget target) { try { // Fetch the user and related details from backend Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(sessionStudyId); ArkUserVO arkUserVOFromBackend = iUserService.lookupArkUser(arkUserVo.getUserName(), study); if (!arkUserVOFromBackend.isArkUserPresentInDatabase()) { containerForm .info(new StringResourceModel("user.not.linked.to.study", this, null).getString()); target.add(feedbackPanel); arkUserVOFromBackend.setChangePassword(true); arkUserVOFromBackend.getArkUserEntity().setLdapUserName(arkUserVo.getUserName()); arkUserVOFromBackend.setStudy(new Study()); prePopulateForNewUser(arkUserVOFromBackend); } else { arkUserVOFromBackend.setStudy(study); prePopulateArkUserRoleList(arkUserVOFromBackend); } containerForm.getModelObject().setArkUserRoleList(arkUserVOFromBackend.getArkUserRoleList()); containerForm.setModelObject(arkUserVOFromBackend); // This triggers the call to populateItem() of the ListView ListView listView = (ListView) arkCrudContainerVO.getWmcForarkUserAccountPanel() .get("arkUserRoleList"); if (listView != null) { listView.removeAll(); } arkCrudContainerVO.getWmcForarkUserAccountPanel().setVisible(true); ArkCRUDHelper.preProcessDetailPanelOnSearchResults(target, arkCrudContainerVO); target.add(feedbackPanel); // Set the MODE here.Since the User Details are from LDAP we don't have a entity that we can use to check for a mode containerForm.getModelObject().setMode(Constants.MODE_EDIT); // Available/assigned child studies List<Study> availableChildStudies = new ArrayList<Study>(0); List<Study> selectedChildStudies = new ArrayList<Study>(0); if (study.getParentStudy() != null && study.getParentStudy() == study) { availableChildStudies = iStudyService.getChildStudyListOfParent(study); // Only assign selected child studies if/when user actually assigned study in context if (arkUserVOFromBackend.getStudy().getId() != null) { selectedChildStudies = iArkCommonService .getAssignedChildStudyListForUser(arkUserVOFromBackend); } } containerForm.getModelObject().setAvailableChildStudies(availableChildStudies); containerForm.getModelObject().setSelectedChildStudies(selectedChildStudies); } catch (ArkSystemException e) { containerForm.error(new StringResourceModel("ark.system.error", this, null).getString()); target.add(feedbackPanel); } } }; // Add the label for the link Label userNameLinkLabel = new Label("userNameLink", arkUserVo.getUserName()); link.add(userNameLinkLabel); return link; }
From source file:au.org.theark.study.web.component.manageuser.SearchResultListPanel.java
License:Open Source License
private void prePopulateForNewUser(ArkUserVO arkUserVOFromBackend) { Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(sessionStudyId); Collection<ArkModuleVO> listArkModuleVO = iArkCommonService.getArkModulesAndRolesLinkedToStudy(study); for (ArkModuleVO arkModuleVO : listArkModuleVO) { ArkUserRole arkUserRole = new ArkUserRole(); arkUserRole.setStudy(study);/*ww w.j a v a 2 s . c om*/ arkUserRole.setArkModule(arkModuleVO.getArkModule()); arkUserVOFromBackend.getArkUserRoleList().add(arkUserRole); } }
From source file:au.org.theark.study.web.component.manageuser.SearchResultListPanel.java
License:Open Source License
private void prePopulateArkUserRoleList(ArkUserVO arkUserVOFromBackend) { Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(sessionStudyId); // Get a List of ArkModules and associated ArkRoles linked to the study Collection<ArkModuleVO> listOfModulesAndRolesForStudy = iArkCommonService .getArkModulesAndRolesLinkedToStudy(study); // Note:Ideally using a Hibernate Criteria we should be able to get a List of Modules for (ArkModuleVO arkModuleVO : listOfModulesAndRolesForStudy) { boolean moduleFoundFlag = false; ArkModule module = arkModuleVO.getArkModule(); for (ArkUserRole arkUserRole : arkUserVOFromBackend.getArkUserRoleList()) { ArkModule arkModule = arkUserRole.getArkModule(); if (module.equals(arkModule)) { moduleFoundFlag = true;/* w w w. j a va 2s. c o m*/ break; } } if (!moduleFoundFlag) { ArkUserRole userRole = new ArkUserRole(); userRole.setStudy(study); userRole.setArkModule(module); arkUserVOFromBackend.getArkUserRoleList().add(userRole); } } }
From source file:au.org.theark.study.web.component.manageuser.UserContainerPanel.java
License:Open Source License
@Override protected WebMarkupContainer initialiseSearchResults() { SearchResultListPanel searchResultListPanel = new SearchResultListPanel("searchResults", arkCrudContainerVO, containerForm, feedBackPanel); iModel = new LoadableDetachableModel<Object>() { private static final long serialVersionUID = 1L; @Override//from www.j a v a 2 s . com protected Object load() { List<ArkUserVO> userResultList = new ArrayList<ArkUserVO>(); Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); String sessionUserName = (String) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.ARK_USERID); if (isActionPermitted()) { if (sessionStudyId != null && sessionStudyId > 0) { ArkUser arkUser = null; try { arkUser = iArkCommonService.getArkUser(sessionUserName); } catch (EntityNotFoundException e) { log.error("User not found: " + arkUser.getLdapUserName()); e.printStackTrace(); } for (ArkUser arkUserEntry : iArkCommonService.getArkUserListByStudy(arkUser, iArkCommonService.getStudy(sessionStudyId))) { ArkUserVO arkUserVO = null; try { arkUserVO = iUserService.getCurrentUser(arkUserEntry.getLdapUserName()); } catch (EntityNotFoundException e) { log.error("User not found: " + arkUserEntry.getLdapUserName()); e.printStackTrace(); } if (arkUserVO != null) { userResultList.add(arkUserVO); } } containerForm.getModelObject().setUserList(userResultList); } pageableListView.removeAll(); } return userResultList; } }; pageableListView = searchResultListPanel.buildPageableListView(iModel, arkCrudContainerVO.getSearchResultPanelContainer()); pageableListView.setReuseItems(true); AjaxPagingNavigator pageNavigator = new AjaxPagingNavigator("navigator", pageableListView); pageNavigator.setOutputMarkupId(true); searchResultListPanel.setOutputMarkupId(true); searchResultListPanel.add(pageNavigator); searchResultListPanel.add(pageableListView); arkCrudContainerVO.getSearchResultPanelContainer().add(searchResultListPanel); return arkCrudContainerVO.getSearchResultPanelContainer(); }
From source file:au.org.theark.study.web.component.manageuser.UserContainerPanel.java
License:Open Source License
@Override protected WebMarkupContainer initialiseSearchPanel() { ArkUserVO arkUserVO = new ArkUserVO(); Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); List<ArkUserVO> userResultList = new ArrayList<ArkUserVO>(); try {// w w w . ja v a2s . c o m if (sessionStudyId != null && sessionStudyId > 0) { userResultList = iUserService.searchUser(arkUserVO); } } catch (ArkSystemException arkException) { } containerForm.getModelObject().setUserList(userResultList); searchPanel = new SearchPanel("searchPanel", arkCrudContainerVO, feedBackPanel, containerForm, pageableListView); searchPanel.initialisePanel(cpModel); arkCrudContainerVO.getSearchPanelContainer().add(searchPanel); return arkCrudContainerVO.getSearchPanelContainer(); }
From source file:au.org.theark.study.web.component.mydetails.form.MyDetailsForm.java
License:Open Source License
@SuppressWarnings({ "unchecked" }) public void initialiseForm() { //ArkUserVO arkUserVOFromBackend = new ArkUserVO(); try {//from w w w .j a v a2s . c o m ArkUserVO arkUserVOFromBackend = iUserService.lookupArkUser(getModelObject().getUserName(), getModelObject().getStudy()); Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); if (sessionStudyId != null) { arkUserVOFromBackend.setStudy(iArkCommonService.getStudy(sessionStudyId)); } else { arkUserVOFromBackend.setStudy(getModelObject().getStudy()); } //Study will selected with model object and that will be the page list view accordingly. listViewPanel.setOutputMarkupId(true); iModel = new LoadableDetachableModel() { private static final long serialVersionUID = 1L; @Override protected Object load() { return getModelObject().getArkRolePolicyTemplatesList(); } }; initStudyDdc(arkUserVOFromBackend); } catch (ArkSystemException e) { log.error(e.getMessage()); } emailTxtField.setOutputMarkupId(true); saveButton = new AjaxButton(Constants.SAVE) { private static final long serialVersionUID = -8737230044711628981L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { arkSettingsDataViewPanel.save(target, form); onSave(target); } public void onError(AjaxRequestTarget target, Form<?> form) { processFeedback(target, feedbackPanel); } }; //Save button will enable if study context enabled only. //Changed refer ARK-1852 //saveButton.setEnabled(isStudyContexSelected()); closeButton = new AjaxButton(Constants.CLOSE) { private static final long serialVersionUID = 5457464178392550628L; public void onSubmit(AjaxRequestTarget target, Form<?> form) { modalWindow.close(target); } public void onError(AjaxRequestTarget target, Form<?> form) { processFeedback(target, feedbackPanel); } }; closeButton.setDefaultFormProcessing(false); emailTxtField.add(EmailAddressValidator.getInstance()); boolean loggedInViaAAF = ((String) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.SHIB_SESSION_ID) != null); groupPasswordContainer.setVisible(!loggedInViaAAF); shibbolethSessionDetails .add(new AttributeModifier("src", ArkShibbolethServiceProviderContextSource.handlerUrl + ArkShibbolethServiceProviderContextSource.session)); shibbolethSession.add(new AttributeModifier("class", "paddedDetailPanel")); shibbolethSession.setVisible(loggedInViaAAF); shibbolethSession.add(shibbolethSessionDetails); CompoundPropertyModel<Setting> cpModel = new CompoundPropertyModel<Setting>(new UserSpecificSetting()); cpModel.getObject().setHighestType("user"); try { ArkUser arkUser = iArkCommonService.getArkUser(SecurityUtils.getSubject().getPrincipal().toString()); ((UserSpecificSetting) cpModel.getObject()).setArkUser(arkUser); } catch (EntityNotFoundException e) { e.printStackTrace(); } ArkDataProvider dataProvider = new ArkDataProvider<Setting, IArkSettingService>(iArkSettingService) { public int size() { return service.getSettingsCount(model.getObject()); } public Iterator<Setting> iterator(int first, int count) { List<Setting> listCollection = new ArrayList<Setting>(); listCollection = service.searchPageableSettings(model.getObject(), first, count); return listCollection.iterator(); } }; // Set the criteria into the data provider's model dataProvider.setModel(new LoadableDetachableModel<Setting>() { @Override protected Setting load() { return cpModel.getObject(); } }); arkSettingsDataViewPanel = new ArkSettingsDataViewPanel("settingsPanel", dataProvider, UserSpecificSetting.class, feedbackPanel); attachValidators(); addComponents(); }