Example usage for org.apache.shiro SecurityUtils getSubject

List of usage examples for org.apache.shiro SecurityUtils getSubject

Introduction

In this page you can find the example usage for org.apache.shiro SecurityUtils getSubject.

Prototype

public static Subject getSubject() 

Source Link

Document

Returns the currently accessible Subject available to the calling code depending on runtime environment.

Usage

From source file:au.org.theark.study.web.component.subjectUpload.SearchResultListPanel.java

License:Open Source License

/**
 * Selection values for the consent template will be make more pricise and easy to select.
 * @param consentTemplate/*from  w w  w .j av a2s. c o  m*/
 * @return
 */
private String[][] makeConsentTemplateSelectionValuesMorePrecise(String[][] consentTemplate) {

    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    Study study = iArkCommonService.getStudy(sessionStudyId);
    List<String> studyCompList = convertListOfObjectsToListOfString(
            iArkCommonService.getStudyComponentByStudy(study));
    List<String> studyCompStatus = convertListOfObjectsToListOfString(
            iArkCommonService.getStudyComponentStatus());
    List<String> consentTypes = convertListOfObjectsToListOfString(iArkCommonService.getConsentType());
    List<String> consentStatus = convertListOfObjectsToListOfString(iArkCommonService.getConsentStatus());

    //Here we have to be careful not to use the reference object since it will destroy the original values
    //So array copying will do the trick to keep the original values unchanged for other studies to use it.
    String[][] newConsentTemplate = new String[consentTemplate.length][consentTemplate[1].length];

    arrayCopy(consentTemplate, newConsentTemplate);

    for (String[] mainArray : newConsentTemplate) {
        for (String innerArray : mainArray) {
            switch (innerArray) {
            case "@CompName":
                mainArray[ArrayUtils.indexOf(mainArray,
                        innerArray)] = mainArray[ArrayUtils.indexOf(mainArray, innerArray)].replace(innerArray,
                                " [" + StringUtils.join(studyCompList, ',') + "].");
                break;
            case "@CompNameStatus":
                mainArray[ArrayUtils.indexOf(mainArray,
                        innerArray)] = mainArray[ArrayUtils.indexOf(mainArray, innerArray)].replace(innerArray,
                                " [" + StringUtils.join(studyCompStatus, ',') + "].");
                break;
            case "@ConsentName":
                mainArray[ArrayUtils.indexOf(mainArray,
                        innerArray)] = mainArray[ArrayUtils.indexOf(mainArray, innerArray)].replace(innerArray,
                                " [" + StringUtils.join(consentTypes, ',') + "].");
                break;
            case "@ConsentStatus":
                mainArray[ArrayUtils.indexOf(mainArray,
                        innerArray)] = mainArray[ArrayUtils.indexOf(mainArray, innerArray)].replace(innerArray,
                                " [" + StringUtils.join(consentStatus, ',') + "].");
                break;
            default:
                break;
            }
        }
    }
    return newConsentTemplate;
}

From source file:au.org.theark.study.web.component.subjectUpload.SubjectUploadContainerPanel.java

License:Open Source License

public SubjectUploadContainerPanel(String id, ArkFunction arkFunction) {
    super(id);//from  w w  w .  java2  s  .c  o m

    /* Initialise the CPM */
    cpModel = new CompoundPropertyModel<UploadVO>(new UploadVO());
    this.arkFunction = arkFunction;
    /* Bind the CPM to the Form */
    containerForm = new ContainerForm("containerForm", cpModel);
    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    Study study = iArkCommonService.getStudy(sessionStudyId);
    containerForm.getModelObject().setStudy(study);

    containerForm.add(initialiseFeedBackPanel());
    containerForm.add(initialiseWizardPanel());
    containerForm.add(initialiseSearchResults());
    containerForm.setMultiPart(true);
    add(containerForm);
}

From source file:au.org.theark.study.web.component.subjectUpload.SubjectUploadContainerPanel.java

