@Override
  public boolean equals(Object other) {

    if (this == other) {
      return true;
    }
    if (other == null || !(other instanceof PropertyDiffDisplay)) {
      return false;
    }
    Serializable otherValue = ((PropertyDiffDisplay) other).getValue();
    Serializable otherStyleClass = ((PropertyDiffDisplay) other).getStyleClass();
    DifferenceType otherDifferenceType = ((PropertyDiffDisplay) other).getDifferenceType();
    if (value == null
        && otherValue == null
        && styleClass == null
        && otherStyleClass == null
        && differenceType.equals(otherDifferenceType)) {
      return true;
    }
    return differenceType.equals(otherDifferenceType)
        && (value == null
                && otherValue == null
                && styleClass != null
                && styleClass.equals(otherStyleClass)
            || styleClass == null
                && otherStyleClass == null
                && value != null
                && value.equals(otherValue)
            || value != null
                && value.equals(otherValue)
                && styleClass != null
                && styleClass.equals(otherStyleClass));
  }
 @Override
 public Serializable getCurrentFromResultSet(
     ResultSet rs, List<Column> columns, Model model, Serializable[] returnId, int[] returnPos)
     throws SQLException {
   Serializable id = null;
   Serializable value = null;
   int i = 0;
   for (Column column : columns) {
     i++;
     String key = column.getKey();
     Serializable v = column.getFromResultSet(rs, i);
     if (key.equals(model.MAIN_KEY)) {
       id = v;
     } else if (key.equals(model.COLL_TABLE_POS_KEY)) {
       // (the pos column is ignored, results are already ordered by id
       // then pos)
     } else if (key.equals(model.COLL_TABLE_VALUE_KEY)) {
       value = v;
     } else {
       throw new RuntimeException(key);
     }
   }
   Serializable prevId = returnId[0];
   returnId[0] = id;
   int pos = (id != null && !id.equals(prevId)) ? 0 : returnPos[0] + 1;
   returnPos[0] = pos;
   return value;
 }
Example #3
0
  public void testUidGeneration() {
    Serializable id = this.uidGenerator.generateUid();
    assertNotNull(id);

    Serializable id2 = this.uidGenerator.generateUid();
    assertNotNull(id2);

    assertFalse(id.equals(id2));
  }
Example #4
0
 @Override
 public boolean equals(final Object obj) {
   if (this == obj) {
     return true;
   }
   if (!(obj instanceof SerializableData)) {
     return false;
   }
   final SerializableData other = (SerializableData) obj;
   return (raw == null ? other.raw == null : raw.equals(other.raw))
       && Arrays.equals(serialized, other.serialized);
 }
Example #5
0
  public boolean equals(final Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    final InstanceImpl instance = (InstanceImpl) o;

    if (Double.compare(instance.weight, weight) != 0) return false;
    if (!attributes.equals(instance.attributes)) return false;
    if (!label.equals(instance.label)) return false;

    return true;
  }
