Example usage for com.liferay.portal.kernel.security.auth PrincipalException PrincipalException

List of usage examples for com.liferay.portal.kernel.security.auth PrincipalException PrincipalException

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.security.auth PrincipalException PrincipalException.

Prototype

public PrincipalException() 

Source Link

Usage

From source file:com.liferay.adaptive.media.web.internal.portlet.action.BaseMVCActionCommand.java

License:Open Source License

private void _checkPermission(PermissionChecker permissionChecker) throws PortalException {

    if (!permissionChecker.isCompanyAdmin()) {
        throw new PrincipalException();
    }/*from w  w  w.  j  a v  a2  s  .co  m*/
}

From source file:com.liferay.adaptive.media.web.internal.servlet.AdaptiveMediaServletTest.java

License:Open Source License

@Test
public void testNoPermissionError() throws Exception {
    Mockito.when(_request.getPathInfo()).thenReturn(StringUtil.randomString());

    Mockito.when(_adaptiveMediaRequestHandlerLocator.locateForPattern(Mockito.anyString()))
            .thenReturn(_adaptiveMediaRequestHandler);

    Mockito.when(_adaptiveMediaRequestHandler.handleRequest(_request))
            .thenThrow(new ServletException(new PrincipalException()));

    _servlet.doGet(_request, _response);

    Mockito.verify(_response).sendError(Mockito.eq(HttpServletResponse.SC_FORBIDDEN), Mockito.anyString());
}

From source file:com.liferay.adaptive.media.web.internal.servlet.AMServletTest.java

License:Open Source License

@Test
public void testNoPermissionError() throws Exception {
    Mockito.when(_request.getPathInfo()).thenReturn(RandomTestUtil.randomString());

    Mockito.when(_amRequestHandlerLocator.locateForPattern(Mockito.anyString())).thenReturn(_amRequestHandler);

    Mockito.when(_amRequestHandler.handleRequest(_request))
            .thenThrow(new ServletException(new PrincipalException()));

    _amServlet.doGet(_request, _response);

    Mockito.verify(_response).sendError(Mockito.eq(HttpServletResponse.SC_FORBIDDEN), Mockito.anyString());
}

From source file:com.liferay.akismet.hook.action.AkismetEditDiscussionAction.java

License:Open Source License

protected void checkPermission(HttpServletRequest request) throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (permissionChecker.isCompanyAdmin()) {
        return;//from  ww  w .  j a  va2s  . c om
    }

    if (permissionChecker.isGroupAdmin(themeDisplay.getScopeGroupId())) {
        return;
    }

    throw new PrincipalException();
}

From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java

License:Open Source License

@Override
public long getGroupIdFromScopeId(String scopeId, long siteGroupId, boolean privateLayout)
        throws PortalException {

    if (scopeId.startsWith(SCOPE_ID_CHILD_GROUP_PREFIX)) {
        String scopeIdSuffix = scopeId.substring(SCOPE_ID_CHILD_GROUP_PREFIX.length());

        long childGroupId = GetterUtil.getLong(scopeIdSuffix);

        Group childGroup = _groupLocalService.getGroup(childGroupId);

        if (!childGroup.hasAncestor(siteGroupId)) {
            throw new PrincipalException();
        }/*w w  w . j a  va2s  .co m*/

        return childGroupId;
    } else if (scopeId.startsWith(SCOPE_ID_GROUP_PREFIX)) {
        String scopeIdSuffix = scopeId.substring(SCOPE_ID_GROUP_PREFIX.length());

        if (scopeIdSuffix.equals(GroupConstants.DEFAULT)) {
            return siteGroupId;
        }

        long scopeGroupId = GetterUtil.getLong(scopeIdSuffix);

        Group scopeGroup = _groupLocalService.getGroup(scopeGroupId);

        return scopeGroup.getGroupId();
    } else if (scopeId.startsWith(SCOPE_ID_LAYOUT_UUID_PREFIX)) {
        String layoutUuid = scopeId.substring(SCOPE_ID_LAYOUT_UUID_PREFIX.length());

        Layout scopeIdLayout = _layoutLocalService.getLayoutByUuidAndGroupId(layoutUuid, siteGroupId,
                privateLayout);

        Group scopeIdGroup = _groupLocalService.checkScopeGroup(scopeIdLayout,
                PrincipalThreadLocal.getUserId());

        return scopeIdGroup.getGroupId();
    } else if (scopeId.startsWith(SCOPE_ID_LAYOUT_PREFIX)) {

        // Legacy portlet preferences

        String scopeIdSuffix = scopeId.substring(SCOPE_ID_LAYOUT_PREFIX.length());

        long scopeIdLayoutId = GetterUtil.getLong(scopeIdSuffix);

        Layout scopeIdLayout = _layoutLocalService.getLayout(siteGroupId, privateLayout, scopeIdLayoutId);

        Group scopeIdGroup = scopeIdLayout.getScopeGroup();

        return scopeIdGroup.getGroupId();
    } else if (scopeId.startsWith(SCOPE_ID_PARENT_GROUP_PREFIX)) {
        String scopeIdSuffix = scopeId.substring(SCOPE_ID_PARENT_GROUP_PREFIX.length());

        long parentGroupId = GetterUtil.getLong(scopeIdSuffix);

        Group parentGroup = _groupLocalService.getGroup(parentGroupId);

        if (!SitesUtil.isContentSharingWithChildrenEnabled(parentGroup)) {
            throw new PrincipalException();
        }

        Group group = _groupLocalService.getGroup(siteGroupId);

        if (!group.hasAncestor(parentGroupId)) {
            throw new PrincipalException();
        }

        return parentGroupId;
    } else {
        throw new IllegalArgumentException("Invalid scope ID " + scopeId);
    }
}

