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.lims.web.component.global.biospecimen.BiospecimenContainerPanel.java

License:Open Source License

public BiospecimenContainerPanel(String id, WebMarkupContainer arkContextMarkup,
        WebMarkupContainer studyNameMarkup, WebMarkupContainer studyLogoMarkup, DefaultTreeModel treeModel) {
    super(id);/*www.  j  a  v  a 2  s. c  o m*/
    this.arkContextMarkup = arkContextMarkup;
    this.studyNameMarkup = studyNameMarkup;
    this.studyLogoMarkup = studyLogoMarkup;

    limsVO.setTreeModel(treeModel);

    // Get session data (used for subject search)
    //      Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession().getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    //      Study study = iArkCommonService.getStudy(sessionStudyId);
    //      limsVO.setStudy(study);

    cpModel = new CompoundPropertyModel<LimsVO>(limsVO);

    Subject currentUser = SecurityUtils.getSubject();
    ArkUser arkUser;
    try {
        arkUser = iArkCommonService.getArkUser(currentUser.getPrincipal().toString());
        ArkUserVO arkUserVo = new ArkUserVO();
        arkUserVo.setArkUserEntity(arkUser);
        List<Study> studies = iArkCommonService.getStudyListForUser(arkUserVo);
        cpModel.getObject().setStudyList(studies);
    } catch (EntityNotFoundException e) {
        e.printStackTrace();
    }

    arkCrudContainerVO = new ArkCrudContainerVO();

    initialisePanel();
}

From source file:au.org.theark.lims.web.component.global.biospecimen.form.BiospecimenListForm.java

License:Open Source License

private void initialiseDataView() {

    Subject currentUser = SecurityUtils.getSubject();
    ArkUser arkUser;//from  w  ww .  j a  v  a 2 s. c  om
    try {
        arkUser = iArkCommonService.getArkUser(currentUser.getPrincipal().toString());
        ArkUserVO arkUserVo = new ArkUserVO();
        arkUserVo.setArkUserEntity(arkUser);
        studyListForUser = iArkCommonService.getStudyListForUser(arkUserVo); //getParentAndChildStudies(sessionStudyId);
    } catch (EntityNotFoundException e) {
        e.printStackTrace();
    }

    dataViewListWMC = new WebMarkupContainer("dataViewListWMC");
    dataViewListWMC.setOutputMarkupId(true);
    // Data provider to paginate resultList
    biospecimenProvider = new ArkDataProvider2<LimsVO, Biospecimen>() {

        private static final long serialVersionUID = 1L;

        public int size() {
            return (int) iLimsService.getBiospecimenCount(criteriaModel.getObject());
        }

        public Iterator<Biospecimen> iterator(int first, int count) {
            List<Biospecimen> biospecimenList = new ArrayList<Biospecimen>();
            if (ArkPermissionHelper.isActionPermitted(au.org.theark.core.Constants.SEARCH)) {
                biospecimenList = iLimsService.searchPageableBiospecimens(criteriaModel.getObject(), first,
                        count);
            }
            return biospecimenList.iterator();
        }
    };
    // Set the criteria into the data provider's model
    biospecimenProvider.setCriteriaModel(cpModel);

    dataView = buildDataView(biospecimenProvider);
    dataView.setItemsPerPage(iArkCommonService.getRowsPerPage());

    final IModel<String> amountModel = new Model<String>(Integer.toString(biospecimenProvider.size()));
    dataViewListWMC.add(new Label("total", amountModel) {
        private static final long serialVersionUID = 1L;

        protected void onBeforeRender() {
            amountModel.setObject(Integer.toString(biospecimenProvider.size()));
            super.onBeforeRender();
        };
    });

    AjaxPagingNavigator pageNavigator = new AjaxPagingNavigator("navigator", dataView) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onAjaxEvent(AjaxRequestTarget target) {
            target.add(dataViewListWMC);
        }
    };
    dataViewListWMC.add(pageNavigator);
    dataViewListWMC.add(dataView);

    List<IColumn<Biospecimen>> columns = new ArrayList<IColumn<Biospecimen>>();
    columns.add(new ExportableTextColumn<Biospecimen>(Model.of("BiospecimenUID"), "biospecimenUid"));
    columns.add(new ExportableTextColumn<Biospecimen>(Model.of("Study"), "study.name"));
    columns.add(new ExportableTextColumn<Biospecimen>(Model.of("SubjectUID"), "linkSubjectStudy.subjectUID"));
    columns.add(new ExportableTextColumn<Biospecimen>(Model.of("ParentUID"), "parentUid"));
    columns.add(new ExportableTextColumn<Biospecimen>(Model.of("Collection"), "bioCollection.name"));
    columns.add(new ExportableTextColumn<Biospecimen>(Model.of("Sample Type"), "sampleType.name"));
    columns.add(new ExportableTextColumn<Biospecimen>(Model.of("Quantity"), "quantity"));

    DataTable table = new DataTable("datatable", columns, dataView.getDataProvider(),
            iArkCommonService.getRowsPerPage());
    List<String> headers = new ArrayList<String>(0);
    headers.add("BiospecimenUID");
    headers.add("Study");
    headers.add("SubjectUID");
    headers.add("ParentUID");
    headers.add("Collection");
    headers.add("Sample Type");
    headers.add("Quantity");

    String filename = "biospecimens";
    RepeatingView toolbars = new RepeatingView("toolbars");
    ExportToolbar<String> exportToolBar = new ExportToolbar<String>(table, headers, filename);
    toolbars.add(new Component[] { exportToolBar });
    dataViewListWMC.add(toolbars);
    add(dataViewListWMC);
}

