SlideShare a Scribd company logo
1 of 34
Download to read offline
Domain Primitives in Action
- Making it Secure by Design
@DanielDeogun @danbjson
DataTjej
February 15, 2018
@DanielDeogun @danbjson #SecureByDesign
About Us…
Dan Bergh Johnsson
Secure Domain Philosopher
Omegapoint, Sweden
Umeå
Malmö
Göteborg
Falun
New York
Stockholm
Daniel Deogun
Coder and Quality Defender
@DanielDeogun @danbjson #SecureByDesign
Key Take Aways
Domain Primitives
- are native to your domain
- form a conceptual whole
- easy way to improve and secure existing code
@DanielDeogun @danbjson #SecureByDesign
Agenda
• A Bank Robbery
• Secure by Design
• Buying -1 Books
• Room Numbers
• Domain Primitives
• Domain Primitives Applied on Legacy
@DanielDeogun @danbjson #SecureByDesign
A Bank Robbery
image: Smådisigt Medlemsblad för DIS-Småland
@DanielDeogun @danbjson #SecureByDesign
Secure by Design
“A mindset and strategy for creating secure
software by focusing on good design”
- Secure by Design
@DanielDeogun @danbjson #SecureByDesign
Buying -1 books
[1]
1 Secure by Design $49.99
-1 Hamlet $40.50
1 Hitchhiker's Guide to the Galaxy $30.00
Shopping Cart
Total $39.49
@DanielDeogun @danbjson #SecureByDesign
Analysis
-1 : Integer
-1 : Integer
OrderLine {ISBN, -1}
Math Context
Webshop Context
@DanielDeogun @danbjson #SecureByDesign
But Quantity is “just”
an integer…
Quantity
• a concept that’s well defined
with strict boundaries
• not closed under addition
• cannot be negative
Peano's Axioms
1. Zero is a number
2. If n is a number, the successor of n is a number
3. Zero isn’t the successor of a number
4. Two numbers of which the successors are equal are
themselves equal
5. If a set S of numbers contains zero and also the successor
of every number in S, then every number is in S
Abelian Group
• Closure: a + b = integer
• Associativity: a + (b + c) = (a + b) + c
• Commutativity: a + b = b + a
• Identity: a + 0 = a
• Inverse: a + (−a) = 0
🤔
@DanielDeogun @danbjson #SecureByDesign
…or is Quantity a
String?
• What characters are legal?
• Which operations are allowed?
• Does this make sense?
@DanielDeogun @danbjson #SecureByDesign
Let’s Model a Hotel
Room
@DanielDeogun @danbjson #SecureByDesign
But Room Number
is “just” an Integer…
🤔Peano's Axioms
1. Zero is a number
2. If n is a number, the successor of n is a number
3. Zero isn’t the successor of a number
4. Two numbers of which the successors are equal are
themselves equal
5. If a set S of numbers contains zero and also the successor
of every number in S, then every number is in S
Abelian Group
• Closure: a + b = integer
• Associativity: a + (b + c) = (a + b) + c
• Commutativity: a + b = b + a
• Identity: a + 0 = a
• Inverse: a + (−a) = 0
@DanielDeogun @danbjson #SecureByDesign
…or is Room Number a
String?
• What characters are legal?
• Which operations are allowed?
• Does this make sense?
@DanielDeogun @danbjson #SecureByDesign
Domain Primitives
“A value object so precise in its definition that it, by its mere
existence, manifests its validity is called a Domain Primitive.”
- Secure by Design
• Can only exist if its value is valid
• Building block that’s native to your domain
• Valid in the current context
• Immutable and resemble a value object in DDD
@DanielDeogun @danbjson #SecureByDesign
Math and Hotel are
different Contexts
Math Domain
Integer
Hotel Domain
Room Number
Hotel Domain
Math Domain
Integer
(a.k.a Room Number)
Domain Primitive
@DanielDeogun @danbjson #SecureByDesign
Math and Webshop are
different Contexts
Math Domain
Integer
Webshop Domain
Quantity
Webshop
Math Domain
Integer
(a.k.a Quantity)
Domain Primitive
@DanielDeogun @danbjson #SecureByDesign
Quantity as a Domain
Primitive
public final class Quantity {
private final int value;
public Quantity(final int value) {
inclusiveBetween(1, 99, value);
this.value = value;
}
//Domain specific quantity operations...
}
@DanielDeogun @danbjson #SecureByDesign
Room Number as a
Domain Primitive
public final class RoomNumber {
private final int value;
public RoomNumber(final int value) {
isTrue(Floor.isValid(value));
inclusiveBetween(1, 50, value % 100);
this.value = value;
}
public Floor floor() {
return new Floor(value);
}
// other logic …
}
@DanielDeogun @danbjson #SecureByDesign
Invalid quantities are
rejected by Definition!
-1 : Integer
Quantity: {1 - 99}
OrderLine {ISBN, Quantity}
Math Context
Webshop Context
Only valid quantities are
accepted
Rejected
@DanielDeogun @danbjson #SecureByDesign
Less Simple
Domain Primitive
public void pay(final double money, final int recipientId) {
final String currency = CurrencyService.currencyFor(recipientId);
BankService.transfer(money, currency, recipientId);
}
public void pay(final Money money, final Recipient recipient) {
notNull(money);
notNull(recipient);
BankService.transfer(money, recipient);
}
But Money is a conceptual whole and
should be modeled as a domain primitive
@DanielDeogun @danbjson #SecureByDesign
Intelligent Machines -
not just values
class Rate {

private final Currency from;

private final Currency to;



Rate(Currency from, Currency to) {

this.from = notNull(from);

this.to = notNull(to);

}


Money exchange(Money from) {
notNull(from);
isTrue(this.from
.equals(from.currency));
BigDecimal converted = . . .

return new Money(converted, to);

}

}
@DanielDeogun @danbjson #SecureByDesign
Standing on the
Shoulders of Giants
• Domain Primitives act as building blocks
• Guy L. Steele Jr. “Growing a Language”
• Abelson, Sussman “Structure and
Interpretation of Computer Programs”
https://flic.kr/p/8cc44h https://creativecommons.org/licenses/by/2.0/
@DanielDeogun @danbjson #SecureByDesign
Domain Primitives in
Action on Legacy
https://flic.kr/p/Q7zV https://creativecommons.org/licenses/by-sa/2.0/
vs
https://flic.kr/p/djYc9H https://creativecommons.org/licenses/by/2.0/
Green Field Brown Field
@DanielDeogun @danbjson #SecureByDesign
Three Steps
https://flic.kr/p/wdBcT
https://creativecommons.org/licenses/by/2.0/
Untangle insideDraw the line
Harden your API
https://flic.kr/p/YgfS6s
https://creativecommons.org/licenses/by/2.0/
https://flic.kr/p/nEZKMd
https://creativecommons.org/licenses/by/2.0/
@DanielDeogun @danbjson #SecureByDesign
“Draw the Line”
- Find a Semantic Border
• We need to identify the semantic boundary of a context
• Add a layer that internally translates data to a domain
primitive and the back again
data -> domain primitive -> data
• This way, we have created a validation boundary that
protects the inside from bad input
• But, if rejecting data is to harsh, consider logging it for
insight
https://flic.kr/p/nEZKMd https://creativecommons.org/licenses/by/2.0/
public void checkout(final int roomNumber) {
new RoomNumber(roomNumber); //throws exception if invalid
houseKeepingService.registerForCleaning(roomNumber);
minibarService.replenish(roomNumber);
// other operations ...
}
public void checkout(final int roomNumber) {
if (!RoomNumber.isValid(roomNumber)) {
reporter.logInvalidRoomNumber(roomNumber);
}
houseKeepingService.registerForCleaning(roomNumber);
minibarService.replenish(roomNumber);
// other operations ...
}
@DanielDeogun @danbjson #SecureByDesign
Harden your API
- Enforce Data Quality
Generic
Specific
public void checkout(final int roomNumber)
public void checkout(final RoomNumber roomNumber)
Enforce data quality https://flic.kr/p/YgfS6s
https://creativecommons.org/licenses/by/2.0/
@DanielDeogun @danbjson #SecureByDesign
Untangle Inside
- Cluttered Entity
https://flic.kr/p/wdBcT
https://creativecommons.org/licenses/by/2.0/
class Order {
private ArrayList<Object> items;
private boolean paid;



public void addItem(String isbn, int qty) {
if(this.paid == false) {
notNull(isbn);
inclusiveBetween(10, 10, isbn.length());
isTrue(isbn.matches("[0-9X]*"));
isTrue(isbn.matches("[0-9]{9}[0-9X]"));

Book book = bookCatalogue.findByISBN(isbn);

if (inventory.availableBooks(isbn) >= qty) {
items.add(new OrderLine(book, qty));
}
}
}
//Other logic...
}
@DanielDeogun @danbjson #SecureByDesign
De-Cluttered Entity
class Order {
private ArrayList<Object> items;
private boolean paid;

public void addItem(ISBN isbn, Quantity qty) {
notNull(isbn);
notNull(qty);
if(this.paid == false) {
Book book = bookCatalogue.findByISBN(isbn);

if (inventory.availableBooks(isbn).greaterOrEqualTo(qty)) {
items.add(new OrderLine(book, qty));
}
}
}
//Other logic...
} https://flic.kr/p/wdBcT
https://creativecommons.org/licenses/by/2.0/
@DanielDeogun @danbjson #SecureByDesign
But…
https://flic.kr/p/eGYhMw
https://creativecommons.org/licenses/by/2.0/
… what about performance?
https://flic.kr/p/2pvb2T
https://creativecommons.org/licenses/by/2.0/
… it becomes a lot of classes!
… isn’t it overly complex?
https://flic.kr/p/7Ro4HU
https://creativecommons.org/licenses/by/2.0/
@DanielDeogun @danbjson #SecureByDesign
… Making it
Secure by Design
OWASP:
• Injection Flaw
• Cross-site scripting (XSS)
Seals lots of small holes
https://flic.kr/p/85qctm
https://creativecommons.org/licenses/by/2.0/
Confidentiality
Integrity
Availability
@DanielDeogun @danbjson #SecureByDesign
Design secure
software without
“thinking” about
security
There’s a Book…
Shameless plug…
A lot of good design
patterns
Still in Early Access
@DanielDeogun @danbjson #SecureByDesign
Key Take Aways
Domain Primitives
- are native to your domain
- form a conceptual whole
- easy way to improve and secure existing code
Thanks
@DanielDeogun @danbjson #SecureByDesign
https://www.studentkonferens.omegapoint.se

