java


Spring + Hibernate auditing (no Spring Data)


I have joined a project that was built for a year with Spring and Hibernate with Agile methodology and it didn't use Spring Data and has its own user class (not descendent of org.springframework.security.core.userdetails.User ).
Auditing came up as a new feauture to be implemented. (It's not enough to log the what controllers were called, we have to log every DB field's change, and which user did it. One controller can cause a lot of DB fields to change.) What are my options?
I have been looking at Javers, Envers and Audit4j. Javers requires Spring Data, so it's out. Envers' only requirement is Hibernate, which is statisfied, but I still don't see how the User object will be passed to it from the controller (the User's auth token is in the request object).
Hibernate Envers only gives you versioning (what have happened to an object at what time), but it doesn't help you figuring out who did the change.
A simple solution to the who-part is to create two new fields on all objects that shall be audited (i.e. in a base class such as AbstractAuditableEntity): User createdBy; and User lastModifiedBy;. Add two methods (I'm assuming you're using Spring Security here):
#PrePersist
protected void setCreatedBy() {createdBy = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();}
#PreUpdate
protected void setCreatedBy() {lastModifiedBy = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();}

Related Links

Enabling back button with Ajax
how to develop automatic birthday reminder java program to display reminder message to different computer
Remove duplicates in an array without changing order of elements
getting parent directory of ${basedir} from maven
WebSphere 7 log level configuration at runtime
H2 driver can't find/create a table
how to suppress Inefficient use of keySet iterator instead of entrySet iterator in findbugs?
create rectangles in java netbeans with data from database mysql
Java. Regex matcher not working, with regex which works in c# or vb.net
How do I get nodes from a OutlineView in the current order?
Google Wallet API miss in google-play-services
Calling new key word twice, both at declaration and in a method
Different results with Boolean and boolean in java
JSF2 - Flexible way on restrict access on certain xhtml pages, apply simple logic on access
Error in Spliting and Concatenating String
How can I access a 'Web App' built in Google Apps Script from Android?

Categories

HOME
pandas
reflection
google-api-php-client
homebrew
hp-exstream
vmware
tesseract
kalman-filter
microservices
electronics
azure-media-services
directx
basic
dax
numeral.js
export-to-csv
correlation
timeout
messages
ghc
pythonanywhere
physics-engine
arabic
accessor
extjs5
bootstrap-tour
cultureinfo
php-openssl
firebase-crash-reporting
selectedindexchanged
facebook-access-token
facebook-apps
javascriptcore
bosh
ioio
hybridauth
host
appfabric
leading-zero
hp-ux
mapzen
fedex
nand2tetris
spring-security-kerberos
galleria
qwt
rainbowtable
promela
svmlight
darcs
csound
r-forge
windows-iot-core-10
pdfclown
nbconvert
bind9
lync-client-sdk
wdf
deadbolt-2
angular-cache
libpng
log4c
slicknav
elements
skobbler-maps
mathematica-frontend
xml-attribute
impresspages
connect-by
qcustomplot
essence
sdf
asp.net5
pyke
photobucket
content-length
varargs
unity3d-gui
composite
bigbluebutton
dd
angularjs-ng-click
relocation
code-access-security
htmlcleaner
resty-gwt
prettify
terminal-services
listings
eclipse-memory-analyzer
itmstransporter
hamiltonian-cycle
trusted
funscript
objective-c-2.0
appconkit
amazon-appstore
semantic-diff
fireworks
php-parser
pydot
f#-powerpack
xtype
yetanotherforum
appendto
pyinotify
.nettiers
meego
kdbg
microsoft-virtualization
premature-optimization
noscript
procedural-music
multiple-languages
rtml

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App