List of usage examples for org.apache.shiro SecurityUtils getSubject
public static Subject getSubject()
From source file:au.org.theark.study.model.dao.LdapUserDao.java
License:Open Source License
public List<ArkUserVO> searchUser(ArkUserVO userVO) throws ArkSystemException { // This is only when you want all the users. List<ArkUserVO> userList = new ArrayList<ArkUserVO>(); /**/* w w w .j a va2 s. c om*/ * Determine the role of the user and return results based on role */ SecurityManager securityManager = ThreadContext.getSecurityManager(); Subject currentUser = SecurityUtils.getSubject(); // Allow only a role that has Create, if (securityManager.isPermitted(currentUser.getPrincipals(), PermissionConstants.CREATE) && securityManager.isPermitted(currentUser.getPrincipals(), PermissionConstants.UPDATE) && securityManager.isPermitted(currentUser.getPrincipals(), PermissionConstants.READ)) { userList = searchAllUsers(userVO); } return userList; }
From source file:au.org.theark.study.model.dao.LdapUserDao.java
License:Open Source License
/** * Looks up a particular user from LDAP using the username/login name for Ark System * /* w w w . ja va 2 s . c o m*/ * @param arkUserName * @return ArkUserVO * @throws ArkSystemException */ public ArkUserVO lookupArkUser(String arkUserName) throws ArkSystemException { SecurityManager securityManager = ThreadContext.getSecurityManager(); Subject currentUser = SecurityUtils.getSubject(); List<ArkUserVO> userList = new ArrayList<ArkUserVO>(); if (securityManager.isPermitted(currentUser.getPrincipals(), PermissionConstants.CREATE) && securityManager.isPermitted(currentUser.getPrincipals(), PermissionConstants.UPDATE) && securityManager.isPermitted(currentUser.getPrincipals(), PermissionConstants.READ)) { log.debug("getBaseDn() " + ldapDataContextSource.getBasePeopleDn());// ou=arkUsers or whatever is configured in the context file. LdapName ldapName; try { AndFilter andFilter = new AndFilter(); andFilter.and(new EqualsFilter("objectClass", "person")); ldapName = new LdapName(ldapDataContextSource.getBasePeopleDn()); // if userId was specified /* User ID */ if (StringUtils.hasText(arkUserName)) { ldapName.add(new Rdn(Constants.CN, arkUserName)); andFilter.and(new EqualsFilter(Constants.CN, arkUserName)); } userList = ldapDataContextSource.getLdapTemplate().search(ldapDataContextSource.getBasePeopleDn(), andFilter.encode(), new PersonContextMapper()); log.debug("Size of list " + userList.size()); } catch (InvalidNameException ine) { log.error("Exception occured in lookupArkUser(String arkUserName) " + ine); throw new ArkSystemException("A system errror occured"); } } ArkUserVO arkUserVO = new ArkUserVO(); if (userList != null && userList.size() > 0) { arkUserVO = userList.get(0); } return arkUserVO; }
From source file:au.org.theark.study.service.StudyServiceImpl.java
License:Open Source License
public StringBuffer uploadAndReportMatrixSubjectFile(File file, String fileFormat, char delimChar, List<String> uidsToUpdate) { StringBuffer uploadReport = null; Subject currentUser = SecurityUtils.getSubject(); Long studyId = (Long) currentUser.getSession().getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); DataUploader subjectUploader = new DataUploader(study, iArkCommonService, this); try {//from w ww .j a v a 2 s . c om InputStream is = new FileInputStream(file); log.info("Importing and reporting Subject file"); uploadReport = subjectUploader.uploadAndReportMatrixSubjectFile(is, file.length(), fileFormat, delimChar, uidsToUpdate); } catch (IOException ioe) { log.error(Constants.IO_EXCEPTION + ioe); } catch (FileFormatException ffe) { log.error(Constants.FILE_FORMAT_EXCEPTION + ffe); } catch (ArkBaseException abe) { log.error(Constants.ARK_BASE_EXCEPTION + abe); } return uploadReport; }
From source file:au.org.theark.study.service.UserServiceImpl.java
License:Open Source License
/** * This is a new interface that persists the user into ArkUsers group in LDAP * //from w ww. j ava2s . c o m * @param arkUserVO * @throws UserNameExistsException * @throws ArkSystemException */ public void createArkUser(ArkUserVO arkUserVO) throws UserNameExistsException, ArkSystemException { // Create user in LDAP try { iLdapUserDao.createArkUser(arkUserVO); // Setting the Username and Study on the ArkUser Hibernate entity from the Value Object that would reflect what it is on LDAP Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); arkUserVO.setStudy(iArkCommonService.getStudy(sessionStudyId)); arkUserVO.getArkUserEntity().setLdapUserName(arkUserVO.getUserName()); // Create the user in Ark Database as well and persist and update and roles user was assigned iArkAuthorisationService.createArkUser(arkUserVO); AuditHistory ah = new AuditHistory(); ah.setActionType(au.org.theark.core.Constants.ACTION_TYPE_CREATED); ah.setComment("User (in LDAP) " + arkUserVO.getUserName() + " was successfully created."); ah.setEntityType(au.org.theark.core.Constants.ENTITY_TYPE_USER); iArkCommonService.createAuditHistory(ah); } catch (UserNameExistsException personExistsException) { throw personExistsException; } }
From source file:au.org.theark.study.util.CustomFieldUploadValidator.java
License:Open Source License
@SuppressWarnings("unchecked") public CustomFieldUploadValidator(IArkCommonService iArkCommonService) { super();/*from www . jav a 2s . c o m*/ this.iArkCommonService = iArkCommonService; Subject currentUser = SecurityUtils.getSubject(); studyId = (Long) currentUser.getSession().getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); this.study = iArkCommonService.getStudy(studyId); this.existantSubjectUIDRows = new HashSet<Integer>(); this.nonExistantUIDs = new HashSet<Integer>(); this.errorCells = new HashSet<ArkGridCell>(); simpleDateFormat.setLenient(false); }
From source file:au.org.theark.study.util.SubjectUploadReport.java
License:Open Source License
public void appendDetails(Upload studyUpload, String studyName) { append("Study: "); appendAndNewLine(studyName);/*from w w w . j av a 2 s . co m*/ append("User ID: "); appendAndNewLine(SecurityUtils.getSubject().getPrincipal().toString()); append("Filename: "); appendAndNewLine(studyUpload.getFilename()); append("File Format: "); appendAndNewLine(studyUpload.getFileFormat().getName()); append("Delimiter Type "); appendAndNewLine(studyUpload.getDelimiterType().getName()); }
From source file:au.org.theark.study.util.SubjectUploadValidator.java
License:Open Source License
public SubjectUploadValidator() { super();/*from w w w.j a v a 2 s . c om*/ Subject currentUser = SecurityUtils.getSubject(); studyId = (Long) currentUser.getSession().getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); this.study = iArkCommonService.getStudy(studyId); this.insertRows = new HashSet<Integer>(); this.updateRows = new HashSet<Integer>(); this.errorCells = new HashSet<ArkGridCell>(); simpleDateFormat.setLenient(false); }
From source file:au.org.theark.study.util.SubjectUploadValidator.java
License:Open Source License
@SuppressWarnings("unchecked") public SubjectUploadValidator(IArkCommonService iArkCommonService) { super();//from ww w. ja v a 2s . c o m this.iArkCommonService = iArkCommonService; Subject currentUser = SecurityUtils.getSubject(); studyId = (Long) currentUser.getSession().getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); this.study = iArkCommonService.getStudy(studyId); this.insertRows = new HashSet<Integer>(); this.updateRows = new HashSet<Integer>(); this.errorCells = new HashSet<ArkGridCell>(); simpleDateFormat.setLenient(false); }
From source file:au.org.theark.study.web.component.address.AddressContainerPanel.java
License:Open Source License
@Override protected WebMarkupContainer initialiseSearchPanel() { Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); // if it was/*www . java 2 s. c om*/ // Set the person who this address should be associated with Collection<Address> addressList = new ArrayList<Address>(); try { if (sessionPersonId != null) { containerForm.getModelObject().getAddress().setPerson(studyService.getPerson(sessionPersonId)); addressList = studyService.getPersonAddressList(sessionPersonId, containerForm.getModelObject().getAddress()); } cpModel.getObject().setAddresses(addressList); searchPanel = new SearchPanel("searchComponentPanel", arkCrudContainerVO, feedBackPanel, containerForm, listView); searchPanel.initialisePanel(cpModel); arkCrudContainerVO.getSearchPanelContainer().add(searchPanel); } catch (EntityNotFoundException e) { // Report this to the user } catch (ArkSystemException e) { // Logged by the back end. Report this to the user } return arkCrudContainerVO.getSearchPanelContainer(); }
From source file:au.org.theark.study.web.component.address.AddressContainerPanel.java
License:Open Source License
@Override protected WebMarkupContainer initialiseSearchResults() { SearchResultListPanel searchResultPanel = new SearchResultListPanel("searchResults", arkCrudContainerVO, containerForm);//from w w w .jav a 2 s . c o m 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<Address> addressList = new ArrayList<Address>(); Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID); try { if (isActionPermitted()) { if (sessionPersonId != null) { addressList = studyService.getPersonAddressList(sessionPersonId, containerForm.getModelObject().getAddress()); } } } catch (ArkSystemException e) { containerForm .error("A system exception has occurred. Please contact the system administrator."); } listView.removeAll(); return addressList; } }; listView = searchResultPanel.buildPageableListView(iModel); listView.setReuseItems(true); // TODO: use Ajax paging navigator PagingNavigator pageNavigator = new PagingNavigator("addressNavigator", listView); searchResultPanel.add(pageNavigator); searchResultPanel.add(listView); arkCrudContainerVO.getSearchResultPanelContainer().add(searchResultPanel); return arkCrudContainerVO.getSearchResultPanelContainer(); }