License:Open Source License

protected WebMarkupContainer initialiseSearchResults() {
    searchResultPanel = new SearchResultListPanel("searchResults", feedBackPanel, containerForm,
            arkCrudContainerVO);/*from w  w  w  .ja va  2  s  .  c  om*/

    iModel = new LoadableDetachableModel<Object>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected Object load() {
            // Return all Uploads for the Study in context
            java.util.Collection<Upload> studyUploads = new ArrayList<Upload>();
            Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
                    .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);

            //if (isActionPermitted() && sessionStudyId != null) {  TODO we need so make sure permission logic only occurs at the highest possible level
            if (sessionStudyId != null) {
                Upload studyUpload = new Upload();
                studyUpload.setStudy(iArkCommonService.getStudy(sessionStudyId));
                studyUpload.setArkFunction(arkFunction);
                studyUploads = iArkCommonService.searchUploads(studyUpload);

            }
            listView.removeAll();
            return studyUploads;
        }
    };

    listView = searchResultPanel.buildPageableListView(iModel);
    listView.setReuseItems(true);
    PagingNavigator pageNavigator = new PagingNavigator("navigator", listView);
    searchResultPanel.add(pageNavigator);
    searchResultPanel.add(listView);
    arkCrudContainerVO.getSearchResultPanelContainer().add(searchResultPanel);
    searchResultPanel.setVisible(true);

    return arkCrudContainerVO.getSearchResultPanelContainer();
}

From source file:au.org.theark.study.web.component.subjectUpload.SubjectUploadStep1.java

License:Open Source License

private void saveFileInMemory() {
    Long studyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    Study study = iArkCommonService.getStudy(studyId);
    FileUpload fileUpload = fileUploadField.getFileUpload();
    containerForm.getModelObject().setFileUpload(fileUpload);
    Payload payload = iArkCommonService.createPayload(fileUpload.getBytes());

    containerForm.getModelObject().getUpload().setPayload(payload);
    String filename = containerForm.getModelObject().getFileUpload().getClientFileName();
    String fileFormatName = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase();
    au.org.theark.core.model.study.entity.FileFormat fileFormat = new au.org.theark.core.model.study.entity.FileFormat();
    fileFormat = iArkCommonService.getFileFormatByName(fileFormatName);
    byte[] byteArray = fileUpload.getMD5();
    String checksum = getHex(byteArray);

    containerForm.getModelObject().getUpload().setStudy(study);
    //containerForm.getModelObject().getUpload().set;
    containerForm.getModelObject().getUpload().setFileFormat(fileFormat);
    containerForm.getModelObject().getUpload().setChecksum(checksum);
    containerForm.getModelObject().getUpload().setFilename(filename);
    containerForm.getModelObject().getUpload().setStartTime(new Date(System.currentTimeMillis()));
    containerForm.getModelObject().getUpload().setArkFunction(
            iArkCommonService.getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_STUDY_STUDY_DATA_UPLOAD));
    wizardForm.setFileName(filename);/*from w  ww  . ja  va  2 s.c om*/

    containerForm.getModelObject().getUpload()
            .setUploadStatus(iArkCommonService.getUploadStatusFor(Constants.UPLOAD_STATUS_AWAITING_VALIDATION));

    //Move to step 2 to add the file type validation 
    //      iArkCommonService.createUpload(containerForm.getModelObject().getUpload());
}

From source file:au.org.theark.study.web.component.subjectUpload.SubjectUploadStep4.java

License:Open Source License

