Search in sources :

Example 1 with RolesPermissionException

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;
}
Also used : PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosUser(org.mifos.security.MifosUser) RolesPermissionException(org.mifos.security.rolesandpermission.exceptions.RolesPermissionException) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO)

Example 2 with RolesPermissionException

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();
    }
}
Also used : RolesPermissionsBusinessService(org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) RolesPermissionException(org.mifos.security.rolesandpermission.exceptions.RolesPermissionException) ActivityGeneratorException(org.mifos.security.activity.ActivityGeneratorException) ServiceException(org.mifos.framework.exceptions.ServiceException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) RolesPermissionException(org.mifos.security.rolesandpermission.exceptions.RolesPermissionException) HibernateException(org.hibernate.HibernateException) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 3 with RolesPermissionException

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();
    }
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) ActivityGeneratorException(org.mifos.security.activity.ActivityGeneratorException) ServiceException(org.mifos.framework.exceptions.ServiceException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) RolesPermissionException(org.mifos.security.rolesandpermission.exceptions.RolesPermissionException) HibernateException(org.hibernate.HibernateException) RolesPermissionsBusinessService(org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService) BusinessRuleException(org.mifos.service.BusinessRuleException) RolesPermissionException(org.mifos.security.rolesandpermission.exceptions.RolesPermissionException) RoleActivityRestrictionBO(org.mifos.security.rolesandpermission.business.RoleActivityRestrictionBO) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

PersistenceException (org.mifos.framework.exceptions.PersistenceException)3 RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)3 RolesPermissionException (org.mifos.security.rolesandpermission.exceptions.RolesPermissionException)3 HibernateException (org.hibernate.HibernateException)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 ServiceException (org.mifos.framework.exceptions.ServiceException)2 MifosUser (org.mifos.security.MifosUser)2 ActivityGeneratorException (org.mifos.security.activity.ActivityGeneratorException)2 ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)2 RolesPermissionsBusinessService (org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)1 RoleActivityRestrictionBO (org.mifos.security.rolesandpermission.business.RoleActivityRestrictionBO)1 UserContext (org.mifos.security.util.UserContext)1