More Related Content

Similar to Domain Primitives in Action - DataTjej 2018

Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
Fast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDBFast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDBMongoDB
 
Devoxx BE - How to fail at benchmarking
Devoxx BE - How to fail at benchmarkingDevoxx BE - How to fail at benchmarking
Devoxx BE - How to fail at benchmarkingPierre Laporte
 
Designing software with security in mind?
Designing software with security in mind?Designing software with security in mind?
Designing software with security in mind?Omegapoint Academy
 
Data Mining Open Ap Is
Data Mining Open Ap IsData Mining Open Ap Is
Data Mining Open Ap Isoscon2007
 
Rubyconf2016 - Solving communication problems in distributed teams with BDD
Rubyconf2016 - Solving communication problems in distributed teams with BDDRubyconf2016 - Solving communication problems in distributed teams with BDD
Rubyconf2016 - Solving communication problems in distributed teams with BDDRodrigo Urubatan
 
Designing software with security in mind
Designing software with security in mindDesigning software with security in mind
Designing software with security in mindOmegapoint Academy
 
Practical Machine Learning
Practical Machine LearningPractical Machine Learning
Practical Machine LearningDavid Jones
 
Introduction to Domain-Driven Design in Ruby on Rails
Introduction to Domain-Driven Design in Ruby on RailsIntroduction to Domain-Driven Design in Ruby on Rails
Introduction to Domain-Driven Design in Ruby on RailsVisuality
 
