@PreAuthorize("hasRole('" + StandardEntitlement.SECURITY_QUESTION_READ + "')") @Transactional(readOnly = true) public SecurityQuestionTO read(final String key) { SecurityQuestion securityQuestion = securityQuestionDAO.find(key); if (securityQuestion == null) { LOG.error("Could not find security question '" + key + "'"); throw new NotFoundException(key); } return binder.getSecurityQuestionTO(securityQuestion); }
@PreAuthorize("hasRole('" + StandardEntitlement.SECURITY_QUESTION_CREATE + "')") public SecurityQuestionTO create(final SecurityQuestionTO securityQuestionTO) { return binder.getSecurityQuestionTO(securityQuestionDAO.save(binder.create(securityQuestionTO))); }
@PreAuthorize("hasRole('" + StandardEntitlement.SECURITY_QUESTION_DELETE + "')") public SecurityQuestionTO delete(final String key) { SecurityQuestion securityQuestion = securityQuestionDAO.find(key); if (securityQuestion == null) { LOG.error("Could not find security question '" + key + "'"); throw new NotFoundException(key); } SecurityQuestionTO deleted = binder.getSecurityQuestionTO(securityQuestion); securityQuestionDAO.delete(key); return deleted; }
@PreAuthorize("hasRole('" + StandardEntitlement.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(securityQuestionTO.getKey()); } binder.update(securityQuestion, securityQuestionTO); securityQuestion = securityQuestionDAO.save(securityQuestion); return binder.getSecurityQuestionTO(securityQuestion); }
@PreAuthorize("isAnonymous() or hasRole('" + StandardEntitlement.ANONYMOUS + "')") public SecurityQuestionTO readByUser(final String username) { if (username == null) { throw new NotFoundException("Null username"); } User user = userDAO.findByUsername(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()); }
@Override protected SecurityQuestionTO resolveReference(final Method method, final Object... args) throws UnresolvedReferenceException { String key = null; if (ArrayUtils.isNotEmpty(args)) { for (int i = 0; key == null && i < args.length; i++) { if (args[i] instanceof String) { key = (String) args[i]; } else if (args[i] instanceof SecurityQuestionTO) { key = ((SecurityQuestionTO) args[i]).getKey(); } } } if (key != null) { try { return binder.getSecurityQuestionTO(securityQuestionDAO.find(key)); } catch (Throwable ignore) { LOG.debug("Unresolved reference", ignore); throw new UnresolvedReferenceException(ignore); } } throw new UnresolvedReferenceException(); } }