Spring Boot - 加密JSON数据(Spring Boot - Encrypt JSON data)
在我们的应用程序中,我们必须为每个请求和响应加密/解密Json属性值(而不是属性名称)。 例,
{"userName":"encrypted value", "email":"encrypted value"}
我们使用Sprint引导1.3,我们使用@RequestBody和@ResponseBody注释将请求json与对象绑定,并将响应对象序列化为JSON。
我们不想在我们的每个控制器方法中调用加密/解密方法。 有什么方法可以指示Sprint在绑定请求对象之前解密json值? 同样,要将响应对象字段值在转换为json之前加密? 或者定制杰克逊可能会帮助我们?
谢谢!
In our application we have to encrypt/decrypt the Json property values (not the property name) for each request and response. Example,
{"userName":"encrypted value", "email":"encrypted value"}
We use Sprint boot 1.3 and we are using @RequestBody and @ResponseBody annotations to bind the request json with the object and serialise the response object as JSON.
We don't want to call encrypt/decrypt method in our each controller method. Is there any way we can instruct sprint to decrypt the json values before binding with the request object? Similarly, to encrypt the response object field values before converting them to json? Or customising Jackson may help us?
Thanks!
原文:https://stackoverflow.com/questions/40740771
最满意答案
当您使用
Gemfile
,您正在使用bundler。 在您的脚本中,您需要包含rubygems
和bundler
才能使其正常工作。 试试这个require 'rubygems' require 'bundler/setup' require 'linkedindata' l = LinkedinData.new(1, "c:/users/proxylist.txt", true, true) searchTerms = ['First', 'Second', 'Third'] l.getByKeywords(searchTerms)
你已经运行了
bundle install
,抱歉不熟悉gemrat,所以不确定它对你有多大帮助。如果你实际上没有使用
bundler
,只需从上面的代码中删除require 'bundler/setup'
,你仍然需要在脚本中需要rubygems。在看起来像宝石本身有点破坏它声明依赖关系的方式,以及它所依赖的其他宝石。 我似乎能够使其工作如下:
的Gemfile:
source 'https://rubygems.org' gem 'linkedin-scraper' gem 'linkedindata' gem 'generalscraper' gem 'uploadconvert' gem 'docsplit' gem 'crack' gem 'pry' gem 'activesupport' gem 'selenium-webdriver'
它似乎还需要
linkedin-scraper
作为linkedin_scraper
但不确定为什么会这样。 所以编辑。
{GEMPATH}/linkedindata-0.0.22/lib/linkedindata.rb
require 'linkedin_scraper'
而不是require 'linkedin-scraper'
似乎使它工作。所以用上面的更改并使用bundler
require 'rubygems' require 'bundler/setup' require 'linkedindata' l = LinkedinData.new(1, "proxylist.txt", true, true) searchTerms = ['First', 'Second', 'Third'] l.getByKeywords(searchTerms)
现在运行(我没有proxylist.txt所以它爆炸寻找它,但它不再得到库错误)。
As you are using a
Gemfile
, you are using bundler. In your script you will need to includerubygems
andbundler
to make it work. Try thisrequire 'rubygems' require 'bundler/setup' require 'linkedindata' l = LinkedinData.new(1, "c:/users/proxylist.txt", true, true) searchTerms = ['First', 'Second', 'Third'] l.getByKeywords(searchTerms)
You have run
bundle install
, sorry not familiar with gemrat, so not sure how much it does for you.if you are not actually using
bundler
, just removerequire 'bundler/setup'
from the code above, you will still need to require rubygems though in your script.in looks like the gem itself is kind of broken in the way it declare dependencies, and the other gems that it relies on. I appear to be able to make it work as follows:
Gemfile:
source 'https://rubygems.org' gem 'linkedin-scraper' gem 'linkedindata' gem 'generalscraper' gem 'uploadconvert' gem 'docsplit' gem 'crack' gem 'pry' gem 'activesupport' gem 'selenium-webdriver'
It also appears that it the
linkedin-scraper
needs to required aslinkedin_scraper
but not sure why that is. So editing.
{GEMPATH}/linkedindata-0.0.22/lib/linkedindata.rb
torequire 'linkedin_scraper'
as opposed torequire 'linkedin-scraper'
seems to make it work.So with the above changes and using bundler
require 'rubygems' require 'bundler/setup' require 'linkedindata' l = LinkedinData.new(1, "proxylist.txt", true, true) searchTerms = ['First', 'Second', 'Third'] l.getByKeywords(searchTerms)
now runs (I don't have a proxylist.txt so it blows up looking for it, but it doesn't get anymore library errors).
相关问答
更多-
当您使用Gemfile ,您正在使用bundler。 在您的脚本中,您需要包含rubygems和bundler才能使其正常工作。 试试这个 require 'rubygems' require 'bundler/setup' require 'linkedindata' l = LinkedinData.new(1, "c:/users/proxylist.txt", true, true) searchTerms = ['First', 'Second', 'Third'] l.getByKeywor ...
-
为了获得良好的开端,您可以使用bundle gem命令和rspec --init 。 ~/code $ bundle gem my_lib create my_lib/Gemfile create my_lib/Rakefile create my_lib/LICENSE.txt create my_lib/README.md create my_lib/.gitignore create my_lib/my_lib.gem ...
-
没有。 这种语言发展很多,与Ruby最近有很大的不同。 虽然感觉有点像Ruby,但如果你真的尝试过,你很快就会明白为什么这个问题甚至不会出现,除了你可以想象的最简单的宝石。 只有两个例子: Crystal没有单引号字符串文字: 'c' # Ok in Ruby and Crystal, but different things, # a String in Ruby, a Char in Crystal "a string" # Ok in Ruby and Cryst ...
-
OP在评论中表示: 实际上,检查应用程序/更新它似乎我的Xcode已更新。 但是我没有升级到约塞米蒂。 升级到Apple的Xcode可以以惊人的方式破解事物。 每当更新Xcode或升级OS X系统库时,它通常可以帮助执行以下部分或全部操作: 接受新的Xcode许可协议。 即使您之前已经接受了协议,也需要在每次升级后执行此操作。 再次安装Xcode命令行工具。 重新安装任何非系统Ruby版本,并使用本机扩展重新编译gem。 In comments, the OP said: Actually, checkin ...
-
使用Ruby Gems(Using Ruby Gems)[2022-03-13]
你有没有通过shell中的“gem install curb”安装gem? 前两个,Net :: HTTP和JSON,是Ruby 1.9标准库的一部分,因此它们实际上根本不使用RubyGems。 Have you installed the gem via "gem install curb" in the shell? The first two, Net::HTTP and JSON, are part of the Ruby 1.9 standard library, so they don't ac ... -
正如Jesper建议的那样,我使用Dalli memcached客户端解决了这个问题。 As Jesper suggested, I solved the issue using Dalli memcached client.
-
Ruby中的基本身份提供程序(Basic Identity Provider in Ruby)[2022-03-23]
使用类似于适用于ADFS服务器的Ruby on Rails的SAML工具包之类的东西,您可以与ADFS集成。 现在您可以利用ADFS功能: 通过Azure ACS与Facebook等界面 与Azure Active Directory的接口以及SSO到SaaS应用程序的接口 Azure Active Directory多重身份验证 BYOD通过Web应用程序代理 ADFS 3.0上的OAuth 等等。 该名单一直在扩大。 一旦你加入这些标准。 您只需在发布时继承所有新功能。 Using something ... -
Ruby gems升级问题(Ruby gems issue with upgrading)[2022-03-09]
由于我过去使用过旧的Ruby版本2.0,所以它让apache感到困惑。 我可以明确地告诉apache使用哪个目录,或者使用RVM(Ruby Version Manager)来完成所有工作。 只需要完成以下步骤: 安装RVM: rvm get stable --auto-dotfiles 然后告诉您倾向于使用哪个版本: rvm use 2.2.0 更新宝石 gem install rails 现在准备好了! Since I had an older Ruby version 2.0 from the p ... -
我想,你正在使用指挥官宝石。 请安装 gem install commander 版本是4.1.1 I guess, You are using commander gem. Please install it by gem install commander Version is 4.1.1
-
我可以从Ruby中删除什么,仍然支持Rake / gems?(What can I remove from Ruby and still have it support Rake/gems?)[2022-09-03]
从我自己的实验和调查来看,很难确定什么是“必需的”和什么是可选的。 有些文件看起来非常安全且易于删除,而有些文件我不想玩。 我的结果只能节省大约5 MB ...可能还不足以保证这样做。 箱子 ruby/bin目录包含许多批处理脚本,它们只是用正确的“应用程序”调用ruby可执行文件的助手,如Rake或Gem。 例如, rake.bat包含此行 @"%~dp0ruby.exe" "%~dpn0" %* 您可以在build.bat脚本中使用正确的comamnd替换它(假设它比ruby环境高一级,可能在解决方案 ...