Devoxx: Event storming a DDD/MicroService landscape using post-it's and markers
Devoxx: Event storming a DDD/MicroService landscape using post-it's and markersDevoxx: Event storming a DDD/MicroService landscape using post-it's and markers
Devoxx: Event storming a DDD/MicroService landscape using post-it's and markersstijn vanpoucke
 
Codemotion Berlin 2018 - AI with a devops mindset: experimentation, sharing a...
Codemotion Berlin 2018 - AI with a devops mindset: experimentation, sharing a...Codemotion Berlin 2018 - AI with a devops mindset: experimentation, sharing a...
Codemotion Berlin 2018 - AI with a devops mindset: experimentation, sharing a...Thiago de Faria
 
Thiago de Faria - AI with a devops mindset - experimentation, sharing and eas...
Thiago de Faria - AI with a devops mindset - experimentation, sharing and eas...Thiago de Faria - AI with a devops mindset - experimentation, sharing and eas...
Thiago de Faria - AI with a devops mindset - experimentation, sharing and eas...Codemotion
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeWim Godden
 
DDD beyond the infamous repository pattern - GeeCon Prague 2018
DDD beyond the infamous repository pattern - GeeCon Prague 2018DDD beyond the infamous repository pattern - GeeCon Prague 2018
DDD beyond the infamous repository pattern - GeeCon Prague 2018Cyrille Martraire
 
