[英]Using WS-Security tools to secure web applications created by the Ruby on Rails framework
使用Ruby on Rails框架開發的Web應用程序是否可以使用第三方安全工具攔截對它的所有調用? 對此Web應用程序的任何調用都將轉到安全工具而不是Web應用程序本身,然后安全工具可以將其重定向到Web應用程序。
在響應方面類似,安全工具在將其發送到客戶端(瀏覽器)之前攔截Web應用程序響應
如果我理解你想要正確做什么,你可以使用befor_methods來做到這一點
回調掛鈎到Active Record對象的生命周期,允許您在更改對象狀態之前或之后觸發邏輯。 這可用於確保在調用destroy(通過覆蓋before_destroy)時刪除關聯和依賴對象,或者在驗證之前按下屬性(通過覆蓋before_validation)。 作為啟動回調的示例,請考慮新記錄的Base#save調用:
(-) save
(-) valid
(1) before_validation
(-) validate
(2) after_validation
(3) before_save
(4) before_create
(-) create
(5) after_create
(6) after_save
(7) after_commit
此外,可以將after_rollback回調配置為在發出回滾時觸發。 有關after_commit和after_rollback的更多詳細信息,請查看ActiveRecord :: Transactions。
此外,只要觸摸對象,就會觸發after_touch回調。
最后,為查找器找到並實例化的每個對象觸發after_find和after_initialize回調,並在實例化新對象后觸發after_initialize。
總共有十九個回調,它們為您提供了巨大的力量來為Active Record生命周期中的每個州做出反應和准備。 為現有記錄調用Base#save的順序類似,只是每個_create回調都被相應的_update回調替換。
例子:
class CreditCard < ActiveRecord::Base
# Strip everything but digits, so the user can specify "555 234 34" or
# "5552-3434" and both will mean "55523434"
before_validation(on: :create) do
self.number = number.gsub(/[^0-9]/, "") if attribute_present?("number")
end
end
class Subscription < ActiveRecord::Base
before_create :record_signup
private
def record_signup
self.signed_up_on = Date.today
end
end
class Firm < ActiveRecord::Base
# Destroys the associated clients and people when the firm is destroyed
before_destroy { |record| Person.destroy_all "firm_id = #{record.id}" }
before_destroy { |record| Client.destroy_all "client_of = #{record.id}" }
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.