Example #6
0
  /**
   * 记录一条日志【登陆,逻辑,异常】
   *
   * @param logText
   * @param classStr
   * @param exceptions
   * @author 朱启亮
   * @date 2008-1-31
   */
  public void saveLog(JoinPoint jp, String logText, String classStr, Exception... exceptions) {
    Object obj = jp.getThis();
    String ip = "unknow";
    if (obj instanceof AbstractAction) {
      AbstractAction action = (AbstractAction) obj;
      HttpServletRequest request = action.getRequest();
      ip = this.getIpAddr(request);
    }

    HttpSession session = (HttpSession) UserSession.get(Constants.THREADLOCAL_CURRENT_SESSION);
    Serializable personid = (Serializable) session.getAttribute(Constants.SESSION_CURRENT_PERSONID);
    Person person = null;
    // 区分游客,root用户,普通用户
    if (personid == null) {
      person = new Person();
      person.setUserName(Constants.GUEST_NAME);
      person.setId(Constants.GUEST_ID);
      person.setUserLoginName(Constants.GUEST_NAME);
    } else if (personid.equals(Constants.ADMINISTRATOR_ID)) {
      person = new Person();
      person.setUserName(Constants.ADMINISTRATOR_NAME);
      person.setId(Constants.ADMINISTRATOR_ID);
      person.setUserLoginName(Constants.ADMINISTRATOR_ACCOUNT);
    } else {
      PersonManager personManager = this.getPersonManager();
      person = personManager.get(personid);
    }
    StringUtil.isoToUTF8(logText);
    Log log = new Log();
    log.setIp(ip);
    log.setLog(logText);
    log.setDt(new Date());
    // 记录日志的类型
    if (exceptions.length == 0) {
      //			if(classStr.equals(Constants.LOGINACTION)){
      //				log.setType(Log.LOG_TYPE_LOGIN);
      //			}else{
      log.setType(Log.LOG_TYPE_LOGIC);
      //			}
    } else {
      log.setType(Log.LOG_TYPE_EXCEPTION);
    }
    log.setPersonName(person.getUserName());
    if (person.getUserName().equals(Constants.GUEST_NAME)
        || person.getUserName().equals(Constants.ADMINISTRATOR_NAME)) {
      log.setPersonLoginName(person.getUserLoginName());
    } else {
      log.setPersonLoginName(person.getUserLoginName());
    }
    logManager.save(log);
  }
  private void evictCache(
      Object entity, EntityPersister persister, EventSource session, Object[] oldState) {
    try {
      SessionFactoryImplementor factory = persister.getFactory();

      Set<String> collectionRoles =
          factory.getCollectionRolesByEntityParticipant(persister.getEntityName());
      if (collectionRoles == null || collectionRoles.isEmpty()) {
        return;
      }
      for (String role : collectionRoles) {
        CollectionPersister collectionPersister = factory.getCollectionPersister(role);
        if (!collectionPersister.hasCache()) {
          // ignore collection if no caching is used
          continue;
        }
        // this is the property this OneToMany relation is mapped by
        String mappedBy = collectionPersister.getMappedByProperty();
        if (mappedBy != null) {
          int i = persister.getEntityMetamodel().getPropertyIndex(mappedBy);
          Serializable oldId = null;
          if (oldState != null) {
            // in case of updating an entity we perhaps have to decache 2 entity collections, this
            // is the
            // old one
            oldId = session.getIdentifier(oldState[i]);
          }
          Object ref = persister.getPropertyValue(entity, i);
          Serializable id = null;
          if (ref != null) {
            id = session.getIdentifier(ref);
          }
          // only evict if the related entity has changed
          if (id != null && !id.equals(oldId)) {
            evict(id, collectionPersister, session);
            if (oldId != null) {
              evict(oldId, collectionPersister, session);
            }
          }
        } else {
          LOG.debug("Evict CollectionRegion " + role);
          collectionPersister.getCacheAccessStrategy().evictAll();
        }
      }
    } catch (Exception e) {
      // don't let decaching influence other logic
      LOG.error("", e);
    }
  }
 /**
  * The second stage of the <code>NodeRef</code> repointing. Call this method to have any <code>
  * NodeRef</code> properties readjusted to reflect the copied node hierarchy. Only use this method
  * if it a requirement for the particular type or aspect that you are coding for.
  *
  * @param sourceNodeRef the source node
  * @param propertyQName the target node i.e. the copy of the source node
  * @param copyMap the full hierarchy copy map of source to copies
  * @see #recordNodeRefsForRepointing(NodeRef, Map, QName)
  */
 @SuppressWarnings("unchecked")
 public void repointNodeRefs(
     NodeRef sourceNodeRef,
     NodeRef targetNodeRef,
     QName propertyQName,
     Map<NodeRef, NodeRef> copyMap,
     NodeService nodeService) {
   String key = KEY_NODEREF_REPOINTING_PREFIX + propertyQName.toString();
   Map<NodeRef, Serializable> map = TransactionalResourceHelper.getMap(key);
   Serializable value = map.get(sourceNodeRef);
   if (value == null) {
     // Don't bother.  The source node did not have a NodeRef property
     return;
   }
   Serializable newValue = null;
   if (value instanceof Collection) {
     Collection<Serializable> oldList = (Collection<Serializable>) value;
     List<Serializable> newList = new ArrayList<Serializable>(oldList.size());
     for (Serializable oldListValue : oldList) {
       Serializable newListValue = oldListValue;
       if (oldListValue instanceof NodeRef) {
         newListValue = repointNodeRef(copyMap, (NodeRef) oldListValue);
       }
       // Put the value in the new list even though the new list might be discarded
       newList.add(newListValue);
       // Check if the value changed
       if (!newListValue.equals(oldListValue)) {
         // The value changed, so the new list will have to be set onto the target node
         newValue = (Serializable) newList;
       }
     }
   } else if (value instanceof NodeRef) {
     NodeRef newNodeRef = repointNodeRef(copyMap, (NodeRef) value);
     if (!newNodeRef.equals(value)) {
       // The value changed, so the new list will have to be set onto the target node
       newValue = newNodeRef;
     }
   } else {
     throw new IllegalStateException("Should only have Collections and NodeRef values");
   }
   // Fix the node property on the target, if necessary
   if (newValue != null) {
     nodeService.setProperty(targetNodeRef, propertyQName, newValue);
   }
 }
 protected void registerEntityMapping(
     final Class<?> entityClass, final Serializable oldId, final Serializable newId) {
   final Serializable registeredNewId = getNewId(entityClass, oldId);
   if (registeredNewId != null && registeredNewId.equals(newId) == false) {
     log.error(
         "Oups, double entity mapping found for entity '"
             + entityClass
             + "' with old id="
             + oldId
             + " . New id "
             + newId
             + " ignored, using previous stored id "
             + registeredNewId
             + " instead.");
   } else {
     this.entityMapping.put(getClassname4History(entityClass) + oldId, newId);
   }
 }
  @Test
  public void testKeyUniqueObject() throws Exception {
    OnHeapStore<Serializable, Serializable> store = newStore();

    List<String> key = new ArrayList<String>();
    key.add("key");
    String value = "value";

    store.put((Serializable) key, value);

    // mutate the key -- should not affect cache
    key.clear();

    Serializable storeKey = store.iterator().next().getKey();
    if (storeKey == key || !storeKey.equals(Collections.singletonList("key"))) {
      throw new AssertionError();
    }
  }
 /**
  * Returns {@code true} if the specified argument is an {@code instanceof} {@code SimpleSession}
  * and both {@link #getId() id}s are equal. If the argument is a {@code SimpleSession} and either
  * 'this' or the argument does not yet have an ID assigned, the value of {@link
  * #onEquals(SimpleSession) onEquals} is returned, which does a necessary attribute-based
  * comparison when IDs are not available.
  *
  * <p>Do your best to ensure {@code SimpleSession} instances receive an ID very early in their
  * lifecycle to avoid the more expensive attributes-based comparison.
  *
  * @param obj the object to compare with this one for equality.
  * @return {@code true} if this object is equivalent to the specified argument, {@code false}
  *     otherwise.
  */
 @Override
 public boolean equals(Object obj) {
   if (this == obj) {
     return true;
   }
   if (obj instanceof SimpleSession) {
     SimpleSession other = (SimpleSession) obj;
     Serializable thisId = getId();
     Serializable otherId = other.getId();
     if (thisId != null && otherId != null) {
       return thisId.equals(otherId);
     } else {
       // fall back to an attribute based comparison:
       return onEquals(other);
     }
   }
   return false;
 }
  /**
   * Test that validates functionality for issue <a
   * href="https://issues.apache.org/jira/browse/JSEC-22">JSEC-22</a>
   */
  @Test
  public void testSubjectReuseAfterLogout() {

    Subject subject = SecurityUtils.getSubject();

    AuthenticationToken token = new UsernamePasswordToken("guest", "guest");
    subject.login(token);
    assertTrue(subject.isAuthenticated());
    assertTrue("guest".equals(subject.getPrincipal()));
    assertTrue(subject.hasRole("guest"));

    Session session = subject.getSession();
    Serializable firstSessionId = session.getId();

    session.setAttribute("key", "value");
    assertEquals(session.getAttribute("key"), "value");

    subject.logout();

    assertNull(subject.getSession(false));
    assertNull(subject.getPrincipal());
    assertNull(subject.getPrincipals());

    subject.login(new UsernamePasswordToken("lonestarr", "vespa"));
    assertTrue(subject.isAuthenticated());
    assertTrue("lonestarr".equals(subject.getPrincipal()));
    assertTrue(subject.hasRole("goodguy"));

    assertNotNull(subject.getSession());
    assertFalse(firstSessionId.equals(subject.getSession().getId()));

    subject.logout();

    assertNull(subject.getSession(false));
    assertNull(subject.getPrincipal());
    assertNull(subject.getPrincipals());
  }
