Esempio n. 1
0
  @Override
  protected SecurityQuestionTO resolveReference(final Method method, final Object... args)
      throws UnresolvedReferenceException {

    Long key = null;

    if (ArrayUtils.isNotEmpty(args)) {
      for (int i = 0; key == null && i < args.length; i++) {
        if (args[i] instanceof Long) {
          key = (Long) args[i];
        } else if (args[i] instanceof SecurityQuestionTO) {
          key = ((SecurityQuestionTO) args[i]).getKey();
        }
      }
    }

    if ((key != null) && !key.equals(0L)) {
      try {
        return binder.getSecurityQuestionTO(securityQuestionDAO.find(key));
      } catch (Throwable ignore) {
        LOG.debug("Unresolved reference", ignore);
        throw new UnresolvedReferenceException(ignore);
      }
    }

    throw new UnresolvedReferenceException();
  }
Esempio n. 2
0
  @PreAuthorize("isAuthenticated()")
  public SecurityQuestionTO read(final Long securityQuestionId) {
    SecurityQuestion securityQuestion = securityQuestionDAO.find(securityQuestionId);
    if (securityQuestion == null) {
      LOG.error("Could not find security question '" + securityQuestionId + "'");

      throw new NotFoundException(String.valueOf(securityQuestionId));
    }

    return binder.getSecurityQuestionTO(securityQuestion);
  }
Esempio n. 3
0
  @PreAuthorize("hasRole('" + Entitlement.SECURITY_QUESTION_DELETE + "')")
  public SecurityQuestionTO delete(final Long securityQuestionId) {
    SecurityQuestion securityQuestion = securityQuestionDAO.find(securityQuestionId);
    if (securityQuestion == null) {
      LOG.error("Could not find security question '" + securityQuestionId + "'");

      throw new NotFoundException(String.valueOf(securityQuestionId));
    }

    SecurityQuestionTO deleted = binder.getSecurityQuestionTO(securityQuestion);
    securityQuestionDAO.delete(securityQuestionId);
    return deleted;
  }
Esempio n. 4
0
  @PreAuthorize("hasRole('" + Entitlement.SECURITY_QUESTION_UPDATE + "')")
  public SecurityQuestionTO update(final SecurityQuestionTO securityQuestionTO) {
    SecurityQuestion securityQuestion = securityQuestionDAO.find(securityQuestionTO.getKey());
    if (securityQuestion == null) {
      LOG.error("Could not find security question '" + securityQuestionTO.getKey() + "'");

      throw new NotFoundException(String.valueOf(securityQuestionTO.getKey()));
    }

    binder.update(securityQuestion, securityQuestionTO);
    securityQuestion = securityQuestionDAO.save(securityQuestion);

    return binder.getSecurityQuestionTO(securityQuestion);
  }
Esempio n. 5
0
  @PreAuthorize("isAnonymous() or hasRole('" + Entitlement.ANONYMOUS + "')")
  public SecurityQuestionTO read(final String username) {
    if (username == null) {
      throw new NotFoundException("Null username");
    }
    User user = userDAO.find(username);
    if (user == null) {
      throw new NotFoundException("User " + username);
    }

    if (user.getSecurityQuestion() == null) {
      LOG.error("Could not find security question for user '" + username + "'");

      throw new NotFoundException("Security question for user " + username);
    }

    return binder.getSecurityQuestionTO(user.getSecurityQuestion());
  }
Esempio n. 6
0
 @PreAuthorize("hasRole('" + Entitlement.SECURITY_QUESTION_CREATE + "')")
 public SecurityQuestionTO create(final SecurityQuestionTO securityQuestionTO) {
   return binder.getSecurityQuestionTO(
       securityQuestionDAO.save(binder.create(securityQuestionTO)));
 }