@Override
public void onStepOutNext(AbstractWizardForm<?> form, AjaxRequestTarget target) {
    form.getNextButton().setEnabled(false);
    target.add(form.getNextButton());//from  w  w  w.  j a v a 2s  .  c om
    // Filename seems to be lost from model when moving between steps in wizard?  is this a symptom of something greater?
    containerForm.getModelObject().getUpload().setFilename(wizardForm.getFileName());

    String fileFormat = containerForm.getModelObject().getUpload().getFileFormat().getName();
    char delimiterChar = containerForm.getModelObject().getUpload().getDelimiterType().getDelimiterCharacter();
    try {
        List<String> uidsToUpload = containerForm.getModelObject().getUidsToUpload();
        //log.info("________________________________________________________" + "about to try passing list of uids is of size " + uidsToUpload.size() );
        InputStream inputStream = containerForm.getModelObject().getFileUpload().getInputStream();
        long size = containerForm.getModelObject().getFileUpload().getSize();
        Long uploadId = containerForm.getModelObject().getUpload().getId();
        String report = generateInitialUploadReport();

        Subject currentUser = SecurityUtils.getSubject();
        Long studyId = (Long) currentUser.getSession()
                .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
        String customfieldType = containerForm.getModelObject().getCustomFieldType();

        if (containerForm.getModelObject().getUpload().getUploadType().getName()
                .equalsIgnoreCase(Constants.SUBJECT_DEMOGRAPHIC_DATA)) {
            StudyDataUploadExecutor task = new StudyDataUploadExecutor(iArkCommonService, iStudyService,
                    inputStream, uploadId, //null user
                    studyId, fileFormat, delimiterChar, size, report, uidsToUpload);
            task.run();
        } else if (containerForm.getModelObject().getUpload().getUploadType().getName()
                .equalsIgnoreCase(Constants.STUDY_SPECIFIC_CUSTOM_DATA)) {
            SubjectCustomDataUploadExecutor task = new SubjectCustomDataUploadExecutor(iArkCommonService,
                    iStudyService, inputStream, uploadId, //null user
                    studyId, fileFormat, delimiterChar, size, report, uidsToUpload, customfieldType,
                    containerForm.getModelObject());
            task.run();
        } else if (containerForm.getModelObject().getUpload().getUploadType().getName()
                .equalsIgnoreCase(Constants.SUBJECT_CONSENT_DATA)) {
            SubjectConsentDataUploadExecutor task = new SubjectConsentDataUploadExecutor(iArkCommonService,
                    iStudyService, inputStream, uploadId, studyId, fileFormat, delimiterChar, size, report);
            task.run();
        } else if (containerForm.getModelObject().getUpload().getUploadType().getName()
                .equalsIgnoreCase(Constants.PEDIGREE_DATA)) {
            PedigreeDataUploadExecutor task = new PedigreeDataUploadExecutor(iArkCommonService, iStudyService,
                    inputStream, uploadId, studyId, fileFormat, delimiterChar, size, report);
            task.run();
        } else if (containerForm.getModelObject().getUpload().getUploadType().getName()
                .equalsIgnoreCase(Constants.SUBJECT_ATTACHMENT_DATA)) {
            SubjectAttachmentDataUploadExecutor task = new SubjectAttachmentDataUploadExecutor(
                    iArkCommonService, iStudyService, uploadId, studyId, fileFormat, inputStream, delimiterChar,
                    size, report);
            task.run();
        }
        //TimeUnit.SECONDS.sleep(10);
        log.info(containerForm.getModelObject().getValidationMessagesAsString());
        getNextStep().handleWizardState(form, target);

    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
}

From source file:au.org.theark.study.web.menu.MainTabProviderImpl.java

License:Open Source License

public ITab createTab(final String tabName) {
    if (tabName.equalsIgnoreCase(au.org.theark.core.Constants.ARK_MODULE_STUDY)) {
        return new ArkMainTab(new Model<String>(tabName)) {
            /**//  ww  w  . j a  v a2s .c o m
             * 
             */
            private static final long serialVersionUID = -8671910074409249398L;

            @Override
            public Panel getPanel(String pid) {
                return panelToReturn(pid, tabName);
            }

            public boolean isAccessible() {
                // Study tab is always accessible
                return true;
            }

            public boolean isVisible() {
                // Study tab is always visible
                return true;
            }
        };
    } else {
        return new ArkMainTab(new Model<String>(tabName)) {
            /**
             * 
             */
            private static final long serialVersionUID = -6838973454398478802L;

            @Override
            public Panel getPanel(String pid) {
                return panelToReturn(pid, tabName);
            }

            public boolean isAccessible() {
                // Only accessible when study in session (repainted on Study selection)
                Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
                        .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
                if (sessionStudyId == null) {
                    this.getPanel(au.org.theark.core.Constants.ARK_MODULE_SUBJECT)
                            .error(au.org.theark.core.Constants.NO_STUDY_IN_CONTEXT_MESSAGE);
                    return false;
                } else
                    return true;
            }

            public boolean isVisible() {
                // Only visible when study in session (repainted on Study selection)
                Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
                        .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
                if (sessionStudyId == null) {
                    return false;
                } else
                    return true;
            }
        };
    }
}

From source file:au.org.theark.study.web.menu.StudySubMenuTab.java

License:Open Source License

/**
 * Build the list of tabs that represent the sub-menus
 *//*from   www .  j  a  v  a  2  s  .co  m*/
public void buildTabs() {
    ArkModule arkModule = iArkCommonService.getArkModuleByName(Constants.ARK_MODULE_STUDY);
    List<ArkFunction> arkFunctionList = iArkCommonService.getModuleFunction(arkModule);// Gets a list of ArkFunctions for the given Module

    /*
     * Iterate each ArkFunction render the Tabs.When something is clicked it uses the arkFunction and calls processAuthorizationCache to clear
     * principals of the user and loads the new set of principals.(permissions)
     */
    for (final ArkFunction menuArkFunction : arkFunctionList) {
        moduleSubTabsList
                .add(new AbstractTab(new StringResourceModel(menuArkFunction.getResourceKey(), this, null)) {
                    /**
                     * 
                     */
                    private static final long serialVersionUID = -8421399480756599074L;

                    @Override
                    public Panel getPanel(String panelId) {
                        Panel panelToReturn = null;// Set up a common tab that will be accessible for all users

                        // Clear authorisation cache
                        processAuthorizationCache(au.org.theark.core.Constants.ARK_MODULE_STUDY,
                                menuArkFunction);

                        if (menuArkFunction.getName()
                                .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_STUDY)) {
                            panelToReturn = new StudyContainerPanel(panelId, studyNameMarkup, studyLogoMarkup,
                                    arkContextMarkup, mainTabProvider.getModuleTabbedPanel());
                        } else if (menuArkFunction.getName().equalsIgnoreCase(
                                au.org.theark.core.Constants.FUNCTION_KEY_VALUE_STUDY_COMPONENT)) {
                            panelToReturn = new StudyComponentContainerPanel(panelId);
                        } else if (menuArkFunction.getName()
                                .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_USER)) {
                            panelToReturn = new UserContainerPanel(panelId);
                        }
                        return panelToReturn;
                    }

                    @Override
                    public boolean isVisible() {
                        if (menuArkFunction.getName()
                                .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_STUDY)) {
                            // Study function always visible
                            return true;
                        } else {
                            // Other functions require study in context 
                            Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
                                    .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);

                            // Manage Users only visible to Super Administrators or Study Administrators 
                            if (menuArkFunction.getName()
                                    .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_USER)) {
                                SecurityManager securityManager = ThreadContext.getSecurityManager();
                                Subject currentUser = SecurityUtils.getSubject();
                                return ArkPermissionHelper.hasEditPermission(securityManager, currentUser)
                                        && sessionStudyId != null;
                            }
                            return sessionStudyId != null;
                        }
                    }
                });
    }

    ArkAjaxTabbedPanel moduleTabbedPanel = new ArkAjaxTabbedPanel(Constants.MENU_STUDY_SUBMENU,
            moduleSubTabsList, arkContextMarkup);
    add(moduleTabbedPanel);
}

