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.core.service.ArkCommonServiceImpl.java

License:Open Source License

@Override
public WebComponent getProductImage() {
    WebComponent productImage = new ContextImage("productImage",
            new Model<String>("images/" + Constants.PRODUCT_IMAGE));

    try {/* w  w w . j a  v  a  2s  . c  om*/
        Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
                .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
        Study study = null;
        if (sessionStudyId != null) {
            study = getStudy(sessionStudyId);
        }
        SettingFile settingFile = iArkSettingService.getSettingFileFromSetting("BRANDING_IMAGE_RIGHT", study,
                null);
        if (settingFile != null) {
            File product_file = retriveArkFileAttachmentAsFile(null, null,
                    au.org.theark.core.Constants.ARK_SETTINGS_DIR, settingFile.getFileId(),
                    settingFile.getChecksum());
            productImage = new NonCachingImage("productImage",
                    new AbstractReadOnlyModel<DynamicImageResource>() {
                        @Override
                        public DynamicImageResource getObject() {
                            DynamicImageResource dir = getDynamicImageResourceForFile(settingFile,
                                    product_file);
                            dir.setFormat("image/png");
                            return dir;
                        }
                    });
        }
    } catch (ArkSystemException e) {
        e.printStackTrace();
    } catch (ArkFileNotFoundException e) {
        e.printStackTrace();
    } catch (ArkCheckSumNotSameException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
    productImage.setOutputMarkupId(true);
    return productImage;
}

From source file:au.org.theark.core.service.ArkCommonServiceImpl.java

License:Open Source License

private ArkUser getCurrentArkUser() {
    ArkUser arkUser = null;/*from w w  w  .  ja  va 2s .com*/
    String sessionUserName = SecurityUtils.getSubject().getPrincipal().toString();
    try {
        arkUser = getArkUser(sessionUserName);
    } catch (EntityNotFoundException e) {
        e.printStackTrace();
    }
    return arkUser;
}

From source file:au.org.theark.core.service.ArkCommonServiceImpl.java

License:Open Source License

private Study getCurrentStudy() {
    Study currentStudy = null;// w w w .  j  a  v  a  2  s. c  o  m

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

From source file:au.org.theark.core.util.CustomFieldImporter.java

License:Open Source License

/**
 * PhenotypicImport constructor/* ww  w  .j  a  v a2 s .  c  o  m*/
 * 
 * @param studyId
 *           study identifier in context
 * @param arkFunction
 *           the function that this CustomField import should attach to
 * @param iArkCommonService
 *           the common service for dao
 * @param fileFormat
 *           format of the file uploaded
 * @param delimiterChar
 *           delimiter of the file data (comma, tab etc)
 */
public CustomFieldImporter(Study study, ArkFunction arkFunction, IArkCommonService<Void> iArkCommonService,
        String fileFormat, char delimiterChar) {
    this.study = study;
    this.iArkCommonService = iArkCommonService;
    this.fileFormat = fileFormat;
    this.phenotypicDelimChr = delimiterChar;
    this.arkFunction = arkFunction;
    Long sessionModuleId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.ARK_MODULE_KEY);
    this.arkModule = iArkCommonService.getArkModuleById(sessionModuleId);
}

From source file:au.org.theark.core.util.CustomFieldImportValidator.java

License:Open Source License

/**
 * CustomFieldImportValidator constructor
 * @param iArkCommonService//  w w w  . j a  v  a2  s .c  o  m
 * @param uploadVo
 */
public CustomFieldImportValidator(IArkCommonService<Void> iArkCommonService, UploadVO uploadVo) {
    this.iArkCommonService = iArkCommonService;
    this.arkFunction = uploadVo.getUpload().getArkFunction();

    // Set study in context
    Long studyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    if (studyId != null) {
        Study study = iArkCommonService.getStudy(studyId);
        this.study = study;
    }

    Long sessionModuleId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.ARK_MODULE_KEY);
    arkModule = iArkCommonService.getArkModuleById(sessionModuleId);
    customFieldTypeLstForModule = iArkCommonService.getCustomFieldTypes(arkModule);

    this.fileValidationMessages = new ArrayList<String>();
    this.dataValidationMessages = new ArrayList<String>();

    String filename = uploadVo.getFileUpload().getClientFileName();
    this.fileFormat = filename.substring(filename.lastIndexOf('.') + 1).toUpperCase();

    this.delimChr = uploadVo.getUpload().getDelimiterType().getDelimiterCharacter();

}

From source file:au.org.theark.core.util.UploadReport.java

License:Open Source License

public void appendDetails(Upload upload) {
    append("Study: ");
    appendAndNewLine(upload.getStudy().getName());
    append("User ID: ");
    appendAndNewLine(SecurityUtils.getSubject().getPrincipal().toString());
    append("Filename: ");
    appendAndNewLine(upload.getFilename());
    append("File Format: ");
    appendAndNewLine(upload.getFileFormat().getName());
    append("Delimiter Type: ");
    appendAndNewLine(upload.getDelimiterType().getName());
}

From source file:au.org.theark.core.web.component.AbstractContainerPanel.java

License:Open Source License

/**
 * //from  ww  w  .j  ava  2 s .  c  om
 * @param id
 */
public AbstractContainerPanel(String id) {
    super(id);
    Subject currentUser = SecurityUtils.getSubject();
    arkLdapRealm.clearCachedAuthorizationInfo(currentUser.getPrincipals());
    aafRealm.clearCachedAuthorizationInfo(currentUser.getPrincipals());
    initCrudContainerVO();
}

From source file:au.org.theark.core.web.component.AbstractContainerPanel.java

License:Open Source License

protected boolean isActionPermitted() {
    boolean flag = false;
    SecurityManager securityManager = ThreadContext.getSecurityManager();
    Subject currentUser = SecurityUtils.getSubject();
    if (securityManager.isPermitted(currentUser.getPrincipals(), PermissionConstants.READ)) {
        flag = true;//from w w  w.  java 2 s . c o m
    } else {
        flag = false;
    }
    return flag;
}

From source file:au.org.theark.core.web.component.AbstractContainerPanel.java

License:Open Source License

protected void disableUploadersInDemoMode() {
    SecurityManager securityManager = ThreadContext.getSecurityManager();
    Subject currentUser = SecurityUtils.getSubject();
    if (!securityManager.hasRole(currentUser.getPrincipals(),
            au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)
            && Constants.YES.equalsIgnoreCase(iArkCommonService.getDemoMode().getPropertyValue())) {

        ComponentHierarchyIterator iterrator = this.visitChildren();

        while (iterrator.hasNext()) {
            Component component = iterrator.next();
            if (FileUploadField.class.isAssignableFrom(component.getClass())) {
                component.setEnabled(false);
            }/*from   www . java 2 s .  c o m*/
        }
    }
}

From source file:au.org.theark.core.web.component.AbstractSubContainerPanel.java

License:Open Source License

/**
 * @param id/* ww  w.j  a  v a 2s.  c  o  m*/
 */
public AbstractSubContainerPanel(String id) {
    super(id);
    setOutputMarkupPlaceholderTag(true);
    Subject currentUser = SecurityUtils.getSubject();
    realm.clearCachedAuthorizationInfo(currentUser.getPrincipals());
    currentUser.hasRole("Administrator");
}