Java tutorial
/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.message.boards.service.impl; import com.liferay.message.boards.model.MBBan; import com.liferay.message.boards.service.base.MBBanServiceBaseImpl; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.model.User; import com.liferay.portal.kernel.security.auth.PrincipalException; import com.liferay.portal.kernel.security.permission.ActionKeys; import com.liferay.portal.kernel.security.permission.PermissionChecker; import com.liferay.portal.kernel.service.ServiceContext; import com.liferay.portal.kernel.service.UserLocalService; import com.liferay.portal.kernel.util.Portal; import com.liferay.portal.spring.extender.service.ServiceReference; import com.liferay.portlet.messageboards.service.permission.MBPermission; /** * @author Brian Wing Shun Chan */ public class MBBanServiceImpl extends MBBanServiceBaseImpl { @Override public MBBan addBan(long banUserId, ServiceContext serviceContext) throws PortalException { PermissionChecker permissionChecker = getPermissionChecker(); MBPermission.check(permissionChecker, serviceContext.getScopeGroupId(), ActionKeys.BAN_USER); User banUser = _userLocalService.getUser(banUserId); boolean groupAdmin = false; try { groupAdmin = _portal.isGroupAdmin(banUser, serviceContext.getScopeGroupId()); } catch (Exception e) { throw new SystemException(e); } if (groupAdmin) { throw new PrincipalException(); } return mbBanLocalService.addBan(getUserId(), banUserId, serviceContext); } @Override public void deleteBan(long banUserId, ServiceContext serviceContext) throws PortalException { MBPermission.check(getPermissionChecker(), serviceContext.getScopeGroupId(), ActionKeys.BAN_USER); mbBanLocalService.deleteBan(banUserId, serviceContext); } @ServiceReference(type = Portal.class) private Portal _portal; @ServiceReference(type = UserLocalService.class) private UserLocalService _userLocalService; }