Example #13
0
  @Override
  public boolean equals(Object obj) {
    if (!(obj instanceof DataMap)) {
      return false;
    }

    DataMap other = (DataMap) obj;
    if (isEmpty() && other.isEmpty()) {
      return true;
    }

    for (Map.Entry<? extends String, ? extends Serializable> e : entrySet()) {
      Serializable value = e.getValue();
      Serializable otherValue = other.get(e.getKey());
      if (value != null) {
        if (!value.equals(otherValue)) {
          return false;
        }
      } else if (otherValue != null) {
        return false;
      }
    }
    return true;
  }
  /**
   * @param test_name Name used to refer to the serialized instance. If a test output dir is
   *     specified (see constructor), a file will be created with this name.
   */
  private boolean serializesCorrectly(Serializable obj, String test_name) {
    assert obj instanceof Externalizable : obj + " is not Externalizable";

    ObjectOutputStream oout = null;
    ObjectInputStream oin = null;
    try {
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      oout = new ObjectOutputStream(bout);

      oout.writeObject(obj);
      oout.close();

      ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
      oin = new ObjectInputStream(bin);

      Object new_obj = oin.readObject();

      if (!obj.equals(new_obj)) {
        System.err.println("Non-matching serialized objects (in-VM test):");
        System.err.println("  Original: " + obj);
        System.err.println("  Deserialized: " + new_obj);
        return false;
      }

      if (obj instanceof THash) {
        assertEquals(
            ((THash) obj).getAutoCompactionFactor(),
            ((THash) new_obj).getAutoCompactionFactor(),
            0.0);
      }

      oin.close();

      if (serialized_object_output_dir != null) {
        try {
          File file = new File(serialized_object_output_dir, test_name + ".obj");
          ObjectOutputStream test_out = new ObjectOutputStream(new FileOutputStream(file));

          test_out.writeObject(obj);

          test_out.close();
        } catch (IOException ex) {
          ex.printStackTrace();
          fail("Unable to write to test file: " + test_name);
        }
      }

      // Look for previous versions
      int version = 0;
      for (; ; version++) {
        InputStream stream =
            SerializationTest.class.getResourceAsStream(
                "old_serialized_versions/" + version + "/" + test_name + ".obj");
        if (stream == null) break;

        System.out.println("Testing " + test_name + " against version " + version + "...");

        oin = new ObjectInputStream(stream);

        new_obj = oin.readObject();

        if (!obj.equals(new_obj)) {
          System.err.println("Non-matching serialized objects (version " + version + "):");
          System.err.println("  Original: " + obj);
          System.err.println("  Deserialized: " + new_obj);
          return false;
        }
      }

      return true;
    } catch (Exception ex) {
      ex.printStackTrace();
      return false;
    } finally {
      if (oout != null) {
        try {
          oout.close();
        } catch (IOException ex) {
          // ignore
        }
      }
      if (oin != null) {
        try {
          oin.close();
        } catch (IOException ex) {
          // ignore
        }
      }
    }
  }