From source file:au.org.theark.lims.web.component.global.biospecimen.form.SearchForm.java

License:Open Source License

private void initStudyDdc() {
    CompoundPropertyModel<LimsVO> limsCpm = cpmModel;
    PropertyModel<Study> studyPm = new PropertyModel<Study>(limsCpm, "study");
    List<Study> studyListForUser = new ArrayList<Study>(0);
    try {/*w  w w  .j  a v  a2s .co  m*/
        Subject currentUser = SecurityUtils.getSubject();
        ArkUser arkUser = iArkCommonService.getArkUser(currentUser.getPrincipal().toString());
        ArkUserVO arkUserVo = new ArkUserVO();
        arkUserVo.setArkUserEntity(arkUser);

        //Long sessionArkModuleId = (Long) SecurityUtils.getSubject().getSession().getAttribute(au.org.theark.core.Constants.ARK_MODULE_KEY);
        //ArkModule arkModule = null;
        //arkModule = iArkCommonService.getArkModuleById(sessionArkModuleId);
        //studyListForUser = iArkCommonService.getStudyListForUserAndModule(arkUserVo, arkModule);

        studyListForUser = iArkCommonService.getStudyListForUser(arkUserVo);

        cpmModel.getObject().setStudyList(studyListForUser);
    } catch (EntityNotFoundException e) {
        log.error(e.getMessage());
    }
    ChoiceRenderer<Study> studyRenderer = new ChoiceRenderer<Study>(Constants.NAME, Constants.ID);
    studyDdc = new DropDownChoice<Study>("study", studyPm, (List<Study>) studyListForUser, studyRenderer) {
        @Override
        protected void onBeforeRender() {
            Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
                    .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
            //            Study study = iArkCommonService.getStudy(sessionStudyId);
            //            cpmModel.getObject().setStudy(study);
            super.onBeforeRender();
        };
    };
}

From source file:au.org.theark.lims.web.component.inventory.form.AbstractInventoryDetailForm.java

License:Open Source License

