use of com.liferay.portal.security.permission.PermissionChecker in project liferay-ide by liferay.
the class ShindigFilter method doFilter.
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
if (injector == null) {
HttpSession session = request.getSession();
_init(session.getServletContext());
}
PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();
if (permissionChecker == null) {
setPermissionChecker(servletRequest);
}
ShindigUtil.setScheme(servletRequest.getScheme());
String serverName = servletRequest.getServerName();
String host = serverName.concat(StringPool.COLON).concat(String.valueOf(servletRequest.getServerPort()));
ShindigUtil.setHost(host);
HttpServletRequestThreadLocal.setHttpServletRequest(request);
try {
filterChain.doFilter(servletRequest, servletResponse);
} finally {
HttpServletRequestThreadLocal.setHttpServletRequest(null);
}
}
use of com.liferay.portal.security.permission.PermissionChecker in project liferay-ide by liferay.
the class ShindigFilter method setPermissionChecker.
protected boolean setPermissionChecker(ServletRequest servletRequest) {
String companyIdString = CookieKeys.getCookie((HttpServletRequest) servletRequest, CookieKeys.COMPANY_ID);
if (Validator.isNull(companyIdString)) {
return false;
}
long companyId = GetterUtil.getLong(companyIdString);
String userUUID = StringPool.BLANK;
try {
Company company = CompanyLocalServiceUtil.fetchCompany(companyId);
if (company == null) {
return false;
}
String userUUIDString = CookieKeys.getCookie((HttpServletRequest) servletRequest, CookieKeys.USER_UUID);
if (Validator.isNull(userUUIDString)) {
return false;
}
userUUID = GetterUtil.getString(Encryptor.decrypt(company.getKeyObj(), userUUIDString));
} catch (EncryptorException ee) {
return false;
} catch (Exception e) {
_log.error(e, e);
return false;
}
if (!AuthenticatedUserUUIDStoreUtil.exists(userUUID)) {
return false;
}
String userIdString = userUUID.substring(0, userUUID.indexOf(StringPool.PERIOD));
long userId = GetterUtil.getLong(userIdString);
try {
User user = UserLocalServiceUtil.getUserById(userId);
PrincipalThreadLocal.setName(userIdString);
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
} catch (Exception e) {
_log.error(e, e);
return false;
}
return true;
}
use of com.liferay.portal.security.permission.PermissionChecker in project liferay-ide by liferay.
the class ArticlePortlet method getResourcePrimKey.
protected long getResourcePrimKey(RenderRequest renderRequest) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
PortletPreferences preferences = renderRequest.getPreferences();
long defaultValue = GetterUtil.getLong(preferences.getValue("resourcePrimKey", null));
String mvcPath = ParamUtil.getString(renderRequest, "mvcPath");
if (((defaultValue == 0) && mvcPath.equals(viewTemplate)) || mvcPath.equals("/article/select_configuration_article.jsp")) {
return 0;
}
long resourcePrimKey = ParamUtil.getLong(renderRequest, "resourcePrimKey", defaultValue);
if ((resourcePrimKey == 0) || (resourcePrimKey != defaultValue)) {
return resourcePrimKey;
}
PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
if (!KBArticlePermission.contains(permissionChecker, defaultValue, ActionKeys.VIEW)) {
return 0;
}
return defaultValue;
}
use of com.liferay.portal.security.permission.PermissionChecker in project liferay-ide by liferay.
the class FindKBArticleAction method getKBArticle.
protected KBArticle getKBArticle(long resourcePrimKey, int status) throws Exception {
KBArticle kbArticle = KBArticleLocalServiceUtil.fetchLatestKBArticle(resourcePrimKey, status);
if (kbArticle == null) {
return null;
}
PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();
if (!KBArticlePermission.contains(permissionChecker, kbArticle, ActionKeys.VIEW)) {
return null;
}
return kbArticle;
}
use of com.liferay.portal.security.permission.PermissionChecker in project liferay-ide by liferay.
the class CalendarPortlet method addCalendar.
protected void addCalendar(PortletRequest portletRequest, Set<Calendar> calendarsSet, long classNameId, long classPK) throws PortalException, SystemException {
CalendarResource calendarResource = CalendarResourceUtil.getCalendarResource(portletRequest, classNameId, classPK);
if (calendarResource == null) {
return;
}
ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
List<Calendar> calendars = CalendarLocalServiceUtil.getCalendarResourceCalendars(calendarResource.getGroupId(), calendarResource.getCalendarResourceId());
for (Calendar calendar : calendars) {
if (!CalendarPermission.contains(permissionChecker, calendar, ActionKeys.VIEW)) {
continue;
}
calendarsSet.add(calendar);
}
}
Aggregations