Example #15
0
  /** @param args */
  public static void main(final String[] args) throws Exception {
    final BufferedReader br =
        new BufferedReader(
            new InputStreamReader(
                (new GZIPInputStream(
                    new FileInputStream(
                        new File(
                            new File(System.getProperty("user.dir")), "testdata/mobo1.txt.gz"))))));

    final List<Instance> instances = Lists.newLinkedList();

    int count = 0;
    while (true) {
      count++;
      final String line = br.readLine();
      if (line == null) {
        break;
      }
      final JSONObject jo = (JSONObject) JSONValue.parse(line);
      final HashMapAttributes a = new HashMapAttributes();
      a.putAll((JSONObject) jo.get("attributes"));
      Instance instance = new Instance(a, (String) jo.get("output"));
      instances.add(instance);
    }

    final List<Instance> train = instances.subList(0, instances.size() / 2);
    final List<Instance> test = instances.subList(instances.size() / 2 + 1, instances.size() - 1);

    System.out.println("Read " + instances.size() + " instances");

    System.out.println("Testing scorers with single decision node");
    for (final Scorer scorer : Sets.newHashSet(new Scorer1())) {
      final TreeBuilder tb = new TreeBuilder(scorer);

      final long startTime = System.currentTimeMillis();
      final Node tree = tb.buildPredictiveModel(train).node;
      System.out.println(
          scorer.getClass().getSimpleName()
              + " build time "
              + (System.currentTimeMillis() - startTime)
              + ", size: "
              + tree.size()
              + " mean depth: "
              + tree.meanDepth());

      int correctlyClassified = 0;
      for (Instance testInstance : test) {
        String result = (String) tree.getLeaf(testInstance.getAttributes()).getBestClassification();
        if (result.equals(testInstance.getClassification())) {
          correctlyClassified++;
        }
      }
      System.out.println(", accuracy: " + (double) correctlyClassified / test.size());

      System.out.println("Testing random forest");

      for (int i = 2; i <= 20; i++) {
        RandomForestBuilder rfBuilder = new RandomForestBuilder(new TreeBuilder());
        RandomForest randomForest = rfBuilder.buildPredictiveModel(train);
        correctlyClassified = 0;
        for (Instance testInstance : test) {
          Serializable result =
              randomForest.getClassificationByMaxProb(testInstance.getAttributes());
          if (result.equals(testInstance.getClassification())) {
            correctlyClassified++;
          }
        }
        System.out.println(
            "accuracy with " + i + " trees: " + (double) correctlyClassified / test.size());
        // ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(new
        // File("baggedTree.ser")));
        // out.writeObject(baggedTree);
      }
    }
  }
  @Override
  protected Condition getGridSpecalCondition() {
    OrCondition orCondition = new OrCondition();
    AndCondition operateFoldersCondition = new AndCondition();
    AndCondition publicFoldersCondition = new AndCondition();
    // 状态条件
    Condition statusCondition = null;
    Condition typeCondition = null;
    // Condition userCondition = null;
    Condition authorityCondition = null;
    Condition eliminateCondition = null;
    // Condition tierCondition = null;

    // 状态
    if (status != null && status.length() > 0) {
      String[] ss = status.split(",");
      if (ss.length == 1) {
        statusCondition = new EqualsCondition("f.status_", new Integer(ss[0]));
      } else {
        statusCondition = new InCondition("f.status_", StringUtils.stringArray2IntegerArray(ss));
      }
    }
    // 文件夹类型
    typeCondition = new EqualsCondition("f.type_", NetdiskFile.TYPE_FOLDER);
    // 当前用户只能查看自己上传的文件
    SystemContext context = (SystemContext) this.getContext();
    // userCondition = new EqualsCondition("f.author_id", context
    // .getUserHistory().getId());

    // 文件夹不能隶属于自己
    if (folderId != null) {
      eliminateCondition = new NotEqualsCondition("f.id", folderId);
    }
    // 父级文件夹不能隶属子级
    // 当前用户有权限查看的文件
    Serializable[] ids = this.netdiskFileService.getUserSharFileId2All(context.getUser().getId());
    // 查找当前文件的父级
    // 可以操作的文件夹id
    List<Object> operateId = new ArrayList<Object>();
    if (folderId != null) {
      Serializable[] myselfAndChildId = this.netdiskFileService.getMyselfAndChildFileId(folderId);
      // 排除自己与子文件id后来的数组
      List<Object> eliminateId = new ArrayList<Object>();
      if (ids != null) {
        for (Serializable id : ids) {
          boolean isIn = false;
          for (Serializable pid : myselfAndChildId) {
            if (id.equals(pid)) {
              isIn = true;
              break;
            }
          }
          if (!isIn) {
            eliminateId.add(id);
          }
        }
        // 找出可操作的id
        if (!eliminateId.isEmpty()) {
          for (int i = 0; i < eliminateId.size(); i++) {
            // 查看当前文件是否设置访问权限,如果有就根据当前的权限来判断
            NetdiskShare myNetdiskShare =
                this.netdiskFileService.getNetdiskShare(
                    context.getUser().getId(), Long.valueOf(eliminateId.get(i).toString()));
            // 如果是自己的建的文件夹也操作
            NetdiskFile netdiskFile =
                this.netdiskFileService.load(Long.valueOf(eliminateId.get(i).toString()));
            if (netdiskFile.getAuthor().getId().equals(context.getUserHistory().getId())) {
              operateId.add(eliminateId.get(i));
            } else if (myNetdiskShare != null) {
              if (haveAuthority(myNetdiskShare.getRole(), 0)) {
                // 如果有权限就添加
                operateId.add(eliminateId.get(i));
              }
            } else {
              // 获取当前的文件和父级文件
              Serializable[] ParentIds =
                  this.netdiskFileService.getMyselfAndParentsFileId(
                      Long.valueOf(eliminateId.get(i).toString()));
              // 判断当前文件或父级文件夹该用户是否拥有编辑权限
              for (Serializable pid : ParentIds) {
                boolean isOwer = false;
                NetdiskFile nf = this.netdiskFileService.load(pid);
                Set<NetdiskShare> netdiskShare = nf.getFileVisitors();
                if (!netdiskShare.isEmpty()) {
                  Iterator<NetdiskShare> n = netdiskShare.iterator();
                  while (n.hasNext()) {
                    NetdiskShare ns = n.next();
                    if (ns.getAid().equals(context.getUser().getId())) {
                      if (haveAuthority(ns.getRole(), 0)) {
                        // 如果有权限就添加
                        operateId.add(eliminateId.get(i));
                        isOwer = true;
                        break;
                      }
                    }
                  }
                  if (isOwer) {
                    break;
                  }
                }
              }
            }
          }
        }
      }

      // 组装条件
      String qlStr4File = "";
      if (operateId.size() != 0) {
        for (int i = 0; i < operateId.size(); i++) {
          if (i + 1 != operateId.size()) {
            qlStr4File += "?,";
          } else {
            qlStr4File += "?";
          }
        }
      }
      authorityCondition =
          orCondition
              .add(
                  (operateId.size() != 0
                      ? new QlCondition("f.id in (" + qlStr4File + ")", operateId)
                      : null))
              .setAddBracket(true);
    }
    // 如果是公共硬盘管理员可以选择公共硬盘的文件夹
    Condition publicCondition = null;
    if (this.isPublicHardDiskManagement()) {
      publicCondition = new EqualsCondition("f.folder_type", NetdiskFile.FOLDER_TYPE_PUBLIC);
    }

    // 可以操作的文件夹不为空和有权限的
    if (operateId.size() != 0 && publicCondition != null) {
      return ConditionUtils.mix2OrCondition(
          operateFoldersCondition
              .add(statusCondition, typeCondition, eliminateCondition, authorityCondition)
              .setAddBracket(true),
          publicFoldersCondition
              .add(statusCondition, publicCondition, typeCondition)
              .setAddBracket(true));
      // 没有公共硬盘管理权限的
    } else if (operateId.size() != 0 && publicCondition == null) {
      return operateFoldersCondition.add(
          statusCondition, typeCondition, eliminateCondition, authorityCondition);
      // 没有可以操作的文件但有公共权限的
    } else if (operateId.size() == 0 && publicCondition != null) {
      return publicFoldersCondition.add(statusCondition, publicCondition, typeCondition);
    } else {
      return null;
    }
  }
  /**
   * Returns a session object. First, a key is generated by the session manager's key provider,
   * based on the JRadiusRequest. If there is a stored session based on the key, this session is
   * returned, otherwise a new session created by the session factory is returned
   *
   * @param request a JRadiusRequest used to retrieve or generate a session with
   * @return Returns a RadiusSession
   * @throws RadiusException
   */
  public JRadiusSession getSession(JRadiusRequest request) throws RadiusException {
    SessionKeyProvider skp = getSessionKeyProvider(request.getSender());
    Serializable key = skp.getAppSessionKey(request);
    JRadiusSession session = null;
    Serializable nkey = null;

    if (key != null) {
      RadiusLog.debug("** Looking for session: " + key);
      session = getSession(request, key);
      if (session == null) {
        RadiusLog.error("Broken JRadius-Session-Id implementation for session: " + key);
        key = null;
      }
    }

    if (key == null) {
      key = skp.getClassKey(request);

      if (key != null) {
        RadiusLog.debug("** Looking for session: " + key);
        session = getSession(request, key);
        if (session == null) {
          RadiusLog.error("Broken Class implementation for session: " + key);
          key = null;
        } else {
          if (session.getJRadiusKey() != null
              && !session.getJRadiusKey().equals(session.getSessionKey())) {
            rehashSession(session, session.getJRadiusKey(), key);
          }
        }
      }
    }

    if (key == null) {
      Serializable keys = skp.getRequestSessionKey(request);

      if (keys == null) {
        return null;
      }

      if (keys instanceof Serializable[]) {
        key = ((Serializable[]) (keys))[0];
        nkey = ((Serializable[]) (keys))[1];
        RadiusLog.debug("Rehashing session with key " + key + " under new key " + nkey);
      } else {
        key = keys;
      }

      RadiusLog.debug("** Looking for session: " + key);
      session = getSession(request, key);

      if (session != null && nkey != null && !nkey.equals(key)) {
        rehashSession(session, key, nkey);
      }
    }

    if (session == null) {
      session = newSession(request, nkey == null ? key : nkey);
    } else {
      session.setNewSession(false);
    }

    session.setTimeStamp(System.currentTimeMillis());
    session.setLastRadiusRequest(request);

    return session;
  }
