我在Java play 2.6中具有以下复合操作:
public class EncryptPasswordAction extends Action<EncryptPassword> {
@Override
public CompletionStage<Result> call(Context ctx) {
User actionAuthor = (User) ctx.args.get(JWTDeadboltHandler.CURRENT_USER_KEY);
JsonNode requestData = ctx.request().body().asJson();
for (Iterator<String> fNames = requestData.fieldNames(); fNames.hasNext();) {
String fieldName = fNames.next();
if (fieldName == "password") {
byte[] encryptedPassword = DBUtils.getEncryptedPassword(actionAuthor.getEmail(),
requestData.get(fieldName).asText());
((ObjectNode) requestData).put(fieldName, encryptedPassword);
}
}
//Do something to update the request body with the new password value
return delegate.call(ctx);
}
}
目标是加密json正文中任何名为password
的字段。加密字段后,如何在调用delegate.call(ctx)
之前修改请求的主体,以便将password
字段的新值用于以下操作?