Search in sources :

Example 11 with PermissionChecker

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) PermissionChecker(com.liferay.portal.security.permission.PermissionChecker)

Example 12 with PermissionChecker

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;
}
Also used : Company(com.liferay.portal.model.Company) User(com.liferay.portal.model.User) EncryptorException(com.liferay.util.EncryptorException) PermissionChecker(com.liferay.portal.security.permission.PermissionChecker) ServletException(javax.servlet.ServletException) EncryptorException(com.liferay.util.EncryptorException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

Example 13 with PermissionChecker

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;
}
Also used : PermissionChecker(com.liferay.portal.security.permission.PermissionChecker) PortletPreferences(javax.portlet.PortletPreferences) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 14 with PermissionChecker

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;
}
Also used : KBArticle(com.liferay.knowledgebase.model.KBArticle) PermissionChecker(com.liferay.portal.security.permission.PermissionChecker)

Example 15 with PermissionChecker

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);
    }
}
Also used : PermissionChecker(com.liferay.portal.security.permission.PermissionChecker) Calendar(com.liferay.calendar.model.Calendar) CalendarResource(com.liferay.calendar.model.CalendarResource) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Aggregations

PermissionChecker (com.liferay.portal.security.permission.PermissionChecker)16 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)10 IOException (java.io.IOException)3 Gadget (com.liferay.opensocial.model.Gadget)2 User (com.liferay.portal.model.User)2 ServletException (javax.servlet.ServletException)2 Calendar (com.liferay.calendar.model.Calendar)1 CalendarResource (com.liferay.calendar.model.CalendarResource)1 KBArticle (com.liferay.knowledgebase.model.KBArticle)1 NoSuchGroupException (com.liferay.portal.NoSuchGroupException)1 PortalException (com.liferay.portal.kernel.exception.PortalException)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 JSONArray (com.liferay.portal.kernel.json.JSONArray)1 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 RepositoryException (com.liferay.portal.kernel.repository.RepositoryException)1 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)1 Folder (com.liferay.portal.kernel.repository.model.Folder)1 Indexer (com.liferay.portal.kernel.search.Indexer)1 SearchPermissionChecker (com.liferay.portal.kernel.search.SearchPermissionChecker)1 UploadPortletRequest (com.liferay.portal.kernel.upload.UploadPortletRequest)1