コード例 #1
0
  @Around("execution(@com.marcolenzo.gameboard.annotations.ActionLoggable * *(..))")
  public Object around(ProceedingJoinPoint point) throws Throwable {
    long start = System.currentTimeMillis();
    Object result = point.proceed();

    User currentUser = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    Action action = new Action();
    action.setName(MethodSignature.class.cast(point.getSignature()).getMethod().getName());

    // Parse args
    List<String> jsonStrings = Lists.newArrayList();
    for (Object obj : point.getArgs()) {

      jsonStrings.add(mapper.writeValueAsString(obj));
    }
    action.setArgs(jsonStrings);
    action.setResult(mapper.writeValueAsString(result));

    action.setUserId(currentUser.getId());
    action.setDatetime(LocalDateTime.now());

    repository.save(action);

    LOGGER.info(
        "#{}({}): in {} ms by {}",
        MethodSignature.class.cast(point.getSignature()).getMethod().getName(),
        point.getArgs(),
        System.currentTimeMillis() - start,
        currentUser.getId() + " " + currentUser.getEmail());

    return result;
  }
コード例 #2
0
 public static Authentication createMockAuthentication(String userId) {
   User user = new User();
   user.setId(userId);
   user.setEmail("*****@*****.**");
   user.setNickname("User's Nickname");
   user.setPassword("123123123");
   return new UsernamePasswordAuthenticationToken(user, "123123123");
 }