Tales from the Field
Tales from the FieldTales from the Field
Tales from the FieldMongoDB
 
Geek Sync | Rewriting Bad SQL Code 101
Geek Sync | Rewriting Bad SQL Code 101Geek Sync | Rewriting Bad SQL Code 101
Geek Sync | Rewriting Bad SQL Code 101IDERA Software
 
Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.Ravi Teja
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Ddd reboot (english version)
Ddd reboot (english version)Ddd reboot (english version)
Ddd reboot (english version)Thomas Pierrain
 

Similar to Domain Primitives in Action - DataTjej 2018 (20)

Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Fast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDBFast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDB
 
Devoxx BE - How to fail at benchmarking
Devoxx BE - How to fail at benchmarkingDevoxx BE - How to fail at benchmarking
Devoxx BE - How to fail at benchmarking
 
Designing software with security in mind?
Designing software with security in mind?Designing software with security in mind?
Designing software with security in mind?
 
Data Mining Open Ap Is
Data Mining Open Ap IsData Mining Open Ap Is
Data Mining Open Ap Is
 
Rubyconf2016 - Solving communication problems in distributed teams with BDD
Rubyconf2016 - Solving communication problems in distributed teams with BDDRubyconf2016 - Solving communication problems in distributed teams with BDD
Rubyconf2016 - Solving communication problems in distributed teams with BDD
 
Designing software with security in mind
Designing software with security in mindDesigning software with security in mind
Designing software with security in mind
 
Practical Machine Learning
Practical Machine LearningPractical Machine Learning
Practical Machine Learning
 
Introduction to Domain-Driven Design in Ruby on Rails
Introduction to Domain-Driven Design in Ruby on RailsIntroduction to Domain-Driven Design in Ruby on Rails
Introduction to Domain-Driven Design in Ruby on Rails
 
Devoxx: Event storming a DDD/MicroService landscape using post-it's and markers
Devoxx: Event storming a DDD/MicroService landscape using post-it's and markersDevoxx: Event storming a DDD/MicroService landscape using post-it's and markers
Devoxx: Event storming a DDD/MicroService landscape using post-it's and markers
 
Codemotion Berlin 2018 - AI with a devops mindset: experimentation, sharing a...
Codemotion Berlin 2018 - AI with a devops mindset: experimentation, sharing a...Codemotion Berlin 2018 - AI with a devops mindset: experimentation, sharing a...
Codemotion Berlin 2018 - AI with a devops mindset: experimentation, sharing a...
 
Thiago de Faria - AI with a devops mindset - experimentation, sharing and eas...
Thiago de Faria - AI with a devops mindset - experimentation, sharing and eas...Thiago de Faria - AI with a devops mindset - experimentation, sharing and eas...
Thiago de Faria - AI with a devops mindset - experimentation, sharing and eas...
 
Clean Code 2
Clean Code 2Clean Code 2
Clean Code 2
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the code
 
DDD beyond the infamous repository pattern - GeeCon Prague 2018
DDD beyond the infamous repository pattern - GeeCon Prague 2018DDD beyond the infamous repository pattern - GeeCon Prague 2018
DDD beyond the infamous repository pattern - GeeCon Prague 2018
 
Tales from the Field
Tales from the FieldTales from the Field
Tales from the Field
 
Geek Sync | Rewriting Bad SQL Code 101
Geek Sync | Rewriting Bad SQL Code 101Geek Sync | Rewriting Bad SQL Code 101
Geek Sync | Rewriting Bad SQL Code 101
 
Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Ddd reboot (english version)
Ddd reboot (english version)Ddd reboot (english version)
Ddd reboot (english version)
 

More from Omegapoint Academy