@Override
public void onBeforeRender() {
    super.onBeforeRender();
    visitChildren(formVisitor);//from   www  .  j ava2 s. c  o m

    SecurityManager securityManager = ThreadContext.getSecurityManager();
    Subject currentUser = SecurityUtils.getSubject();
    if (ArkPermissionHelper.hasEditPermission(securityManager, currentUser) || //User can UPDATE
            ArkPermissionHelper.hasNewPermission(securityManager, currentUser) || //User can CREATE
            ArkPermissionHelper.hasDeletePermission(securityManager, currentUser)) { //User can DELETE

        detailFormContainer.setEnabled(true);
        editButtonContainer.setVisible(true);
        editButtonContainer.setEnabled(true);

    } else {

        detailFormContainer.setEnabled(false);
        editButtonContainer.setVisible(true);
        editButtonContainer.setEnabled(true);
    }

    if (ArkPermissionHelper.isActionPermitted(Constants.DELETE)) {
        AjaxButton ajaxButton = (AjaxButton) editButtonContainer.get("delete");
        if (ajaxButton != null) {
            ajaxButton.setEnabled(true);
        }
    }
}

From source file:au.org.theark.lims.web.component.inventory.form.BoxAllocationDetailForm.java

License:Open Source License

@Override
protected void onSave(Form<LimsVO> containerForm, AjaxRequestTarget target) {
    if (containerForm.getModelObject().getInvBox().getAvailable() == 0) {
        this.error("This box has no available locations");
    } else {//from  w w w .j  ava  2  s  .  c o m
        String biospecimenUid = containerForm.getModelObject().getBiospecimen().getBiospecimenUid();

        if (biospecimenUid != null && !biospecimenUid.isEmpty()) {
            Long studyId = (Long) SecurityUtils.getSubject().getSession()
                    .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
            Study study = null;
            //Inventory can be loaded without selecting a study
            if (studyId != null) {
                study = iArkCommonService.getStudy(studyId);
            }

            Biospecimen biospecimen = iLimsService.getBiospecimenByUid(biospecimenUid, study);

            if (biospecimen != null && biospecimen.getId() != null) {
                InvCell invCell = iInventoryService.getInvCellByBiospecimen(biospecimen);

                if (invCell.getBiospecimen() != null) {
                    try {
                        BiospecimenLocationVO biospecimenLocationVO = iInventoryService
                                .getBiospecimenLocation(biospecimen);
                        StringBuilder location = new StringBuilder();
                        location.append("The Biospecimen: ");
                        location.append(biospecimenUid);
                        location.append(" is already allocated at ");
                        location.append("Box: ");
                        location.append(biospecimenLocationVO.getBoxName());
                        location.append(" ");
                        location.append("Row: ");
                        location.append(biospecimenLocationVO.getRowLabel());
                        location.append(", ");
                        location.append("Column: ");
                        location.append(biospecimenLocationVO.getColLabel());
                        this.error(location.toString());
                    } catch (ArkSystemException e) {
                        log.error(e.getMessage());
                    }
                } else {
                    invCell = iInventoryService
                            .getNextAvailableInvCell(containerForm.getModelObject().getInvBox());
                    containerForm.getModelObject().setBiospecimen(biospecimen);
                    invCell.setBiospecimen(containerForm.getModelObject().getBiospecimen());
                    // TODO: use Reference CellStatus
                    invCell.setStatus("Not Empty");

                    containerForm.getModelObject().setInvCell(invCell);
                    iInventoryService.updateInvCell(invCell);
                    try {
                        iLimsService.updateBiospecimen(containerForm.getModelObject());
                    } catch (ArkSystemException e1) {
                        this.error(e1.getMessage());
                    }

                    // Refresh the gridpanel
                    gridBoxPanel = new GridBoxPanel("gridBoxPanel", containerForm.getModelObject(), modalWindow,
                            false);
                    BoxAllocationDetailForm.this.getParent().addOrReplace(gridBoxPanel);
                    target.add(gridBoxPanel);

                    try {
                        BiospecimenLocationVO biospecimenLocationVO = iInventoryService
                                .getBiospecimenLocation(biospecimen);
                        StringBuilder location = new StringBuilder();
                        location.append("The Biospecimen: ");
                        location.append(biospecimenUid);
                        location.append(" allocated to ");
                        location.append("Row: ");
                        location.append(biospecimenLocationVO.getRowLabel());
                        location.append(", ");
                        location.append("Column: ");
                        location.append(biospecimenLocationVO.getColLabel());
                        this.info(location.toString());
                    } catch (ArkSystemException e) {
                        log.error(e.getMessage());
                    }

                    // Refresh text box model reference
                    containerForm.getModelObject().setBiospecimen(new Biospecimen());
                }
            } else {
                this.error("Biospecimen:" + biospecimenUid
                        + " does not exist in the system. Please check and try again");
            }
        } else {
            this.error("Scan or manually enter the Biospecimen UID to allocate to the next available position");
        }
    }

    // refresh feedback
    target.add(feedbackPanel);
}

