List of usage examples for org.apache.shiro SecurityUtils getSubject
public static Subject getSubject()
From source file:at.pollux.thymeleaf.shiro.dialect.ShiroFacade.java
License:Apache License
public static boolean isUser() { return SecurityUtils.getSubject() != null && SecurityUtils.getSubject().getPrincipal() != null; }
From source file:at.pollux.thymeleaf.shiro.dialect.ShiroFacade.java
License:Apache License
public static boolean hasPermission(final String p) { return SecurityUtils.getSubject() != null && SecurityUtils.getSubject().isPermitted(p); }
From source file:at.pollux.thymeleaf.shiro.dialect.ShiroFacade.java
License:Apache License
public static boolean hasRole(final String roleName) { return SecurityUtils.getSubject() != null && SecurityUtils.getSubject().hasRole(roleName); }
From source file:at.pollux.thymeleaf.shiro.dialect.ShiroFacade.java
License:Apache License
public static boolean hasAnyRoles(final String... roles) { if (SecurityUtils.getSubject() != null) { for (final String role : roles) { if (SecurityUtils.getSubject().hasRole(StringUtils.trim(role))) { return true; }/*from w ww . j a va 2 s . c om*/ } } return false; }
From source file:at.pollux.thymeleaf.shiro.dialect.ShiroFacade.java
License:Apache License
public static String getPrincipalText(final String type, final String property) { if (SecurityUtils.getSubject() == null) { return ""; }// w ww .j av a 2s. com Object principal = SecurityUtils.getSubject().getPrincipal(); if (type != null || property != null) { if (type != null) { principal = getPrincipalFromClassName(type); } if (principal != null) { return (property == null) ? principal.toString() : getPrincipalProperty(principal, property); } } return principal != null ? principal.toString() : ""; }
From source file:at.pollux.thymeleaf.shiro.dialect.ShiroFacade.java
License:Apache License
public static Object getPrincipalFromClassName(final String type) { Object principal = null;//from ww w . j ava2 s. com try { final Class<?> cls = Class.forName(type); principal = SecurityUtils.getSubject().getPrincipals().oneByType(cls); } catch (final ClassNotFoundException e) { Validate.isTrue(false, "Unable to find class for name [" + type + "]"); } return principal; }
From source file:au.org.theark.admin.web.component.settings.SettingsContainerPanel.java
License:Open Source License
public SettingsContainerPanel(String id, Class teir) { this(id);/*from w w w . j a v a 2s. c o m*/ this.teir = teir; if (teir == SystemWideSetting.class) { cpModel = new CompoundPropertyModel<Setting>(new SystemWideSetting()); cpModel.getObject().setHighestType("system"); } if (teir == StudySpecificSetting.class) { cpModel = new CompoundPropertyModel<Setting>(new StudySpecificSetting()); cpModel.getObject().setHighestType("study"); Long studyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); Study study = iArkCommonService.getStudy(studyId); ((StudySpecificSetting) cpModel.getObject()).setStudy(study); } if (teir == UserSpecificSetting.class) { 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(); } } containerForm.add(initialiseFeedBackPanel()); containerForm.add(initialiseDetailPanel()); containerForm.add(initialiseSearchPanel()); containerForm.add(initialiseSearchResults()); }
From source file:au.org.theark.admin.web.menu.AdminTabProviderImpl.java
License:Open Source License
public ITab createTab(String tabName) { return new ArkMainTab(new Model<String>(tabName)) { private static final long serialVersionUID = -5063032622932238615L; @Override/*from w ww . jav a2 s . c o m*/ public Panel getPanel(String pid) { // The sub menu(s) for Admin return new AdminSubMenuTab(pid); } public boolean isAccessible() { return true; } public boolean isVisible() { boolean flag = false; SecurityManager securityManager = ThreadContext.getSecurityManager(); Subject currentUser = SecurityUtils.getSubject(); // Only a Super Administrator can see the Admin tab/menu if (securityManager.hasRole(currentUser.getPrincipals(), au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)) { flag = currentUser.isAuthenticated(); } else { flag = false; } return flag; } }; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public void createAuditHistory(AuditHistory auditHistory, String userId, Study study) { Date date = new Date(System.currentTimeMillis()); if (userId == null) {// if not forcing a userID manually, get // currentuser Subject currentUser = SecurityUtils.getSubject(); auditHistory.setArkUserId((String) currentUser.getPrincipal()); } else {/*from w w w .j a v a 2 s . c o m*/ auditHistory.setArkUserId(userId); } if (study == null) { Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); if (sessionStudyId != null && auditHistory.getStudyStatus() == null) { auditHistory.setStudyStatus(getStudy(sessionStudyId).getStudyStatus()); } else { if (auditHistory.getEntityType().equalsIgnoreCase(au.org.theark.core.Constants.ENTITY_TYPE_STUDY)) { Study studyFromDB = getStudy(auditHistory.getEntityId()); if (studyFromDB != null) { auditHistory.setStudyStatus(studyFromDB.getStudyStatus()); } } } } else { auditHistory.setStudyStatus(study.getStudyStatus()); } auditHistory.setDateTime(date); getSession().save(auditHistory); // getSession().flush(); }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public void createUpload(Upload studyUpload) throws Exception { if (studyUpload.getUploadStatus() == null) { //studyUpload.setUploadStatus(getUploadStatusForUndefined()); studyUpload.setUploadStatus(getUploadStatusFor(Constants.UPLOAD_STATUS_STATUS_NOT_DEFINED)); }//w w w . j a v a 2 s . c o m Subject currentUser = SecurityUtils.getSubject(); String userId = (String) currentUser.getPrincipal(); studyUpload.setUserId(userId); getSession().save(studyUpload); // getSession().flush(); }