001
014
015 package com.liferay.portal.security.membershippolicy;
016
017 import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
018 import com.liferay.portal.kernel.exception.PortalException;
019 import com.liferay.portal.kernel.exception.SystemException;
020 import com.liferay.portal.model.Role;
021 import com.liferay.portal.service.persistence.RoleActionableDynamicQuery;
022
023
027 public abstract class BaseRoleMembershipPolicy implements RoleMembershipPolicy {
028
029 @Override
030 @SuppressWarnings("unused")
031 public boolean isRoleAllowed(long userId, long roleId)
032 throws PortalException, SystemException {
033
034 try {
035 checkRoles(new long[] {userId}, new long[] {roleId}, null);
036 }
037 catch (Exception e) {
038 return false;
039 }
040
041 return true;
042 }
043
044 @Override
045 @SuppressWarnings("unused")
046 public boolean isRoleRequired(long userId, long roleId)
047 throws PortalException, SystemException {
048
049 try {
050 checkRoles(new long[] {userId}, null, new long[] {roleId});
051 }
052 catch (Exception e) {
053 return true;
054 }
055
056 return false;
057 }
058
059 @Override
060 public void verifyPolicy() throws PortalException, SystemException {
061 ActionableDynamicQuery actionableDynamicQuery =
062 new RoleActionableDynamicQuery() {
063
064 @Override
065 protected void performAction(Object object)
066 throws PortalException, SystemException {
067
068 Role role = (Role)object;
069
070 verifyPolicy(role);
071 }
072
073 };
074
075 actionableDynamicQuery.performActions();
076 }
077
078 @Override
079 public void verifyPolicy(Role role)
080 throws PortalException, SystemException {
081
082 verifyPolicy(role, null, null);
083 }
084
085 }