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 @SuppressWarnings("unused")
030 public boolean isRoleAllowed(long userId, long roleId)
031 throws PortalException, SystemException {
032
033 try {
034 checkRoles(new long[] {userId}, new long[] {roleId}, null);
035 }
036 catch (Exception e) {
037 return false;
038 }
039
040 return true;
041 }
042
043 @SuppressWarnings("unused")
044 public boolean isRoleRequired(long userId, long roleId)
045 throws PortalException, SystemException {
046
047 try {
048 checkRoles(new long[] {userId}, null, new long[] {roleId});
049 }
050 catch (Exception e) {
051 return true;
052 }
053
054 return false;
055 }
056
057 public void verifyPolicy() throws PortalException, SystemException {
058 ActionableDynamicQuery actionableDynamicQuery =
059 new RoleActionableDynamicQuery() {
060
061 @Override
062 protected void performAction(Object object)
063 throws PortalException, SystemException {
064
065 Role role = (Role)object;
066
067 verifyPolicy(role);
068 }
069
070 };
071
072 actionableDynamicQuery.performActions();
073 }
074
075 public void verifyPolicy(Role role)
076 throws PortalException, SystemException {
077
078 verifyPolicy(role, null, null);
079 }
080
081 }