Domain Driven Security Jfokus 2016
Domain Driven Security Jfokus 2016Domain Driven Security Jfokus 2016
Domain Driven Security Jfokus 2016Omegapoint Academy
 
Arm yourself with Domain Driven Security. It's time to slay some security trolls
Arm yourself with Domain Driven Security. It's time to slay some security trollsArm yourself with Domain Driven Security. It's time to slay some security trolls
Arm yourself with Domain Driven Security. It's time to slay some security trollsOmegapoint Academy
 
Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015Omegapoint Academy
 
Studentkonferens 2015 - Alla pratar om risker, men vad är det?
Studentkonferens 2015 - Alla pratar om risker, men vad är det?Studentkonferens 2015 - Alla pratar om risker, men vad är det?
Studentkonferens 2015 - Alla pratar om risker, men vad är det?Omegapoint Academy
 
Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)
Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)
Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)Omegapoint Academy
 
Studenkonferens 2015 - Craftsmanship
Studenkonferens 2015 - CraftsmanshipStudenkonferens 2015 - Craftsmanship
Studenkonferens 2015 - CraftsmanshipOmegapoint Academy
 
Agile Enterprise: frukostseminarium
Agile Enterprise: frukostseminariumAgile Enterprise: frukostseminarium
Agile Enterprise: frukostseminariumOmegapoint Academy
 

More from Omegapoint Academy (8)

Designing Testable Software
Designing Testable SoftwareDesigning Testable Software
Designing Testable Software
 
Domain Driven Security Jfokus 2016
Domain Driven Security Jfokus 2016Domain Driven Security Jfokus 2016
Domain Driven Security Jfokus 2016
 
Arm yourself with Domain Driven Security. It's time to slay some security trolls
Arm yourself with Domain Driven Security. It's time to slay some security trollsArm yourself with Domain Driven Security. It's time to slay some security trolls
Arm yourself with Domain Driven Security. It's time to slay some security trolls
 
Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015
 
Studentkonferens 2015 - Alla pratar om risker, men vad är det?
Studentkonferens 2015 - Alla pratar om risker, men vad är det?Studentkonferens 2015 - Alla pratar om risker, men vad är det?
Studentkonferens 2015 - Alla pratar om risker, men vad är det?
 
Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)
Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)
Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)
 
Studenkonferens 2015 - Craftsmanship
Studenkonferens 2015 - CraftsmanshipStudenkonferens 2015 - Craftsmanship
Studenkonferens 2015 - Craftsmanship
 
Agile Enterprise: frukostseminarium
Agile Enterprise: frukostseminariumAgile Enterprise: frukostseminarium
Agile Enterprise: frukostseminarium
 

Recently uploaded

why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 

Recently uploaded (20)

why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 

