Example usage for com.liferay.portal.kernel.security.permission PermissionChecker isOmniadmin

List of usage examples for com.liferay.portal.kernel.security.permission PermissionChecker isOmniadmin

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.security.permission PermissionChecker isOmniadmin.

Prototype

public boolean isOmniadmin();

Source Link

Document

Returns true if the user is a universal administrator.

Usage

From source file:com.liferay.marketplace.app.manager.web.internal.portlet.MarketplaceAppManagerPortlet.java

License:Open Source License

protected void checkOmniAdmin() throws PortletException {
    PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

    if (!permissionChecker.isOmniadmin()) {
        PrincipalException principalException = new PrincipalException.MustBeCompanyAdmin(
                permissionChecker.getUserId());

        throw new PortletException(principalException);
    }//from   w  w w . j  av a 2  s  .c  om
}

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

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker) throws PortalException {

    if (!permissionChecker.isOmniadmin()) {
        return false;
    }//from w w w  .  j  av a 2 s .c  om

    return true;
}

From source file:com.liferay.roles.item.selector.web.internal.display.context.RoleItemSelectorViewDisplayContext.java

License:Open Source License

public SearchContainer<Role> getSearchContainer() throws Exception {
    if (_searchContainer != null) {
        return _searchContainer;
    }/*from   w  ww  .j a  v a2s.  c  o m*/

    _searchContainer = new RoleSearch(_renderRequest, getPortletURL());

    _searchContainer.setEmptyResultsMessage("no-roles-were-found");

    OrderByComparator<Role> orderByComparator = _usersAdmin.getRoleOrderByComparator(getOrderByCol(),
            getOrderByType());

    RowChecker rowChecker = new RoleItemSelectorChecker(_renderResponse, getCheckedRoleIds());

    _searchContainer.setOrderByCol(getOrderByCol());
    _searchContainer.setOrderByComparator(orderByComparator);
    _searchContainer.setOrderByType(getOrderByType());
    _searchContainer.setRowChecker(rowChecker);

    RoleSearchTerms searchTerms = (RoleSearchTerms) _searchContainer.getSearchTerms();

    searchTerms.setType(getType());

    List<Role> results = _roleLocalService.search(CompanyThreadLocal.getCompanyId(), searchTerms.getKeywords(),
            searchTerms.getTypesObj(), QueryUtil.ALL_POS, QueryUtil.ALL_POS,
            _searchContainer.getOrderByComparator());

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

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (!permissionChecker.isOmniadmin()) {
        results = _usersAdmin.filterRoles(permissionChecker, results);
    }

    _searchContainer.setTotal(results.size());

    _searchContainer
            .setResults(ListUtil.subList(results, _searchContainer.getStart(), _searchContainer.getEnd()));

    return _searchContainer;
}

From source file:com.liferay.server.admin.web.internal.portlet.action.EditServerMVCActionCommand.java

License:Open Source License

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

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

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (!permissionChecker.isOmniadmin()) {
        SessionErrors.add(actionRequest, PrincipalException.MustBeOmniadmin.class.getName());

        actionResponse.setRenderParameter("mvcPath", "/error.jsp");

        return;/*from   ww  w  .ja v  a  2 s .  c o m*/
    }

    PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences();

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    String redirect = ParamUtil.getString(actionRequest, "redirect");

    if (cmd.equals("addLogLevel")) {
        addLogLevel(actionRequest);
    } else if (cmd.equals("cacheDb")) {
        cacheDb();
    } else if (cmd.equals("cacheMulti")) {
        cacheMulti();
    } else if (cmd.equals("cacheServlet")) {
        cacheServlet();
    } else if (cmd.equals("cacheSingle")) {
        cacheSingle();
    } else if (cmd.equals("cleanUpPermissions")) {
        CleanUpPermissionsUtil.cleanUpAddToPagePermissions(actionRequest);
    } else if (cmd.equals("cleanUpPortletPreferences")) {
        CleanUpPortletPreferencesUtil.cleanUpLayoutRevisionPortletPreferences();
    } else if (cmd.startsWith("convertProcess.")) {
        redirect = convertProcess(actionRequest, actionResponse, cmd);
    } else if (cmd.equals("dlPreviews")) {
        DLPreviewableProcessor.deleteFiles();
    } else if (cmd.equals("gc")) {
        gc();
    } else if (cmd.equals("installXuggler")) {
        try {
            installXuggler(actionRequest, actionResponse);
        } catch (XugglerInstallException xie) {
            SessionErrors.add(actionRequest, XugglerInstallException.class.getName(), xie);
        }
    } else if (cmd.equals("reindex")) {
        reindex(actionRequest);
    } else if (cmd.equals("reindexDictionaries")) {
        reindexDictionaries(actionRequest);
    } else if (cmd.equals("runScript")) {
        runScript(actionRequest, actionResponse);
    } else if (cmd.equals("shutdown")) {
        shutdown(actionRequest);
    } else if (cmd.equals("threadDump")) {
        threadDump();
    } else if (cmd.equals("updateExternalServices")) {
        updateExternalServices(actionRequest, portletPreferences);
    } else if (cmd.equals("updateLogLevels")) {
        updateLogLevels(actionRequest);
    } else if (cmd.equals("updateMail")) {
        updateMail(actionRequest, portletPreferences);
    } else if (cmd.equals("verifyMembershipPolicies")) {
        verifyMembershipPolicies();
    } else if (cmd.equals("verifyPluginTables")) {
        verifyPluginTables();
    }

    sendRedirect(actionRequest, actionResponse, redirect);
}

