Package org.beangle.ems.security.restrict

Examples of org.beangle.ems.security.restrict.Restriction


    RestrictionHolder<?> userHolder = user;
    restrictions.addAll(userHolder.getRestrictions());
    // 实体过滤
    return (List<Restriction>) CollectionUtils.select(restrictions, new Predicate() {
      public boolean evaluate(Object obj) {
        Restriction restriciton = (Restriction) obj;
        if (restriciton.isEnabled() && entities.contains(restriciton.getPattern().getEntity())) return true;
        else return false;
      }
    });
  }
View Full Code Here


  /**
   * 删除数据限制权限
   */
  public String remove() {
    Restriction restriction = getRestriction();
    RestrictionHolder<Restriction> holer = new RestrictionHelper(entityDao).getHolder();
    holer.getRestrictions().remove(restriction);
    entityDao.remove(restriction);
    entityDao.saveOrUpdate(holer);
    return redirect("info", "info.remove.success");
View Full Code Here

    helper.populateInfo(helper.getHolder());
    return forward();
  }

  public String save() {
    Restriction restriction = getRestriction();
    RestrictionHolder<Restriction> holder = new RestrictionHelper(entityDao).getHolder();
    List<Restriction> myRestrictions = getMyRestrictions(restriction.getPattern(), holder);
    Set<RestrictField> ignoreFields = getIgnoreFields(myRestrictions);
    boolean isAdmin = isAdmin();
    for (final RestrictField field : restriction.getPattern().getEntity().getFields()) {
      String[] values = (String[]) getAll(field.getName());
      if ((ignoreFields.contains(field) || isAdmin) && getBool("ignoreField" + field.getId())) {
        restriction.setItem(field, "*");
      } else {
        if (null == values || values.length == 0) {
          restriction.getItems().remove(field.getId());
        } else {
          String storedValue = null;
          if (null != field.getKeyName()) {
            final Set<String> keys = CollectUtils.newHashSet(values);
            Collection<?> allValues = restrictionService.getFieldValues(field.getName());
            allValues = CollectionUtils.select(allValues, new Predicate() {
              public boolean evaluate(Object arg0) {
                try {
                  String keyValue = String.valueOf(PropertyUtils.getProperty(arg0,
                      field.getKeyName()));
                  return keys.contains(keyValue);
                } catch (Exception e) {
                  e.printStackTrace();
                }
                return false;
              }
            });
            storedValue = idDataResolver.marshal(field, allValues);
          } else {
            storedValue = StrUtils.join(values);
          }
          restriction.setItem(field, storedValue);
        }
      }
    }
    if (restriction.getItems().isEmpty()) {
      holder.getRestrictions().remove(restriction);
      if (restriction.isPersisted()) entityDao.remove(restriction);
      entityDao.saveOrUpdate(holder);
      return redirect("info", "info.save.success");
    } else {
      if (!restriction.isPersisted()) {
        holder.getRestrictions().add(restriction);
        entityDao.saveOrUpdate(holder);
      } else {
        entityDao.saveOrUpdate(
            (String) RestrictionHelper.restrictionTypeMap.get(get("restrictionType")),
View Full Code Here

  /**
   * 编辑权限<br>
   */
  public String edit() {
    // 取得各参数的值
    Restriction restriction = getRestriction();
    boolean isAdmin = isAdmin();
    Map<String, Object> mngFields = CollectUtils.newHashMap();
    Map<String, Object> aoFields = CollectUtils.newHashMap();
    List<Restriction> myRestricitons = getMyRestrictions(restriction.getPattern(),
        restriction.getHolder());
    Set<RestrictField> ignores = getIgnoreFields(myRestricitons);
    put("ignoreFields", ignores);
    Set<RestrictField> holderIgnoreFields = CollectUtils.newHashSet();
    put("holderIgnoreFields", holderIgnoreFields);
    for (RestrictField field : restriction.getPattern().getEntity().getFields()) {
      List<?> mngField = restrictionService.getFieldValues(field.getName());
      if (!isAdmin) {
        mngField.retainAll(getMyRestrictionValues(myRestricitons, field.getName()));
      } else {
        ignores.add(field);
      }
      String fieldValue = restriction.getItem(field);
      if ("*".equals(fieldValue)) {
        holderIgnoreFields.add(field);
      }
      mngFields.put(field.getName(), mngField);
      if (null == field.getSource()) {
View Full Code Here

    return values;
  }

  private Restriction getRestriction() {
    Long restrictionId = getLong("restriction.id");
    Restriction restriction = null;
    String entityName = (String) RestrictionHelper.restrictionTypeMap.get(get("restrictionType"));
    if (null == restrictionId) {
      restriction = (Restriction) Model.getEntityType(entityName).newInstance();
    } else {
      restriction = (Restriction) entityDao.get(entityName, restrictionId);
    }
    populate(Params.sub("restriction"), restriction, entityName);
    if (null == restrictionId) {
      restriction.setPattern((RestrictPattern) entityDao.get(RestrictPattern.class, restriction
          .getPattern().getId()));
    }
    return restriction;
  }
View Full Code Here

TOP

Related Classes of org.beangle.ems.security.restrict.Restriction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.