Domain Primitives in Action - DataTjej 2018

  • 1. Domain Primitives in Action - Making it Secure by Design @DanielDeogun @danbjson DataTjej February 15, 2018
  • 2. @DanielDeogun @danbjson #SecureByDesign About Us… Dan Bergh Johnsson Secure Domain Philosopher Omegapoint, Sweden Umeå Malmö Göteborg Falun New York Stockholm Daniel Deogun Coder and Quality Defender
  • 3. @DanielDeogun @danbjson #SecureByDesign Key Take Aways Domain Primitives - are native to your domain - form a conceptual whole - easy way to improve and secure existing code
  • 4. @DanielDeogun @danbjson #SecureByDesign Agenda • A Bank Robbery • Secure by Design • Buying -1 Books • Room Numbers • Domain Primitives • Domain Primitives Applied on Legacy
  • 5. @DanielDeogun @danbjson #SecureByDesign A Bank Robbery image: Smådisigt Medlemsblad för DIS-Småland
  • 6. @DanielDeogun @danbjson #SecureByDesign Secure by Design “A mindset and strategy for creating secure software by focusing on good design” - Secure by Design
  • 7. @DanielDeogun @danbjson #SecureByDesign Buying -1 books [1] 1 Secure by Design $49.99 -1 Hamlet $40.50 1 Hitchhiker's Guide to the Galaxy $30.00 Shopping Cart Total $39.49
  • 8. @DanielDeogun @danbjson #SecureByDesign Analysis -1 : Integer -1 : Integer OrderLine {ISBN, -1} Math Context Webshop Context
  • 9. @DanielDeogun @danbjson #SecureByDesign But Quantity is “just” an integer… Quantity • a concept that’s well defined with strict boundaries • not closed under addition • cannot be negative Peano's Axioms 1. Zero is a number 2. If n is a number, the successor of n is a number 3. Zero isn’t the successor of a number 4. Two numbers of which the successors are equal are themselves equal 5. If a set S of numbers contains zero and also the successor of every number in S, then every number is in S Abelian Group • Closure: a + b = integer • Associativity: a + (b + c) = (a + b) + c • Commutativity: a + b = b + a • Identity: a + 0 = a • Inverse: a + (−a) = 0 🤔
  • 10. @DanielDeogun @danbjson #SecureByDesign …or is Quantity a String? • What characters are legal? • Which operations are allowed? • Does this make sense?
  • 12. @DanielDeogun @danbjson #SecureByDesign But Room Number is “just” an Integer… 🤔Peano's Axioms 1. Zero is a number 2. If n is a number, the successor of n is a number 3. Zero isn’t the successor of a number 4. Two numbers of which the successors are equal are themselves equal 5. If a set S of numbers contains zero and also the successor of every number in S, then every number is in S Abelian Group • Closure: a + b = integer • Associativity: a + (b + c) = (a + b) + c • Commutativity: a + b = b + a • Identity: a + 0 = a • Inverse: a + (−a) = 0
  • 13. @DanielDeogun @danbjson #SecureByDesign …or is Room Number a String? • What characters are legal? • Which operations are allowed? • Does this make sense?
  • 14. @DanielDeogun @danbjson #SecureByDesign Domain Primitives “A value object so precise in its definition that it, by its mere existence, manifests its validity is called a Domain Primitive.” - Secure by Design • Can only exist if its value is valid • Building block that’s native to your domain • Valid in the current context • Immutable and resemble a value object in DDD
  • 15. @DanielDeogun @danbjson #SecureByDesign Math and Hotel are different Contexts Math Domain Integer Hotel Domain Room Number Hotel Domain Math Domain Integer (a.k.a Room Number) Domain Primitive
  • 16. @DanielDeogun @danbjson #SecureByDesign Math and Webshop are different Contexts Math Domain Integer Webshop Domain Quantity Webshop Math Domain Integer (a.k.a Quantity) Domain Primitive
  • 17. @DanielDeogun @danbjson #SecureByDesign Quantity as a Domain Primitive public final class Quantity { private final int value; public Quantity(final int value) { inclusiveBetween(1, 99, value); this.value = value; } //Domain specific quantity operations... }
  • 18. @DanielDeogun @danbjson #SecureByDesign Room Number as a Domain Primitive public final class RoomNumber { private final int value; public RoomNumber(final int value) { isTrue(Floor.isValid(value)); inclusiveBetween(1, 50, value % 100); this.value = value; } public Floor floor() { return new Floor(value); } // other logic … }
  • 19. @DanielDeogun @danbjson #SecureByDesign Invalid quantities are rejected by Definition! -1 : Integer Quantity: {1 - 99} OrderLine {ISBN, Quantity} Math Context Webshop Context Only valid quantities are accepted Rejected
  • 20. @DanielDeogun @danbjson #SecureByDesign Less Simple Domain Primitive public void pay(final double money, final int recipientId) { final String currency = CurrencyService.currencyFor(recipientId); BankService.transfer(money, currency, recipientId); } public void pay(final Money money, final Recipient recipient) { notNull(money); notNull(recipient); BankService.transfer(money, recipient); } But Money is a conceptual whole and should be modeled as a domain primitive
  • 21. @DanielDeogun @danbjson #SecureByDesign Intelligent Machines - not just values class Rate {
 private final Currency from;
 private final Currency to;
 
 Rate(Currency from, Currency to) {
 this.from = notNull(from);
 this.to = notNull(to);
 } 
 Money exchange(Money from) { notNull(from); isTrue(this.from .equals(from.currency)); BigDecimal converted = . . .
 return new Money(converted, to);
 }
 }
  • 22. @DanielDeogun @danbjson #SecureByDesign Standing on the Shoulders of Giants • Domain Primitives act as building blocks • Guy L. Steele Jr. “Growing a Language” • Abelson, Sussman “Structure and Interpretation of Computer Programs” https://flic.kr/p/8cc44h https://creativecommons.org/licenses/by/2.0/
  • 23. @DanielDeogun @danbjson #SecureByDesign Domain Primitives in Action on Legacy https://flic.kr/p/Q7zV https://creativecommons.org/licenses/by-sa/2.0/ vs https://flic.kr/p/djYc9H https://creativecommons.org/licenses/by/2.0/ Green Field Brown Field
  • 24. @DanielDeogun @danbjson #SecureByDesign Three Steps https://flic.kr/p/wdBcT https://creativecommons.org/licenses/by/2.0/ Untangle insideDraw the line Harden your API https://flic.kr/p/YgfS6s https://creativecommons.org/licenses/by/2.0/ https://flic.kr/p/nEZKMd https://creativecommons.org/licenses/by/2.0/
  • 25. @DanielDeogun @danbjson #SecureByDesign “Draw the Line” - Find a Semantic Border • We need to identify the semantic boundary of a context • Add a layer that internally translates data to a domain primitive and the back again data -> domain primitive -> data • This way, we have created a validation boundary that protects the inside from bad input • But, if rejecting data is to harsh, consider logging it for insight https://flic.kr/p/nEZKMd https://creativecommons.org/licenses/by/2.0/ public void checkout(final int roomNumber) { new RoomNumber(roomNumber); //throws exception if invalid houseKeepingService.registerForCleaning(roomNumber); minibarService.replenish(roomNumber); // other operations ... } public void checkout(final int roomNumber) { if (!RoomNumber.isValid(roomNumber)) { reporter.logInvalidRoomNumber(roomNumber); } houseKeepingService.registerForCleaning(roomNumber); minibarService.replenish(roomNumber); // other operations ... }
  • 26. @DanielDeogun @danbjson #SecureByDesign Harden your API - Enforce Data Quality Generic Specific public void checkout(final int roomNumber) public void checkout(final RoomNumber roomNumber) Enforce data quality https://flic.kr/p/YgfS6s https://creativecommons.org/licenses/by/2.0/
  • 27. @DanielDeogun @danbjson #SecureByDesign Untangle Inside - Cluttered Entity https://flic.kr/p/wdBcT https://creativecommons.org/licenses/by/2.0/ class Order { private ArrayList<Object> items; private boolean paid;
 
 public void addItem(String isbn, int qty) { if(this.paid == false) { notNull(isbn); inclusiveBetween(10, 10, isbn.length()); isTrue(isbn.matches("[0-9X]*")); isTrue(isbn.matches("[0-9]{9}[0-9X]"));
 Book book = bookCatalogue.findByISBN(isbn);
 if (inventory.availableBooks(isbn) >= qty) { items.add(new OrderLine(book, qty)); } } } //Other logic... }
  • 28. @DanielDeogun @danbjson #SecureByDesign De-Cluttered Entity class Order { private ArrayList<Object> items; private boolean paid;
 public void addItem(ISBN isbn, Quantity qty) { notNull(isbn); notNull(qty); if(this.paid == false) { Book book = bookCatalogue.findByISBN(isbn);
 if (inventory.availableBooks(isbn).greaterOrEqualTo(qty)) { items.add(new OrderLine(book, qty)); } } } //Other logic... } https://flic.kr/p/wdBcT https://creativecommons.org/licenses/by/2.0/
  • 29. @DanielDeogun @danbjson #SecureByDesign But… https://flic.kr/p/eGYhMw https://creativecommons.org/licenses/by/2.0/ … what about performance? https://flic.kr/p/2pvb2T https://creativecommons.org/licenses/by/2.0/ … it becomes a lot of classes! … isn’t it overly complex? https://flic.kr/p/7Ro4HU https://creativecommons.org/licenses/by/2.0/
  • 30. @DanielDeogun @danbjson #SecureByDesign … Making it Secure by Design OWASP: • Injection Flaw • Cross-site scripting (XSS) Seals lots of small holes https://flic.kr/p/85qctm https://creativecommons.org/licenses/by/2.0/ Confidentiality Integrity Availability
  • 31. @DanielDeogun @danbjson #SecureByDesign Design secure software without “thinking” about security There’s a Book… Shameless plug… A lot of good design patterns Still in Early Access
  • 32. @DanielDeogun @danbjson #SecureByDesign Key Take Aways Domain Primitives - are native to your domain - form a conceptual whole - easy way to improve and secure existing code