SlideShare a Scribd company logo
Soham Sengupta
https://github.com/trainerpb 1
Basic Approaches of Spring Security
1. URL level security (We already know this)
2. Method level security
3. Entity /Object Level security
https://github.com/trainerpb 2
Method Level Security- what & why?
 Additional Layer of Security
 Decouple & less-rely on Front-end logic for ‘ROLE based access ‘
 Survives in case of developer- mistake (E.g. renaming paths – which
allowed other roles to access resources)
https://github.com/trainerpb 3
What does that mean?
https://github.com/trainerpb 4
Let’s prevent the method ,too
https://github.com/trainerpb 5
What happens?
 Even if any other role is allowed to access /doA
 Access to this method will be FORBIDDEN (HTTP Status: 403)
 @PreAuthorize is capable of:
 Evaluating Spring Expressions
 Access Method Parameters
https://github.com/trainerpb 6
@PostAuthroize
 This helps control access to succeed depending on returned value of the
method
 E.g. -a very silly impractical USE-CASE-
 Let Access succeed as long length of the username <= Radom() mod 8
https://github.com/trainerpb 7
@PreFilter
 Helps filter out from a method, objects from a Collection passed as
parameter to a method
https://github.com/trainerpb 8
@PreFilter – Contd.
 Use Case – List all Users except yourself – (E.g. Facebook –chat pane
shows all friends of your but not you!)
https://github.com/trainerpb 9
@PreFilter – Contd.
Assignment – What happens if more than one
Collection are passed in parameter list?
https://github.com/trainerpb 10
@PostFilter
 This helps filter returned Collection based on some criteria that is returned
https://github.com/trainerpb 11
Other Approaches- @Secured
https://github.com/trainerpb 12
@Secured annotation doesn’t support Spring Expression Language
What’ll be the @PreAuthorize equivalent of the above code snippet?
Another Approach- @RoleAllowed
https://github.com/trainerpb 13
What’ll be the @PreAuthorize equivalent of the above code snippet?
Combining @’s together
 We can put multiple annotations together on a method.
 I want a method
 To be available to ADMIN only
 Then, I want to return Collection of records of logged-in user only
https://github.com/trainerpb 14
Important Notes-
1. By default, Spring AOP proxy-ing is used to apply method security
 Security will be ignored fora secure method m1() called by another method
m2() in the same class
2. Thread-bound Security Context-
 security context isn’t propagated to child-threads
3. We can use @PreAuthroize or similar annotations at class-level to
ensure ROLE_BASED access to that class.
https://github.com/trainerpb 15
https://github.com/trainerpb 16

More Related Content

PPTX
Monitoring with Prometheus
DOC
List of computer network programs
PPT
Lo nuevo en Spring 3.0 - Spring Live Perú 2009
ODP
PST Repair Tool
PDF
Storyplayer
PPTX
Run python from windows taskscheduler
PPTX
Celery in the Django
PDF
Demystifying how imports work in Python
Monitoring with Prometheus
List of computer network programs
Lo nuevo en Spring 3.0 - Spring Live Perú 2009
PST Repair Tool
Storyplayer
Run python from windows taskscheduler
Celery in the Django
Demystifying how imports work in Python

Similar to Spring method-level-secuirty (20)

ODP
Drupal development
PDF
Greach 2014 - Metaprogramming with groovy
PDF
PHP LFI to Arbitrary Code Execution via rfc1867 file upload temporary files
KEY
Fall 2011 PHP Class - Session 1
PPT
How to? Drupal developer toolkit. Dennis Povshedny.
PPTX
Intro to OOP PHP and Github
PPT
Ratpack - Classy and Compact Groovy Web Apps
PPT
Introduction to Cakephp
PPT
Learn flask in 90mins
PPT
Andy On Closures
PPTX
Spring security mvc-1
PPT
PPT
PPT
PDF
Slim PHP when you don't need the kitchen sink
PPT
Oops in PHP By Nyros Developer
PDF
Indic threads delhi13-rest-anirudh
PDF
JVM Web Frameworks Exploration
PPT
Oops in PHP
Drupal development
Greach 2014 - Metaprogramming with groovy
PHP LFI to Arbitrary Code Execution via rfc1867 file upload temporary files
Fall 2011 PHP Class - Session 1
How to? Drupal developer toolkit. Dennis Povshedny.
Intro to OOP PHP and Github
Ratpack - Classy and Compact Groovy Web Apps
Introduction to Cakephp
Learn flask in 90mins
Andy On Closures
Spring security mvc-1
Slim PHP when you don't need the kitchen sink
Oops in PHP By Nyros Developer
Indic threads delhi13-rest-anirudh
JVM Web Frameworks Exploration
Oops in PHP
Ad