From source file:com.liferay.asset.publisher.web.portlet.action.AssetPublisherConfigurationAction.java

License:Open Source License

protected void checkPermission(ActionRequest actionRequest, String scopeId) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    if (!assetPublisherWebUtil.isScopeIdSelectable(themeDisplay.getPermissionChecker(), scopeId,
            themeDisplay.getCompanyGroupId(), layout, true)) {

        throw new PrincipalException();
    }// w w w.j av  a2  s  .c om
}

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

public static long getGroupIdFromScopeId(String scopeId, long siteGroupId, boolean privateLayout)
        throws PortalException {

    if (scopeId.startsWith(SCOPE_ID_CHILD_GROUP_PREFIX)) {
        String scopeIdSuffix = scopeId.substring(SCOPE_ID_CHILD_GROUP_PREFIX.length());

        long childGroupId = GetterUtil.getLong(scopeIdSuffix);

        Group childGroup = _groupLocalService.getGroup(childGroupId);

        if (!childGroup.hasAncestor(siteGroupId)) {
            throw new PrincipalException();
        }// w  w w.ja v  a2  s .co  m

        return childGroupId;
    } else if (scopeId.startsWith(SCOPE_ID_GROUP_PREFIX)) {
        String scopeIdSuffix = scopeId.substring(SCOPE_ID_GROUP_PREFIX.length());

        if (scopeIdSuffix.equals(GroupConstants.DEFAULT)) {
            return siteGroupId;
        }

        long scopeGroupId = GetterUtil.getLong(scopeIdSuffix);

        Group scopeGroup = _groupLocalService.getGroup(scopeGroupId);

        return scopeGroup.getGroupId();
    } else if (scopeId.startsWith(SCOPE_ID_LAYOUT_UUID_PREFIX)) {
        String layoutUuid = scopeId.substring(SCOPE_ID_LAYOUT_UUID_PREFIX.length());

        Layout scopeIdLayout = _layoutLocalService.getLayoutByUuidAndGroupId(layoutUuid, siteGroupId,
                privateLayout);

        Group scopeIdGroup = _groupLocalService.checkScopeGroup(scopeIdLayout,
                PrincipalThreadLocal.getUserId());

        return scopeIdGroup.getGroupId();
    } else if (scopeId.startsWith(SCOPE_ID_LAYOUT_PREFIX)) {

        // Legacy portlet preferences

        String scopeIdSuffix = scopeId.substring(SCOPE_ID_LAYOUT_PREFIX.length());

        long scopeIdLayoutId = GetterUtil.getLong(scopeIdSuffix);

        Layout scopeIdLayout = _layoutLocalService.getLayout(siteGroupId, privateLayout, scopeIdLayoutId);

        Group scopeIdGroup = scopeIdLayout.getScopeGroup();

        return scopeIdGroup.getGroupId();
    } else if (scopeId.startsWith(SCOPE_ID_PARENT_GROUP_PREFIX)) {
        String scopeIdSuffix = scopeId.substring(SCOPE_ID_PARENT_GROUP_PREFIX.length());

        long parentGroupId = GetterUtil.getLong(scopeIdSuffix);

        Group parentGroup = _groupLocalService.getGroup(parentGroupId);

        if (!SitesUtil.isContentSharingWithChildrenEnabled(parentGroup)) {
            throw new PrincipalException();
        }

        Group group = _groupLocalService.getGroup(siteGroupId);

        if (!group.hasAncestor(parentGroupId)) {
            throw new PrincipalException();
        }

        return parentGroupId;
    } else {
        throw new IllegalArgumentException("Invalid scope ID " + scopeId);
    }
}

From source file:com.liferay.blogs.web.internal.portlet.action.TrackbackMVCActionCommandTest.java

License:Open Source License

@Test
public void testPrincipalException() throws Exception {
    whenGetEntryThenThrow(new PrincipalException());

    initValidURL();/*from   w  w  w .  j av a  2 s . c  o  m*/

    addTrackback();

    assertError("Blog entry must have guest view permissions to enable trackbacks");
}

From source file:com.liferay.layout.admin.web.internal.portlet.action.ResetCustomizationViewMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (!LayoutPermissionUtil.contains(themeDisplay.getPermissionChecker(), themeDisplay.getLayout(),
            ActionKeys.CUSTOMIZE)) {/* ww  w  .j  a  va 2 s . c  o  m*/

        throw new PrincipalException();
    }

    LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

    if ((layoutTypePortlet != null) && layoutTypePortlet.isCustomizable()
            && layoutTypePortlet.isCustomizedView()) {

        layoutTypePortlet.resetUserPreferences();
    }

    MultiSessionMessages.add(actionRequest, _portal.getPortletId(actionRequest) + "requestProcessed");

    Layout layout = themeDisplay.getLayout();

    actionResponse.sendRedirect(layout.getRegularURL(_portal.getHttpServletRequest(actionRequest)));
}

From source file:com.liferay.marketplace.internal.service.permission.MarketplacePermission.java

License:Open Source License

public static void check(PermissionChecker permissionChecker) throws PortalException {

    if (!contains(permissionChecker)) {
        throw new PrincipalException();
    }/* ww w. j av  a2  s.  co m*/
}