From source file:au.org.theark.study.web.menu.SubjectSubMenuTab.java

License:Open Source License

/**
 * @param id//from  www.j av a 2 s  . c om
 */
public SubjectSubMenuTab(String id, WebMarkupContainer arkContextMarkup) {
    super(id);
    this.arkContextMarkup = arkContextMarkup;
    new ArrayList<ITab>();
    buildTabs();

    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    Study study = iArkCommonService.getStudy(sessionStudyId);
    childStudy = study.getParentStudy() != null && (study != study.getParentStudy());
}

From source file:au.org.theark.web.menu.LimsSubMenuTab.java

License:Open Source License

public LimsSubMenuTab(String id, WebMarkupContainer arkContextMarkup, WebMarkupContainer studyNameMarkup,
        WebMarkupContainer studyLogoMarkup, DefaultTreeModel treeModel) {
    super(id);/*from  w  w  w . jav  a  2s  . c  o m*/
    this.arkContextMarkup = arkContextMarkup;
    this.studyNameMarkup = studyNameMarkup;
    this.studyLogoMarkup = studyLogoMarkup;
    this.treeModel = new TreeModel(iArkCommonService, iInventoryService).createTreeModel();
    ArkSession.get().setNodeObject(null);
    buildTabs();

    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    if (sessionStudyId != null) {
        //study = iArkCommonService.getStudy(sessionStudyId);
    }
}