From source file:au.org.theark.lims.web.component.inventory.form.SiteDetailForm.java

License:Open Source License

@SuppressWarnings("unchecked")
private void initStudyPalette() {
    CompoundPropertyModel<LimsVO> cpm = (CompoundPropertyModel<LimsVO>) containerForm.getModel();
    List<Study> studyListForUser = new ArrayList<Study>(0);
    try {/*from  www .  jav a  2  s  .  co  m*/
        Subject currentUser = SecurityUtils.getSubject();
        ArkUser arkUser = iArkCommonService.getArkUser(currentUser.getPrincipal().toString());
        ArkUserVO arkUserVo = new ArkUserVO();
        arkUserVo.setArkUserEntity(arkUser);

        Long sessionArkModuleId = (Long) SecurityUtils.getSubject().getSession()
                .getAttribute(au.org.theark.core.Constants.ARK_MODULE_KEY);
        ArkModule arkModule = null;
        arkModule = iArkCommonService.getArkModuleById(sessionArkModuleId);
        studyListForUser = iArkCommonService.getStudyListForUserAndModule(arkUserVo, arkModule);
        cpm.getObject().setStudyList(studyListForUser);
    } catch (EntityNotFoundException e) {
        log.error(e.getMessage());
    }

    IChoiceRenderer<String> renderer = new ChoiceRenderer<String>("name", "name");
    PropertyModel<List<Study>> selectedStudies = new PropertyModel<List<Study>>(cpm, "selectedStudies");
    PropertyModel<List<Study>> availableStudies = new PropertyModel<List<Study>>(cpm, "studyList");
    studyPalette = new ArkPalette("selectedStudies", selectedStudies, availableStudies, renderer,
            au.org.theark.core.Constants.PALETTE_ROWS, false) {
        @Override
        protected Recorder newRecorderComponent() {
            Recorder rec = super.newRecorderComponent();
            rec.setRequired(true).setLabel(new StringResourceModel("error.invSite.studies.required", this,
                    new Model<String>("Studies")));
            return rec;
        }

        @Override
        public boolean isVisible() {
            SecurityManager securityManager = ThreadContext.getSecurityManager();
            Subject currentUser = SecurityUtils.getSubject();
            return securityManager.hasRole(currentUser.getPrincipals(),
                    au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR);
        }
    };
}

From source file:au.org.theark.lims.web.component.inventory.panel.box.display.GridBoxPanel.java

License:Open Source License

private void setUserStudyList() {
    List<Study> studyListForUser = new ArrayList<Study>(0);
    try {//from  ww w. j  a  v a2 s .  co m
        Subject currentUser = SecurityUtils.getSubject();
        ArkUser arkUser = iArkCommonService.getArkUser(currentUser.getPrincipal().toString());
        ArkUserVO arkUserVo = new ArkUserVO();
        arkUserVo.setArkUserEntity(arkUser);

        Long sessionArkModuleId = (Long) SecurityUtils.getSubject().getSession()
                .getAttribute(au.org.theark.core.Constants.ARK_MODULE_KEY);
        ArkModule arkModule = iArkCommonService.getArkModuleById(sessionArkModuleId);
        studyListForUser = iArkCommonService.getStudyListForUserAndModule(arkUserVo, arkModule);
        limsVo.setStudyList(studyListForUser);
    } catch (EntityNotFoundException e) {
        log.error(e.getMessage());
    }
}

