use of com.liferay.portal.security.permission.PermissionChecker in project liferay-ide by liferay.
the class WebServerServlet method service.
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
User user = null;
try {
user = _getUser(request);
PrincipalThreadLocal.setName(user.getUserId());
PrincipalThreadLocal.setPassword(PortalUtil.getUserPassword(request));
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, true);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
if (_lastModified) {
long lastModified = getLastModified(request);
if (lastModified > 0) {
long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
if ((ifModifiedSince > 0) && (ifModifiedSince == lastModified)) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
}
if (lastModified > 0) {
response.setDateHeader(HttpHeaders.LAST_MODIFIED, lastModified);
}
}
String path = HttpUtil.fixPath(request.getPathInfo());
String[] pathArray = StringUtil.split(path, CharPool.SLASH);
if (pathArray.length == 0) {
sendGroups(response, user, request.getServletPath() + StringPool.SLASH + path);
} else {
if (_PATH_DDL.equals(pathArray[0])) {
sendDDLRecordFile(request, response, pathArray);
} else if (Validator.isNumber(pathArray[0])) {
sendFile(request, response, user, pathArray);
} else {
if (isLegacyImageGalleryImageId(request, response)) {
return;
}
Image image = getImage(request, true);
if (image != null) {
writeImage(image, request, response);
} else {
sendDocumentLibrary(request, response, user, request.getServletPath() + StringPool.SLASH + path, pathArray);
}
}
}
} catch (NoSuchFileEntryException nsfee) {
PortalUtil.sendError(HttpServletResponse.SC_NOT_FOUND, nsfee, request, response);
} catch (PrincipalException pe) {
processPrincipalException(pe, user, request, response);
} catch (Exception e) {
PortalUtil.sendError(e, request, response);
}
}
use of com.liferay.portal.security.permission.PermissionChecker in project liferay-ide by liferay.
the class MeetupsPortlet method deleteMeetupsEntry.
public void deleteMeetupsEntry(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
if (!permissionChecker.isCompanyAdmin()) {
return;
}
long meetupsEntryId = ParamUtil.getLong(actionRequest, "meetupsEntryId");
MeetupsEntryLocalServiceUtil.deleteMeetupsEntry(meetupsEntryId);
}
use of com.liferay.portal.security.permission.PermissionChecker in project liferay-ide by liferay.
the class EditorPortlet method updateGadget.
@Override
public void updateGadget(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
long groupId = themeDisplay.getScopeGroupId();
String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
if (cmd.equals(Constants.ADD)) {
GadgetPermission.check(permissionChecker, groupId, ActionKeys.PUBLISH_GADGET);
Gadget gadget = doAddGadget(actionRequest, actionResponse);
String publishGadgetRedirect = ParamUtil.getString(actionRequest, "publishGadgetRedirect");
boolean unpublishPermission = GadgetPermission.contains(permissionChecker, groupId, gadget.getGadgetId(), ActionKeys.DELETE);
publishGadgetRedirect = HttpUtil.addParameter(publishGadgetRedirect, "unpublishPermission", unpublishPermission);
publishGadgetRedirect = HttpUtil.addParameter(publishGadgetRedirect, "gadgetId", gadget.getGadgetId());
actionResponse.sendRedirect(publishGadgetRedirect);
} else {
long gadgetId = ParamUtil.getLong(actionRequest, "gadgetId");
GadgetPermission.check(permissionChecker, groupId, gadgetId, ActionKeys.UPDATE);
doUpdateGadget(actionRequest, actionResponse);
}
}
use of com.liferay.portal.security.permission.PermissionChecker in project liferay-ide by liferay.
the class EditorPortlet method serveGetFolderChildren.
protected void serveGetFolderChildren(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
long repositoryId = ParamUtil.getLong(resourceRequest, "repositoryId");
long folderId = ParamUtil.getLong(resourceRequest, "folderId");
List<Folder> folders = DLAppServiceUtil.getFolders(repositoryId, folderId);
folders = ListUtil.sort(folders, new RepositoryModelNameComparator(true));
JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
for (Folder folder : folders) {
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
jsonObject.put("entryId", folder.getFolderId());
jsonObject.put("label", folder.getName());
jsonObject.put("leaf", false);
jsonObject.put("type", "editor");
jsonArray.put(jsonObject);
}
boolean getFileEntries = ParamUtil.getBoolean(resourceRequest, "getFileEntries");
if (getFileEntries) {
PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
List<FileEntry> fileEntries = DLAppServiceUtil.getFileEntries(repositoryId, folderId);
fileEntries = ListUtil.sort(fileEntries, new RepositoryModelNameComparator(true));
for (FileEntry fileEntry : fileEntries) {
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
jsonObject.put("entryId", fileEntry.getFileEntryId());
String portalURL = PortalUtil.getPortalURL(themeDisplay);
String fileEntryURL = ShindigUtil.getFileEntryURL(portalURL, fileEntry.getFileEntryId());
jsonObject.put("fileEntryURL", fileEntryURL);
long gadgetId = 0;
try {
Gadget gadget = GadgetLocalServiceUtil.getGadget(themeDisplay.getCompanyId(), fileEntryURL);
gadgetId = gadget.getGadgetId();
} catch (Exception e) {
}
jsonObject.put("gadgetId", gadgetId);
jsonObject.put("label", fileEntry.getTitle());
jsonObject.put("leaf", true);
JSONObject jsonPermissions = JSONFactoryUtil.createJSONObject();
if (gadgetId > 0) {
boolean unpublishPermission = GadgetPermission.contains(permissionChecker, themeDisplay.getScopeGroupId(), gadgetId, ActionKeys.DELETE);
jsonPermissions.put("unpublishPermission", unpublishPermission);
}
jsonObject.put("permissions", jsonPermissions);
jsonObject.put("type", "editor");
jsonArray.put(jsonObject);
}
}
writeJSON(resourceRequest, resourceResponse, jsonArray);
}
use of com.liferay.portal.security.permission.PermissionChecker in project liferay-ide by liferay.
the class SearchPermissionCheckerImpl method doGetPermissionQuery.
protected Query doGetPermissionQuery(long companyId, long[] groupIds, long userId, String className, Query query, SearchContext searchContext) throws Exception {
Indexer indexer = IndexerRegistryUtil.getIndexer(className);
if (!indexer.isPermissionAware()) {
return query;
}
PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();
AdvancedPermissionChecker advancedPermissionChecker = null;
if ((permissionChecker != null) && (permissionChecker instanceof AdvancedPermissionChecker)) {
advancedPermissionChecker = (AdvancedPermissionChecker) permissionChecker;
}
if (advancedPermissionChecker == null) {
return query;
}
PermissionCheckerBag permissionCheckerBag = getPermissionCheckerBag(advancedPermissionChecker, userId);
if (permissionCheckerBag == null) {
return query;
}
List<Group> groups = new UniqueList<Group>();
List<Role> roles = new UniqueList<Role>();
List<UserGroupRole> userGroupRoles = new UniqueList<UserGroupRole>();
Map<Long, List<Role>> groupIdsToRoles = new HashMap<Long, List<Role>>();
roles.addAll(permissionCheckerBag.getRoles());
if (ArrayUtil.isEmpty(groupIds)) {
groups.addAll(GroupLocalServiceUtil.getUserGroups(userId, true));
groups.addAll(permissionCheckerBag.getGroups());
userGroupRoles = UserGroupRoleLocalServiceUtil.getUserGroupRoles(userId);
} else {
groups.addAll(permissionCheckerBag.getGroups());
for (long groupId : groupIds) {
if (GroupLocalServiceUtil.hasUserGroup(userId, groupId)) {
Group group = GroupLocalServiceUtil.getGroup(groupId);
groups.add(group);
}
userGroupRoles.addAll(UserGroupRoleLocalServiceUtil.getUserGroupRoles(userId, groupId));
userGroupRoles.addAll(UserGroupRoleLocalServiceUtil.getUserGroupRolesByUserUserGroupAndGroup(userId, groupId));
}
}
if (advancedPermissionChecker.isSignedIn()) {
roles.add(RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST));
}
for (Group group : groups) {
PermissionCheckerBag userBag = advancedPermissionChecker.getUserBag(userId, group.getGroupId());
List<Role> groupRoles = userBag.getRoles();
groupIdsToRoles.put(group.getGroupId(), groupRoles);
roles.addAll(groupRoles);
}
return doGetPermissionQuery_6(companyId, groupIds, userId, className, query, searchContext, advancedPermissionChecker, groups, roles, userGroupRoles, groupIdsToRoles);
}
Aggregations