Example #18
0
  protected List<Serializable> getFieldValues(
      DDMStructure ddmStructure,
      String fieldName,
      String fieldNamespace,
      ServiceContext serviceContext)
      throws PortalException {

    DDMFormField ddmFormField = ddmStructure.getDDMFormField(fieldName);

    String fieldDataType = ddmFormField.getDataType();
    String fieldType = ddmFormField.getType();

    LocalizedValue predefinedValue = ddmFormField.getPredefinedValue();

    List<String> fieldNames = getFieldNames(fieldNamespace, fieldName, serviceContext);

    List<Serializable> fieldValues = new ArrayList<>(fieldNames.size());

    for (String fieldNameValue : fieldNames) {
      Serializable fieldValue = serviceContext.getAttribute(fieldNameValue);

      if (Validator.isNull(fieldValue)) {
        fieldValue = predefinedValue.getString(serviceContext.getLocale());
      }

      if (fieldType.equals(DDMImpl.TYPE_CHECKBOX) && Validator.isNull(fieldValue)) {

        fieldValue = "false";
      } else if (fieldDataType.equals(FieldConstants.DATE)) {
        Date fieldValueDate = null;

        if (Validator.isNull(fieldValue)) {
          int fieldValueMonth =
              GetterUtil.getInteger(serviceContext.getAttribute(fieldNameValue + "Month"));
          int fieldValueDay =
              GetterUtil.getInteger(serviceContext.getAttribute(fieldNameValue + "Day"));
          int fieldValueYear =
              GetterUtil.getInteger(serviceContext.getAttribute(fieldNameValue + "Year"));

          fieldValueDate = PortalUtil.getDate(fieldValueMonth, fieldValueDay, fieldValueYear);
        } else {
          try {
            fieldValueDate =
                DateUtil.parseDate(String.valueOf(fieldValue), serviceContext.getLocale());
          } catch (ParseException pe) {
            if (_log.isErrorEnabled()) {
              _log.error("Unable to parse date " + fieldValue);
            }
          }
        }

        if (fieldValueDate != null) {
          fieldValue = String.valueOf(fieldValueDate.getTime());
        }
      } else if (fieldDataType.equals(FieldConstants.IMAGE) && Validator.isNull(fieldValue)) {

        HttpServletRequest request = serviceContext.getRequest();

        if (request instanceof UploadRequest) {
          String imageFieldValue = getImageFieldValue((UploadRequest) request, fieldNameValue);

          if (Validator.isNotNull(imageFieldValue)) {
            fieldValue = imageFieldValue;
          }
        }
      }

      if (Validator.isNull(fieldValue)) {
        return null;
      }

      if (DDMImpl.TYPE_RADIO.equals(fieldType) || DDMImpl.TYPE_SELECT.equals(fieldType)) {

        String predefinedValueString = predefinedValue.getString(serviceContext.getLocale());

        if (!fieldValue.equals(predefinedValueString) && (fieldValue instanceof String)) {

          fieldValue = new String[] {String.valueOf(fieldValue)};

          fieldValue = JSONFactoryUtil.serialize(fieldValue);
        }
      }

      Serializable fieldValueSerializable =
          FieldConstants.getSerializable(fieldDataType, GetterUtil.getString(fieldValue));

      fieldValues.add(fieldValueSerializable);
    }

    return fieldValues;
  }