From source file:au.org.theark.lims.web.component.inventory.panel.site.SiteDetailPanel.java

License:Open Source License

public void initialisePanel() {
    detailForm = new SiteDetailForm("detailForm", feedbackPanel, detailContainer, containerForm, tree, node,
            this) {
        @Override//from   ww w  .j  ava 2  s .  c om
        public boolean isEnabled() {
            try {
                return iArkCommonService
                        .isSuperAdministrator(SecurityUtils.getSubject().getPrincipal().toString());
            } catch (EntityNotFoundException e) {
                return false;
            }
        }
    };
    detailForm.initialiseDetailForm();

    addFreezer = new ArkBusyAjaxButton("addFreezer") {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            containerForm.getModelObject().setInvFreezer(new InvFreezer());
            containerForm.getModelObject().getInvFreezer()
                    .setInvSite(containerForm.getModelObject().getInvSite());
            FreezerDetailPanel freezerDetailPanel = new FreezerDetailPanel("detailPanel", feedbackPanel,
                    detailContainer, containerForm, tree, node);
            freezerDetailPanel.initialisePanel();

            SiteDetailPanel.this.replaceWith(freezerDetailPanel);
            target.add(detailContainer);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
        }

        @Override
        public boolean isVisible() {
            return super.isVisible() && ArkPermissionHelper.isActionPermitted(Constants.SAVE);
        }
    };
    add(detailForm);
    add(addFreezer);
}

From source file:au.org.theark.lims.web.component.inventory.tree.InventoryLinkTree.java

License:Open Source License

/**
 * Creates the model that feeds the tree.
 * // w  w  w  .j  a  v a 2s  .c om
 * @return New instance of tree model.
 */
protected DefaultTreeModel createTreeModel() {
    InvSite invSite = new InvSite();

    List<Study> studyListForUser = new ArrayList<Study>(0);
    try {
        Subject currentUser = SecurityUtils.getSubject();
        ArkUser arkUser = iArkCommonService.getArkUser(currentUser.getPrincipal().toString());
        ArkUserVO arkUserVo = new ArkUserVO();
        arkUserVo.setArkUserEntity(arkUser);

        Long sessionArkModuleId = (Long) SecurityUtils.getSubject().getSession()
                .getAttribute(au.org.theark.core.Constants.ARK_MODULE_KEY);
        ArkModule arkModule = null;
        arkModule = iArkCommonService.getArkModuleById(sessionArkModuleId);
        studyListForUser = iArkCommonService.getStudyListForUserAndModule(arkUserVo, arkModule);
    } catch (EntityNotFoundException e) {
        log.error(e.getMessage());
    }

    try {
        invSites = iInventoryService.searchInvSite(invSite, studyListForUser);
    } catch (ArkSystemException e) {
        log.error(e.getMessage());
    }
    return convertToTreeModel();
}

From source file:au.org.theark.lims.web.component.subjectlims.lims.biocollection.form.BioCollectionListForm.java

License:Open Source License

@Override
public void onBeforeRender() {
    // Get session data (used for subject search)
    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    String sessionSubjectUID = (String) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.SUBJECTUID);

    if ((sessionStudyId != null) && (sessionSubjectUID != null)) {
        LinkSubjectStudy linkSubjectStudy = null;
        Study study = null;// w  ww  . j a  va2  s. com
        boolean contextLoaded = false;
        try {
            study = iArkCommonService.getStudy(sessionStudyId);
            linkSubjectStudy = iArkCommonService.getSubjectByUID(sessionSubjectUID, study);
            if (study != null && linkSubjectStudy != null) {
                contextLoaded = true;
            }
        } catch (EntityNotFoundException e) {
            log.error(e.getMessage());
        }

        if (contextLoaded) {
            // Successfully loaded from backend
            cpModel.getObject().setLinkSubjectStudy(linkSubjectStudy);
            cpModel.getObject().getBioCollection().setLinkSubjectStudy(linkSubjectStudy);
            cpModel.getObject().getBioCollection().setStudy(study);
        }
    }

    super.onBeforeRender();
}