More from Soham Sengupta (20)

PDF
JavaScript event handling assignment
PDF
Networking assignment 2
PDF
Networking assignment 1
PPT
Sohams cryptography basics
PPT
Network programming1
PPT
JSR-82 Bluetooth tutorial
PPSX
Xmpp and java
PPT
Core java day2
PPT
Core java day1
PPT
Core java day4
PPT
Core java day5
PPT
Exceptions
PPSX
Java.lang.object
PPTX
Soham web security
PPTX
Html tables and_javascript
PPT
Html javascript
PPT
Java script
PPS
Sohamsg ajax
PPT
JavaScript event handling assignment
Networking assignment 2
Networking assignment 1
Sohams cryptography basics
Network programming1
JSR-82 Bluetooth tutorial
Xmpp and java
Core java day2
Core java day1
Core java day4
Core java day5
Exceptions
Java.lang.object
Soham web security
Html tables and_javascript
Html javascript
Java script
Sohamsg ajax
Ad

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Empathic Computing: Creating Shared Understanding
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
KodekX | Application Modernization Development
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Programs and apps: productivity, graphics, security and other tools
sap open course for s4hana steps from ECC to s4
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Reach Out and Touch Someone: Haptics and Empathic Computing
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Empathic Computing: Creating Shared Understanding
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Approach and Philosophy of On baking technology
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
KodekX | Application Modernization Development
20250228 LYD VKU AI Blended-Learning.pptx

Spring method-level-secuirty

  • 2. Basic Approaches of Spring Security 1. URL level security (We already know this) 2. Method level security 3. Entity /Object Level security https://github.com/trainerpb 2
  • 3. Method Level Security- what & why?  Additional Layer of Security  Decouple & less-rely on Front-end logic for ‘ROLE based access ‘  Survives in case of developer- mistake (E.g. renaming paths – which allowed other roles to access resources) https://github.com/trainerpb 3
  • 4. What does that mean? https://github.com/trainerpb 4
  • 5. Let’s prevent the method ,too https://github.com/trainerpb 5
  • 6. What happens?  Even if any other role is allowed to access /doA  Access to this method will be FORBIDDEN (HTTP Status: 403)  @PreAuthorize is capable of:  Evaluating Spring Expressions  Access Method Parameters https://github.com/trainerpb 6
  • 7. @PostAuthroize  This helps control access to succeed depending on returned value of the method  E.g. -a very silly impractical USE-CASE-  Let Access succeed as long length of the username <= Radom() mod 8 https://github.com/trainerpb 7
  • 8. @PreFilter  Helps filter out from a method, objects from a Collection passed as parameter to a method https://github.com/trainerpb 8
  • 9. @PreFilter – Contd.  Use Case – List all Users except yourself – (E.g. Facebook –chat pane shows all friends of your but not you!) https://github.com/trainerpb 9
  • 10. @PreFilter – Contd. Assignment – What happens if more than one Collection are passed in parameter list? https://github.com/trainerpb 10
  • 11. @PostFilter  This helps filter returned Collection based on some criteria that is returned https://github.com/trainerpb 11
  • 12. Other Approaches- @Secured https://github.com/trainerpb 12 @Secured annotation doesn’t support Spring Expression Language What’ll be the @PreAuthorize equivalent of the above code snippet?
  • 13. Another Approach- @RoleAllowed https://github.com/trainerpb 13 What’ll be the @PreAuthorize equivalent of the above code snippet?
  • 14. Combining @’s together  We can put multiple annotations together on a method.  I want a method  To be available to ADMIN only  Then, I want to return Collection of records of logged-in user only https://github.com/trainerpb 14
  • 15. Important Notes- 1. By default, Spring AOP proxy-ing is used to apply method security  Security will be ignored fora secure method m1() called by another method m2() in the same class 2. Thread-bound Security Context-  security context isn’t propagated to child-threads 3. We can use @PreAuthroize or similar annotations at class-level to ensure ROLE_BASED access to that class. https://github.com/trainerpb 15