use of org.mifos.security.rolesandpermission.exceptions.RolesPermissionException in project head by mifos.
the class RolesPermissionServiceFacadeWebTier method hasUserAccessForActivity.
@Override
public boolean hasUserAccessForActivity(Short activityID) throws Exception {
boolean result = false;
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
try {
for (Short roleId : mifosUser.getRoleIds()) {
RoleBO role = legacyRolesPermissionsDao.getRole(roleId);
if (role.getActivityIds().contains(activityID) || null == activityID) {
result = true;
break;
}
}
} catch (PersistenceException e) {
throw new RolesPermissionException(e);
}
return result;
}
use of org.mifos.security.rolesandpermission.exceptions.RolesPermissionException in project head by mifos.
the class RolesPermissionServiceFacadeWebTier method updateRole.
@Override
public void updateRole(Short roleId, Short userId, String name, List<Short> ActivityIds) throws Exception {
RolesPermissionsBusinessService rolesPermissionsBusinessService = new RolesPermissionsBusinessService();
RoleBO role = rolesPermissionsBusinessService.getRole(roleId);
List<ActivityEntity> activityList = getActivityEntities(ActivityIds);
validateRole(name, activityList, role);
try {
StaticHibernateUtil.startTransaction();
role.update(userId, name, activityList);
legacyRolesPermissionsDao.save(role);
StaticHibernateUtil.flushSession();
for (ActivityEntity ae : legacyRolesPermissionsDao.getActivities()) {
StaticHibernateUtil.getSessionTL().refresh(ae);
}
StaticHibernateUtil.commitTransaction();
} catch (RolesPermissionException e) {
StaticHibernateUtil.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
StaticHibernateUtil.closeSession();
}
}
use of org.mifos.security.rolesandpermission.exceptions.RolesPermissionException in project head by mifos.
the class RolesPermissionServiceFacadeWebTier method updateRole.
@Override
public void updateRole(Short roleId, Short userId, String name, List<Short> ActivityIds, List<ActivityRestrictionDto> activityRestrictionDtoList) throws Exception {
RolesPermissionsBusinessService rolesPermissionsBusinessService = new RolesPermissionsBusinessService();
RoleBO role = rolesPermissionsBusinessService.getRole(roleId);
List<ActivityEntity> activityList = getActivityEntities(ActivityIds);
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
List<RoleActivityRestrictionBO> activitiesRestrictions = getActivitiesRestrictionsForUpdate(userContext, activityRestrictionDtoList);
validateRole(name, activityList, role);
try {
StaticHibernateUtil.startTransaction();
role.updateWithActivitiesRestrictions(userId, name, activityList, activitiesRestrictions);
legacyRolesPermissionsDao.save(role);
StaticHibernateUtil.flushSession();
for (ActivityEntity ae : legacyRolesPermissionsDao.getActivities()) {
StaticHibernateUtil.getSessionTL().refresh(ae);
}
StaticHibernateUtil.commitTransaction();
} catch (RolesPermissionException e) {
StaticHibernateUtil.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
StaticHibernateUtil.closeSession();
}
}
Aggregations