From source file:au.org.theark.web.menu.LimsSubMenuTab.java

License:Open Source License

public void buildTabs() {
    List<ITab> moduleSubTabsList = new ArrayList<ITab>();

    ArkModule arkModule = iArkCommonService.getArkModuleByName(au.org.theark.core.Constants.ARK_MODULE_LIMS);
    List<ArkFunction> arkFunctionList = iArkCommonService.getModuleFunction(arkModule);// Gets a list of ArkFunctions for the given Module

    for (final ArkFunction menuArkFunction : arkFunctionList) {
        moduleSubTabsList/*from  ww  w  . j  ava 2s.co  m*/
                .add(new AbstractTab(new StringResourceModel(menuArkFunction.getResourceKey(), this, null)) {
                    /**
                     * 
                     */
                    private static final long serialVersionUID = 1L;

                    @Override
                    public Panel getPanel(String panelId) {
                        return buildPanels(menuArkFunction, panelId);
                    }

                    @Override
                    public boolean isVisible() {
                        boolean flag = true;
                        SecurityManager securityManager = ThreadContext.getSecurityManager();
                        Subject currentUser = SecurityUtils.getSubject();

                        if (menuArkFunction.getResourceKey()
                                .equalsIgnoreCase("tab.module.lims.barcodeprinter")) {
                            // Barcode printer redundant
                            flag = false;
                        } else if (menuArkFunction.getResourceKey()
                                .equalsIgnoreCase("tab.module.lims.biospecimenuidtemplate")
                                || menuArkFunction.getResourceKey()
                                        .equalsIgnoreCase("tab.module.lims.barcodeprinter")
                                || menuArkFunction.getResourceKey()
                                        .equalsIgnoreCase("tab.module.lims.barcodelabel")) {

                            // Only a Super Administrator or LIMS Administrator can see the biospecimenuidtemplate/barcodeprinter/barcodelabel tabs
                            if (securityManager.hasRole(currentUser.getPrincipals(),
                                    au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)
                                    || securityManager.hasRole(currentUser.getPrincipals(),
                                            au.org.theark.core.security.RoleConstants.ARK_ROLE_LIMS_ADMINISTATOR)) {
                                flag = currentUser.isAuthenticated();
                            } else {
                                flag = false;
                            }
                        }
                        return super.isVisible() && flag;
                    }
                });
    }

    ArkAjaxTabbedPanel moduleTabbedPanel = new ArkAjaxTabbedPanel(Constants.MENU_LIMS_SUBMENU,
            moduleSubTabsList);
    add(moduleTabbedPanel);
}