From source file:com.liferay.server.manager.internal.servlet.ServerManagerServlet.java

License:Open Source License

protected boolean isValidUser(HttpServletRequest request) {
    try {/*from   ww w.jav a2  s.  c o  m*/
        User user = _portal.getUser(request);

        PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);

        if (permissionChecker.isOmniadmin()) {
            return true;
        }
    } catch (Exception e) {
        _log.error(e, e);
    }

    return false;
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularTeamServiceImpl.java

License:Open Source License

protected void crossCompanyCheck(long targetCompany) throws PortalException {

    long userCompanyId = this.getGuestOrUser().getCompanyId();

    PermissionChecker permissionChecker = getPermissionChecker();

    if (permissionChecker.isSignedIn()) {

        if (userCompanyId != targetCompany
                && (!permissionChecker.isOmniadmin() || !permissionChecker.isCompanyAdmin(targetCompany))) {
            throw new PrincipalException.MustBeOmniadmin(this.getGuestOrUserId());
        }/*w  w w  .jav  a 2 s  . com*/

    } else {

        throw new PrincipalException.MustBeAuthenticated(this.getGuestOrUserId());
    }
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularTeamServiceImpl.java

License:Open Source License

protected void checkPersonalPermission(String actionId) throws PortalException {

    _log.debug("    ... " + actionId + " right on user ... ");

    User user = this.getGuestOrUser();

    PermissionChecker permissionChecker = getPermissionChecker();

    if (!permissionChecker.isOmniadmin() && permissionChecker.isSignedIn()) {

        PortalPermissionUtil.check(getPermissionChecker(), actionId);

    } else if (!permissionChecker.isSignedIn()) {

        throw new PrincipalException.MustBeAuthenticated(this.getGuestOrUserId());

    }//from w  w w . j ava2s  . co  m

}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularTeamServiceImpl.java

License:Open Source License

protected void hasResourcePermission(long teamId, String actionId) throws PortalException {

    _log.debug("    ... " + actionId + " right on resource team " + teamId);

    PermissionChecker permissionChecker = getPermissionChecker();

    if (!permissionChecker.isOmniadmin() && permissionChecker.isSignedIn()) {

        TeamPermissionUtil.check(getPermissionChecker(), teamId, actionId);

    } else if (!permissionChecker.isSignedIn()) {

        throw new PrincipalException.MustBeAuthenticated(this.getGuestOrUserId());

    }/*from www .j av a 2  s  . co  m*/
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularUserGroupServiceImpl.java

License:Open Source License

protected void hasResourcePermission(long userGroupId, String actionId) throws PortalException {

    _log.debug("    ... " + actionId + " right on resource team " + userGroupId);

    PermissionChecker permissionChecker = getPermissionChecker();

    if (!permissionChecker.isOmniadmin() && permissionChecker.isSignedIn()) {

        UserGroupPermissionUtil.check(getPermissionChecker(), userGroupId, actionId);

    } else if (!permissionChecker.isSignedIn()) {

        throw new PrincipalException.MustBeAuthenticated(this.getGuestOrUserId());

    }//from  w  w  w.  java 2  s .c  o m
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularUserServiceImpl.java

License:Open Source License

protected User deleteUser(User user, User existingUser) throws PortalException {

    _log.debug("Target user: " + existingUser.toString());
    try {/*w  ww  .  j a  va 2  s.c  om*/

        // Check if target user is not an omni admin or a company admin
        PermissionChecker deleteUserPermChecker = PermissionCheckerFactoryUtil.create(existingUser);
        if (deleteUserPermChecker != null && !deleteUserPermChecker.isOmniadmin()
                && !deleteUserPermChecker.isCompanyAdmin()) {
            ServicePermissionUtil.checkAllPersonalPermissions(user, ActionKeys.DELETE,
                    existingUser.getCompanyId(), getPermissionChecker(), User.class.getName());

            boolean workflowEnabled = WorkflowThreadLocal.isEnabled();

            try {

                User deletedUser = UserLocalServiceUtil.deleteUser(existingUser);
                return deletedUser;

            } catch (PortalException e) {
                _log.error("Cannot delete user ... ");
                _log.error(e);
                throw e;
            } finally {
                WorkflowThreadLocal.setEnabled(workflowEnabled);
            }
        } else {
            _log.error("User is omni admin or company admin and cannot be deleted!");
            throw new PortalException();
        }

    } catch (Exception e) {
        throw new PortalException(e);
    }
}