Search in sources :

Example 1 with RolesPermissionsActionForm

use of org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm in project head by mifos.

the class RolesPermissionsAction method manage.

@TransactionDemarcate(joinToken = true)
public ActionForward manage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    RolesPermissionsActionForm rolesPermissionsActionForm = (RolesPermissionsActionForm) form;
    SessionUtils.setCollectionAttribute(RolesAndPermissionConstants.ACTIVITYLIST, ((RolesPermissionsBusinessService) getService()).getActivities(), request);
    Short roleId = Short.valueOf(rolesPermissionsActionForm.getId());
    RoleBO role = ((RolesPermissionsBusinessService) getService()).getRole(roleId);
    List<ActivityRestrictionDto> activityRestrictionDtoList = rolesPermissionServiceFacade.getRoleActivitiesRestrictions(roleId);
    Map<Short, ActivityRestrictionDto> activityRestrictionDtoMap = new HashMap<Short, ActivityRestrictionDto>();
    for (ActivityRestrictionDto activityRestrictionDto : activityRestrictionDtoList) {
        activityRestrictionDtoMap.put(activityRestrictionDto.getActivityRestrictionTypeId(), activityRestrictionDto);
    }
    rolesPermissionsActionForm.setActivityRestrictionDtoMap(activityRestrictionDtoMap);
    rolesPermissionsActionForm.setName(role.getName());
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, role, request);
    return mapping.findForward(ActionForwards.manage_success.toString());
}
Also used : RolesPermissionsBusinessService(org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService) HashMap(java.util.HashMap) RolesPermissionsActionForm(org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm) ActivityRestrictionDto(org.mifos.dto.domain.ActivityRestrictionDto) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with RolesPermissionsActionForm

use of org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm in project head by mifos.

the class RolesPermissionsAction method update.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    RolesPermissionsActionForm rolesPermissionsActionForm = (RolesPermissionsActionForm) form;
    UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    List<ActivityEntity> activities = (List<ActivityEntity>) SessionUtils.getAttribute(RolesAndPermissionConstants.ACTIVITYLIST, request);
    rolesPermissionServiceFacade.updateRole(Short.parseShort(rolesPermissionsActionForm.getId()), userContext.getId(), rolesPermissionsActionForm.getName(), getActivityIds(getActivities(activities, rolesPermissionsActionForm.getActivities())), rolesPermissionsActionForm.getActivityRestrictionDtoToPersistList());
    // MIFOS-3530: update all currently logged users
    for (String loggedUser : getLoggedUsers(request)) {
        this.authenticationAuthorizationServiceFacade.reloadUserDetailsForSecurityContext(loggedUser);
    }
    return mapping.findForward(ActionForwards.update_success.toString());
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) UserContext(org.mifos.security.util.UserContext) RolesPermissionsActionForm(org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm) ArrayList(java.util.ArrayList) List(java.util.List) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 3 with RolesPermissionsActionForm

use of org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm in project head by mifos.

the class RolesPermissionsAction method create.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    List<ActivityEntity> activities = (List<ActivityEntity>) SessionUtils.getAttribute(RolesAndPermissionConstants.ACTIVITYLIST, request);
    RolesPermissionsActionForm rolesPermissionsActionForm = (RolesPermissionsActionForm) form;
    rolesPermissionServiceFacade.createRole(userContext.getId(), rolesPermissionsActionForm.getName(), getActivityIds(getActivities(activities, rolesPermissionsActionForm.getActivities())), rolesPermissionsActionForm.getActivityRestrictionDtoToPersistList());
    return mapping.findForward(ActionForwards.create_success.toString());
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) UserContext(org.mifos.security.util.UserContext) RolesPermissionsActionForm(org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm) ArrayList(java.util.ArrayList) List(java.util.List) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 4 with RolesPermissionsActionForm

use of org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm in project head by mifos.

the class RolesPermissionsAction method preview.

@TransactionDemarcate(joinToken = true)
public ActionForward preview(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    RolesPermissionsActionForm rolesPermissionsActionForm = (RolesPermissionsActionForm) form;
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, ((RolesPermissionsBusinessService) getService()).getRole(Short.valueOf(rolesPermissionsActionForm.getId())), request);
    return mapping.findForward(ActionForwards.preview_success.toString());
}
Also used : RolesPermissionsActionForm(org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 5 with RolesPermissionsActionForm

use of org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm in project head by mifos.

the class ActivityTag method doEndTag.

@SuppressWarnings("unchecked")
@Override
public int doEndTag() throws JspException {
    RoleTempleteBuilder builder = new RoleTempleteBuilder();
    List<ActivityEntity> activities;
    try {
        activities = (List<ActivityEntity>) SessionUtils.getAttribute(RolesAndPermissionConstants.ACTIVITYLIST, (HttpServletRequest) pageContext.getRequest());
        activities = filterActivities(activities);
        RoleBO role = (RoleBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, (HttpServletRequest) pageContext.getRequest());
        RolesPermissionsActionForm rolesPermissionsActionForm = (RolesPermissionsActionForm) pageContext.getSession().getAttribute("rolesPermissionsActionForm");
        if (rolesPermissionsActionForm != null && rolesPermissionsActionForm.getActivities().size() > 0) {
            List<ActivityEntity> flitered = filterActivities(getActivities(activities, rolesPermissionsActionForm.getActivities()));
            Set<Short> activitySet = convertToIdSet(flitered);
            builder.setCurrentActivites(activitySet);
        } else if (role != null) {
            List<ActivityEntity> flitered = filterActivities(new ArrayList<ActivityEntity>(role.getActivities()));
            Set<Short> activitySet = convertToIdSet(flitered);
            builder.setCurrentActivites(activitySet);
        }
        Map<Short, ActivityRestrictionDto> activityRestrictionDtoMap = rolesPermissionsActionForm.getActivityRestrictionDtoMap();
        if (activityRestrictionDtoMap == null) {
            activityRestrictionDtoMap = new HashMap<Short, ActivityRestrictionDto>();
        }
        builder.setActivityRestrictionDtoMap(activityRestrictionDtoMap);
        SessionUtils.getAttribute(Constants.BUSINESS_KEY, (HttpServletRequest) pageContext.getRequest());
        StringBuilder sb = builder.getRolesTemplete(activities);
        pageContext.getOut().print(sb.toString());
    } catch (IOException e) {
        throw new JspException(e);
    } catch (PageExpiredException e1) {
        throw new JspException(e1);
    }
    return EVAL_PAGE;
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) Set(java.util.Set) HashSet(java.util.HashSet) RolesPermissionsActionForm(org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm) ArrayList(java.util.ArrayList) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) RoleTempleteBuilder(org.mifos.security.rolesandpermission.util.helpers.RoleTempleteBuilder) JspException(javax.servlet.jsp.JspException) ArrayList(java.util.ArrayList) List(java.util.List) ActivityRestrictionDto(org.mifos.dto.domain.ActivityRestrictionDto) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO)

Aggregations

RolesPermissionsActionForm (org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm)5 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)3 ActivityRestrictionDto (org.mifos.dto.domain.ActivityRestrictionDto)2 RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)2 UserContext (org.mifos.security.util.UserContext)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 JspException (javax.servlet.jsp.JspException)1 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)1 RolesPermissionsBusinessService (org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService)1 RoleTempleteBuilder (org.mifos.security.rolesandpermission.util.helpers.RoleTempleteBuilder)1