SlideShare a Scribd company logo
1 of 46
Download to read offline
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Secure by Design
Daniel & Daniel

@DanielDeogun @DanielSawano
DevDays, Vilnius 2017
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Daniel Deogun Daniel Sawano
About us…
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Secure by Design
Secure by Design is a new approach to
software security that lets you create secure
software while still focusing on business
features.
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Secure by Design
“Any activity involving active decision making
should be considered part of the software design
process and can thus be referred to as design.”
- Johnsson, Deogun, and Sawano
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
What we’ll cover today…
• Domain Primitives
• Entity Snapshots
• Dealing with Legacy
Code
• Security in your
Pipelines
Design Patterns
Security & tests
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Domain Primitives
A value object so precise in its definition that
it, by its mere existence, manifests its validity
is called a domain primitive.
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Domain Primitives
• A Domain Primitive is very strict in its definition
• If it’s not valid then it cannot exist
• Defined in the current domain
• It’s preciseness brings robustness in your code
• It’s immutable so it will always be valid
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Domain Primitives
import static org.apache.commons.lang3.Validate.inclusiveBetween;
import static org.apache.commons.lang3.Validate.notNull;
public final class Quantity {
private final int value;
public Quantity(final int value) {
inclusiveBetween(1, 200, value);
this.value = value;
}
public int value() {
return value;
}
public Quantity add(final Quantity addend) {
notNull(addend);
return new Quantity(value + addend.value);
}
// ...
}
Quantity is not just
an int!
• Enforces
invariants at
creation
• Provides domain
operations to
• Encapsulate
domain behavior
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
CIA
• Confidentiality - protecting data from being
read by unauthorized users
• Integrity - ensures data is changed in an
authorized way
• Availability - concerns having data available
when authorized users need it
[11]
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Domain Primitives
import static org.apache.commons.lang3.Validate.inclusiveBetween;
import static org.apache.commons.lang3.Validate.notNull;
public final class Quantity {
private final int value;
public Quantity(final int value) {
inclusiveBetween(1, 200, value);
this.value = value;
}
public int value() {
return value;
}
public Quantity add(final Quantity addend) {
notNull(addend);
return new Quantity(value + addend.value);
}
// ...
}
Quantity is not just
an int!
• Enforces
invariants at
creation
• Provides domain
operations to
• Encapsulate
domain behavior
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Domain Primitives
External context
Your context
Email
Email
Defined by RFC
Defined by you
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Domain Primitives
Use Domain Primitives as:
• the smallest building block in your domain model
• to build your Domain Primitive Library
• to harden your code and your APIs
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
What we’ll cover today…
✓ Domain Primitives
• Entity Snapshots
• Dealing with Legacy
Code
• Security in your
Pipelines
Design Patterns
Security & tests
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Entities
• An entity has an identity that doesn’t change over
time
• The values/data belonging to an entity can change
over time
• Typically modeled as mutable objects
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Classic Entity
public final class Order {
private final OrderId id;
private final List<OrderItem> orderItems = new ArrayList<>();
public Order(final OrderId id) {
this.id = notNull(id);
}
public void addItem(final OrderItem item) {
notNull(item);
orderItems.add(item);
}
// ...
}
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Perils of mutable state
• Mutability is a source of security issues
• Consistency in the presence of contention is hard
• Contention can reduce availability
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Entity Snapshots
Entity Snapshots are:
• Securing mutable state by making it immutable
• An immutable representation of a mutable entity
• Solves many of the security problems with regular
entities
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Entity Snapshots
public final class Order {
private final OrderId id;
private final List<OrderItem> orderItems;
public Order(final OrderId id, final List<OrderItem> orderItems) {
noNullElements(orderItems);
notNull(id);
this.id = id;
this.orderItems = unmodifiableList(new ArrayList<>(orderItems));
}
public List<OrderItem> orderItems() {
return orderItems;
}
// ...
}
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Entity Snapshots
public final class WritableOrder {
private final OrderId id;
private final OrderRepository repository;
public WritableOrder(final OrderId id, final OrderRepository repository) {
this.id = notNull(id);
this.repository = notNull(repository);
}
public void addOrderItem(final OrderItem orderItem) {
notNull(orderItem);
isOkToAdd(orderItem);
repository.addItemToOrder(id, orderItem);
}
private void isOkToAdd(final OrderItem orderItem) {
// domain validation logic to ensure it's ok to add order
}
}
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
What we’ll cover today…
✓ Domain Primitives
✓ Entity Snapshots
• Dealing with Legacy
Code
• Security in your
Pipelines
Design Patterns
Security & tests
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Dealing with Legacy Code
3 good design patterns
[6]
Declutter EntitiesHarden your APIsDraw the Line
[7] [8]
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
“Draw the Line”
[6]
• 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
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
“Harden the API”
• Create a library of domain primitives
• Express your APIs with your domain primitives
• Never accept generic input if you have
specific requirements
Generic Specific
[7]
void buyBook(ISBN, Quantity)void buyBook(String, int)
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
“Decluttering Entities”
[8]
import static org.apache.commons.lang3.Validate.notNull;
import static org.apache.commons.lang3.Validate.isTrue;
public class Order {



private final List<Object> items;

private boolean paid;



public void addItem(String isbn, int qty) {

if (this.paid == false) {

notNull(isbn);

isTrue(isbn.length() == 10);

isTrue(isbn.matches("[0-9X]*"));

isTrue(isbn.matches(“[0-9]{9}[0-9X]”));
if (inventory.avaliableBooks(isbn, qty)) {
Book book = bookcatalogue.findBy(isbn);

items.add(new OrderLine(book, qty));

}

}

}
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
“Decluttering Entities”
[8]
import static org.apache.commons.lang3.Validate.notNull;
import static org.apache.commons.lang3.Validate.isTrue;
public class Order {



private final List<Object> items;

private boolean paid;



public void addItem(final ISBN isbn,
final Quantity quantity) {
notNull(isbn);
notNull(quantity);
isTrue(notPaid());
if (inventory.avaliableBooks(isbn, quantity)) {
Book book = bookcatalogue.findBy(isbn);

items.add(new OrderLine(book, quantity));

}

}
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
What we’ll cover today…
✓ Domain Primitives
✓ Entity Snapshots
✓ Dealing with Legacy
Code
• Security in your
Pipelines
Design Patterns
Security & tests
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Security in your Pipelines
[10]
[12]
- Unit testing
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
The Hospital Case
[9]
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Email Domain Primitive
External context
Your context
Email
Email
Defined by RFC
Defined by you
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
The Domain Rules
• The format of an email address must be local-part@domain
• The local part cannot be longer than 64 characters
• The domain must be hospital.com
• Subdomains are not accepted
• The minimum length of an email address is 15 characters
• The maximum length of an email address is 77 characters
• The local part may only contain alphabetic characters (a-z), digits (0-9),
and one period
• The local part may not start or end by a period
[5]
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Testing Normal Behavior
• Focus on input that clearly meets the domain rules
class EmailAddressTest {
@TestFactory
Stream<DynamicTest> should_be_a_valid_address() {
return Stream.of(
"jane@hospital.com",
"jane01@hospital.com",
"jane.doe@hospital.com")
.map(input -> dynamicTest("Accepted: " + input,
() -> new EmailAddress(input)));
}
}
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
1st
version of EmailAddress
public final class EmailAddress {
public final String value;
public EmailAddress(final String value) {
matchesPattern(value.toLowerCase(),
"^[a-z0-9]+.?[a-z0-9]+@bhospital.com$");
this.value = value.toLowerCase();
}
...
}
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Testing Boundary Behavior
- Acceptance
• Accept an address that's exactly 15 characters long.
• Accept an address with a local part that's 64 characters long.
• Accept an address that's exactly 77 characters long.
@TestFactory
Stream<DynamicTest> should_be_accepted() {
return Stream.of(
"aa@hospital.com",
repeat("X", 64) + "@hospital.com")
.map(input -> dynamicTest("Accepted: " + input,
() -> new EmailAddress(input)));
}
Email
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Testing Boundary Behavior
- Rejection
• Reject an address that's 14 characters long
• Reject an address with a local part that's 65 characters long
• Reject an address with a local part containing an invalid character
• Reject an address with multiple '@' symbols
• Reject an address with a domain other than hospital.com
• Reject an address with a subdomain
• Reject an address with a local part that starts with a period
• Reject an address with a local part that ends with a period
• Reject an address with sequential periods in the local part
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Testing Boundary Behavior
- Rejection
@TestFactory
Stream<DynamicTest> should_be_rejected() {
return Stream.of(
"a@hospital.com",
repeat("X", 65) + "@hospital.com",
"address_with_invalid_char_in_local_part@hospital.com",
"jane@doe@hospital.com",
"jane.doe@hospital.lt",
"jane.doe@hospital.io",
"jane.doe@hospital.gov",
"jane.doe@example.com",
"jane.doe@cardio.hospital.com",
".jane.doe@hospital.com",
"jane.doe.@hospital.com",
"jane..doe@hospital.com")
.map(input -> dynamicTest("Rejected: " + input,
assertInvalidEmail(input)));
}
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
2nd
version of EmailAddress
public final class EmailAddress {
public final String value;
public EmailAddress(final String value) {
matchesPattern(value.toLowerCase(),
"^(?=[a-z0-9.@]{15,77}$)[a-z0-9]+.?[a-z0-9]+@bhospital.com$");
this.value = value.toLowerCase();
}
...
}
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Testing with Invalid Input
• Any input that doesn't satisfy the domain rules
is considered invalid
• For some reason, `null`, empty strings, or
"strange" characters tend to result in
unexpected behavior
Email
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Testing with Invalid Input
@TestFactory
Stream<DynamicTest> should_reject_invalid_input() {
return Stream.of(
null,
"null",
"nil",
"0",
"",
" ",
"t",
"n",
"john.doen@hospital.com",
" @hospital.com",
"%20@hospital.com",
"john.d%20e@hospital.com",
"john.doe.jane@hospital.com",
"--",
"e x a m p l e @ hospital . c o m",
"=0@$*^%;<!->.:()&#"")
.map(input -> dynamicTest("Rejected: " + input,
assertInvalidEmail(input)));
}
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
3rd version of EmailAddress
public final class EmailAddress {
public final String value;
public EmailAddress(final String value) {
notNull(value, "Input cannot be null");
matchesPattern(value.toLowerCase(),
"^(?=[a-z0-9.@]{15,77}$)[a-z0-9]+.?[a-z0-9]+@bhospital.com$");
this.value = value.toLowerCase();
}
...
}
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Testing with Extreme Input
• Testing the extreme is all about identifying weaknesses in the
design that makes the application break or behave strangely
when handling extreme values.
@TestFactory
Stream<DynamicTest> should_reject_extreme_input() {
return Stream.<Supplier<String>>of(
() -> repeat("x", 10000),
() -> repeat("x", 100000),
() -> repeat("x", 1000000),
() -> repeat("x", 10000000),
() -> repeat("x", 20000000),
() -> repeat("x", 40000000))
.map(input -> dynamicTest("Rejecting extreme input",
assertInvalidEmail(input.get())));
}
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Security weaknesses caused by
inefficient backtracking
v.s
"^[a-z0-9]+.?[a-z0-9]+@bhospital.com$"
"^(?=[a-z0-9.@]{15,77}$)[a-z0-9]+.?[a-z0-9]+@bhospital.com$"
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
What we have covered…
✓ Domain Primitives
✓ Entity Snapshots
✓ Dealing with Legacy
Code
✓ Security in your
Pipelines
Design Patterns
Security & tests
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
URL https://manning.com
Discount code: ctwdevdays
Part 1: Introduction
1. Why Design Matters for Security
2. Case-Study: An Anti-Hamlet for sale
Part 2: Fundamentals
3. Core concepts of Domain Driven Design
4. Code Constructs Promoting Security
5. Securing mutable state
6. Leveraging your delivery pipeline for security
7. Handling failures in a secure way
8. Case-study: Insurance policy for free
9. Integrating system of systems with security in mind
10. Benefits from cloud thinking
Part 3: Applying the Fundamentals
11. Getting a fresh start in a legacy codebase
12. The subtle issues in a pretty monolith
13. Getting microservices right for security
14. A final word: don’t forget about security
[1]
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Q&A
[2]
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
Thank you!

@DanielSawano @DanielDeogun
@DanielDeogun @DanielSawano DevDays 2017, Vilnius
References
[1] Book cover, Secure by Design, Manning Publication
[2] Question mark, https://flic.kr/p/9ksxQa by Damián Navas under license https://creativecommons.org/licenses/by-nc-nd/2.0/
[3] DDos Attack, Secure by Design, Manning Publication
[4] Uber vs Ola, https://www.bloomberg.com/news/articles/2016-03-23/uber-sues-ola-claiming-fake-bookings-as-india-fight-escalates
[5] Lyft vs Uber, http://time.com/3102548/lyft-uber-cancelling-rides/
[6] Boundary, https://flic.kr/p/nEZKMd by Graeme Fowler under license https://creativecommons.org/licenses/by/2.0/
[7] 3d key, https://flic.kr/p/e9qfrf by Yoel Ben-Avraham under license https://creativecommons.org/licenses/by-nd/2.0/
[8] Building blocks, https://flic.kr/p/agPw7C by Tiffany Terry under license https://creativecommons.org/licenses/by/2.0/
[9] Doctors Stock Photo, https://flic.kr/p/HNJUzV, by Sergio Santos under license https://creativecommons.org/licenses/by/2.0/
[10] Anonymous, https://flic.kr/p/a2eniw, by Lio Leiser under license https://creativecommons.org/licenses/by-nd/2.0/
[11] CIA, https://goo.gl/images/DRzRcp
[12] Bilfinger - Natural gas pipeline USA, https://flic.kr/p/nrFHFz by Bilfinger SE under license https://creativecommons.org/licenses/by-nd/2.0/

More Related Content

Similar to DevDays LT 2017 - Secure by Design

Devoxx PL 2017 - Cracking the Code to Secure Software
Devoxx PL 2017 - Cracking the Code to Secure SoftwareDevoxx PL 2017 - Cracking the Code to Secure Software
Devoxx PL 2017 - Cracking the Code to Secure SoftwareDaniel Sawano
 
GeeCon Prague 2017 - Cracking the Code to Secure Software
GeeCon Prague 2017 - Cracking the Code to Secure SoftwareGeeCon Prague 2017 - Cracking the Code to Secure Software
GeeCon Prague 2017 - Cracking the Code to Secure SoftwareDaniel Sawano
 
NoSQL Endgame JCON Conference 2020
NoSQL Endgame JCON Conference 2020NoSQL Endgame JCON Conference 2020
NoSQL Endgame JCON Conference 2020Thodoris Bais
 
NoSQL Endgame LWJUG 2021
NoSQL Endgame LWJUG 2021NoSQL Endgame LWJUG 2021
NoSQL Endgame LWJUG 2021Thodoris Bais
 
Domain Primitives In Action - Explore DDD 2017
Domain Primitives In Action - Explore DDD 2017Domain Primitives In Action - Explore DDD 2017
Domain Primitives In Action - Explore DDD 2017Omegapoint Academy
 
"DOKU under the hood : Infrastructure and Cloud Services Technology" by M. T...
"DOKU under the hood :  Infrastructure and Cloud Services Technology" by M. T..."DOKU under the hood :  Infrastructure and Cloud Services Technology" by M. T...
"DOKU under the hood : Infrastructure and Cloud Services Technology" by M. T...Tech in Asia ID
 
Domain Primitives in Action - DataTjej 2018
Domain Primitives in Action - DataTjej 2018Domain Primitives in Action - DataTjej 2018
Domain Primitives in Action - DataTjej 2018Omegapoint Academy
 
Integrating Security into your Development Pipeline
Integrating Security into your Development PipelineIntegrating Security into your Development Pipeline
Integrating Security into your Development PipelineDevOps.com
 
Decomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservicesDecomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservicesDennis Doomen
 
Making Software Secure by Design
Making Software Secure by DesignMaking Software Secure by Design
Making Software Secure by DesignOmegapoint Academy
 
EclipseCon 2021 NoSQL Endgame
EclipseCon 2021 NoSQL EndgameEclipseCon 2021 NoSQL Endgame
EclipseCon 2021 NoSQL EndgameThodoris Bais
 
20171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v120171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v1Ivan Ma
 
Presentation by Erik van der Hoeven (Wisdom as a Service) at the Data Vault M...
Presentation by Erik van der Hoeven (Wisdom as a Service) at the Data Vault M...Presentation by Erik van der Hoeven (Wisdom as a Service) at the Data Vault M...
Presentation by Erik van der Hoeven (Wisdom as a Service) at the Data Vault M...Patrick Van Renterghem
 
Building autonomous components with OWIN, PSake, NuGet, GitVersion and Swagger
Building autonomous components with OWIN, PSake, NuGet, GitVersion and SwaggerBuilding autonomous components with OWIN, PSake, NuGet, GitVersion and Swagger
Building autonomous components with OWIN, PSake, NuGet, GitVersion and SwaggerDennis Doomen
 
Managing Compliance in Container Environments
Managing Compliance in Container EnvironmentsManaging Compliance in Container Environments
Managing Compliance in Container EnvironmentsTwistlock
 
Building a Consistent Hybrid Cloud Semantic Model In Denodo
Building a Consistent Hybrid Cloud Semantic Model In DenodoBuilding a Consistent Hybrid Cloud Semantic Model In Denodo
Building a Consistent Hybrid Cloud Semantic Model In DenodoDenodo
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Derek Jacoby
 
NoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualNoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualWerner Keil
 

Similar to DevDays LT 2017 - Secure by Design (20)

Devoxx PL 2017 - Cracking the Code to Secure Software
Devoxx PL 2017 - Cracking the Code to Secure SoftwareDevoxx PL 2017 - Cracking the Code to Secure Software
Devoxx PL 2017 - Cracking the Code to Secure Software
 
GeeCon Prague 2017 - Cracking the Code to Secure Software
GeeCon Prague 2017 - Cracking the Code to Secure SoftwareGeeCon Prague 2017 - Cracking the Code to Secure Software
GeeCon Prague 2017 - Cracking the Code to Secure Software
 
NoSQL Endgame JCON Conference 2020
NoSQL Endgame JCON Conference 2020NoSQL Endgame JCON Conference 2020
NoSQL Endgame JCON Conference 2020
 
NoSQL Endgame LWJUG 2021
NoSQL Endgame LWJUG 2021NoSQL Endgame LWJUG 2021
NoSQL Endgame LWJUG 2021
 
Domain Primitives In Action - Explore DDD 2017
Domain Primitives In Action - Explore DDD 2017Domain Primitives In Action - Explore DDD 2017
Domain Primitives In Action - Explore DDD 2017
 
"DOKU under the hood : Infrastructure and Cloud Services Technology" by M. T...
"DOKU under the hood :  Infrastructure and Cloud Services Technology" by M. T..."DOKU under the hood :  Infrastructure and Cloud Services Technology" by M. T...
"DOKU under the hood : Infrastructure and Cloud Services Technology" by M. T...
 
Domain Primitives in Action - DataTjej 2018
Domain Primitives in Action - DataTjej 2018Domain Primitives in Action - DataTjej 2018
Domain Primitives in Action - DataTjej 2018
 
Integrating Security into your Development Pipeline
Integrating Security into your Development PipelineIntegrating Security into your Development Pipeline
Integrating Security into your Development Pipeline
 
Decomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservicesDecomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservices
 
Making Software Secure by Design
Making Software Secure by DesignMaking Software Secure by Design
Making Software Secure by Design
 
EclipseCon 2021 NoSQL Endgame
EclipseCon 2021 NoSQL EndgameEclipseCon 2021 NoSQL Endgame
EclipseCon 2021 NoSQL Endgame
 
NoSQL with Mongodb
NoSQL with MongodbNoSQL with Mongodb
NoSQL with Mongodb
 
20171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v120171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v1
 
mlearn-qaas
mlearn-qaasmlearn-qaas
mlearn-qaas
 
Presentation by Erik van der Hoeven (Wisdom as a Service) at the Data Vault M...
Presentation by Erik van der Hoeven (Wisdom as a Service) at the Data Vault M...Presentation by Erik van der Hoeven (Wisdom as a Service) at the Data Vault M...
Presentation by Erik van der Hoeven (Wisdom as a Service) at the Data Vault M...
 
Building autonomous components with OWIN, PSake, NuGet, GitVersion and Swagger
Building autonomous components with OWIN, PSake, NuGet, GitVersion and SwaggerBuilding autonomous components with OWIN, PSake, NuGet, GitVersion and Swagger
Building autonomous components with OWIN, PSake, NuGet, GitVersion and Swagger
 
Managing Compliance in Container Environments
Managing Compliance in Container EnvironmentsManaging Compliance in Container Environments
Managing Compliance in Container Environments
 
Building a Consistent Hybrid Cloud Semantic Model In Denodo
Building a Consistent Hybrid Cloud Semantic Model In DenodoBuilding a Consistent Hybrid Cloud Semantic Model In Denodo
Building a Consistent Hybrid Cloud Semantic Model In Denodo
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9
 
NoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualNoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 Virtual
 

More from Daniel Sawano

Devoxx PL 2016 - Beyond Lambdas, the Aftermath
Devoxx PL 2016 - Beyond Lambdas, the AftermathDevoxx PL 2016 - Beyond Lambdas, the Aftermath
Devoxx PL 2016 - Beyond Lambdas, the AftermathDaniel Sawano
 
GeeCon 2016 - Beyond Lambdas, the Aftermath
GeeCon 2016 - Beyond Lambdas, the AftermathGeeCon 2016 - Beyond Lambdas, the Aftermath
GeeCon 2016 - Beyond Lambdas, the AftermathDaniel Sawano
 
Spotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the AftermathSpotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the AftermathDaniel Sawano
 
JDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the AftermathJDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the AftermathDaniel Sawano
 
JFokus 2016 - Beyond Lambdas - the Aftermath
JFokus 2016 - Beyond Lambdas - the AftermathJFokus 2016 - Beyond Lambdas - the Aftermath
JFokus 2016 - Beyond Lambdas - the AftermathDaniel Sawano
 
Devoxx, MA, 2015, Failing Continuous Delivery
Devoxx, MA, 2015, Failing Continuous DeliveryDevoxx, MA, 2015, Failing Continuous Delivery
Devoxx, MA, 2015, Failing Continuous DeliveryDaniel Sawano
 
Failing Continuous Delivery, Agile Prague 2015
Failing Continuous Delivery, Agile Prague 2015Failing Continuous Delivery, Agile Prague 2015
Failing Continuous Delivery, Agile Prague 2015Daniel Sawano
 
Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015Daniel Sawano
 
Things Every Professional Programmer Should Know
Things Every Professional Programmer Should KnowThings Every Professional Programmer Should Know
Things Every Professional Programmer Should KnowDaniel Sawano
 
Failing Continuous Delivery, JDays, 2015
Failing Continuous Delivery, JDays, 2015Failing Continuous Delivery, JDays, 2015
Failing Continuous Delivery, JDays, 2015Daniel Sawano
 
Reactive Programming With Akka - Lessons Learned
Reactive Programming With Akka - Lessons LearnedReactive Programming With Akka - Lessons Learned
Reactive Programming With Akka - Lessons LearnedDaniel Sawano
 

More from Daniel Sawano (12)

Devoxx PL 2016 - Beyond Lambdas, the Aftermath
Devoxx PL 2016 - Beyond Lambdas, the AftermathDevoxx PL 2016 - Beyond Lambdas, the Aftermath
Devoxx PL 2016 - Beyond Lambdas, the Aftermath
 
GeeCon 2016 - Beyond Lambdas, the Aftermath
GeeCon 2016 - Beyond Lambdas, the AftermathGeeCon 2016 - Beyond Lambdas, the Aftermath
GeeCon 2016 - Beyond Lambdas, the Aftermath
 
Spotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the AftermathSpotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the Aftermath
 
JDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the AftermathJDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the Aftermath
 
JFokus 2016 - Beyond Lambdas - the Aftermath
JFokus 2016 - Beyond Lambdas - the AftermathJFokus 2016 - Beyond Lambdas - the Aftermath
JFokus 2016 - Beyond Lambdas - the Aftermath
 
Devoxx, MA, 2015, Failing Continuous Delivery
Devoxx, MA, 2015, Failing Continuous DeliveryDevoxx, MA, 2015, Failing Continuous Delivery
Devoxx, MA, 2015, Failing Continuous Delivery
 
Failing Continuous Delivery, Agile Prague 2015
Failing Continuous Delivery, Agile Prague 2015Failing Continuous Delivery, Agile Prague 2015
Failing Continuous Delivery, Agile Prague 2015
 
Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015
 
Things Every Professional Programmer Should Know
Things Every Professional Programmer Should KnowThings Every Professional Programmer Should Know
Things Every Professional Programmer Should Know
 
Failing Continuous Delivery, JDays, 2015
Failing Continuous Delivery, JDays, 2015Failing Continuous Delivery, JDays, 2015
Failing Continuous Delivery, JDays, 2015
 
Akka Made Our Day
Akka Made Our DayAkka Made Our Day
Akka Made Our Day
 
Reactive Programming With Akka - Lessons Learned
Reactive Programming With Akka - Lessons LearnedReactive Programming With Akka - Lessons Learned
Reactive Programming With Akka - Lessons Learned
 

Recently uploaded

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
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
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
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...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 

DevDays LT 2017 - Secure by Design

  • 1. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Secure by Design Daniel & Daniel
 @DanielDeogun @DanielSawano DevDays, Vilnius 2017
  • 2. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Daniel Deogun Daniel Sawano About us…
  • 3. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Secure by Design Secure by Design is a new approach to software security that lets you create secure software while still focusing on business features.
  • 4. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Secure by Design “Any activity involving active decision making should be considered part of the software design process and can thus be referred to as design.” - Johnsson, Deogun, and Sawano
  • 5. @DanielDeogun @DanielSawano DevDays 2017, Vilnius What we’ll cover today… • Domain Primitives • Entity Snapshots • Dealing with Legacy Code • Security in your Pipelines Design Patterns Security & tests
  • 6. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Domain Primitives A value object so precise in its definition that it, by its mere existence, manifests its validity is called a domain primitive.
  • 7. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Domain Primitives • A Domain Primitive is very strict in its definition • If it’s not valid then it cannot exist • Defined in the current domain • It’s preciseness brings robustness in your code • It’s immutable so it will always be valid
  • 8. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Domain Primitives import static org.apache.commons.lang3.Validate.inclusiveBetween; import static org.apache.commons.lang3.Validate.notNull; public final class Quantity { private final int value; public Quantity(final int value) { inclusiveBetween(1, 200, value); this.value = value; } public int value() { return value; } public Quantity add(final Quantity addend) { notNull(addend); return new Quantity(value + addend.value); } // ... } Quantity is not just an int! • Enforces invariants at creation • Provides domain operations to • Encapsulate domain behavior
  • 9. @DanielDeogun @DanielSawano DevDays 2017, Vilnius CIA • Confidentiality - protecting data from being read by unauthorized users • Integrity - ensures data is changed in an authorized way • Availability - concerns having data available when authorized users need it [11]
  • 10. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Domain Primitives import static org.apache.commons.lang3.Validate.inclusiveBetween; import static org.apache.commons.lang3.Validate.notNull; public final class Quantity { private final int value; public Quantity(final int value) { inclusiveBetween(1, 200, value); this.value = value; } public int value() { return value; } public Quantity add(final Quantity addend) { notNull(addend); return new Quantity(value + addend.value); } // ... } Quantity is not just an int! • Enforces invariants at creation • Provides domain operations to • Encapsulate domain behavior
  • 11. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Domain Primitives External context Your context Email Email Defined by RFC Defined by you
  • 12. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Domain Primitives Use Domain Primitives as: • the smallest building block in your domain model • to build your Domain Primitive Library • to harden your code and your APIs
  • 13. @DanielDeogun @DanielSawano DevDays 2017, Vilnius What we’ll cover today… ✓ Domain Primitives • Entity Snapshots • Dealing with Legacy Code • Security in your Pipelines Design Patterns Security & tests
  • 14. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Entities • An entity has an identity that doesn’t change over time • The values/data belonging to an entity can change over time • Typically modeled as mutable objects
  • 15. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Classic Entity public final class Order { private final OrderId id; private final List<OrderItem> orderItems = new ArrayList<>(); public Order(final OrderId id) { this.id = notNull(id); } public void addItem(final OrderItem item) { notNull(item); orderItems.add(item); } // ... }
  • 16. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Perils of mutable state • Mutability is a source of security issues • Consistency in the presence of contention is hard • Contention can reduce availability
  • 17. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Entity Snapshots Entity Snapshots are: • Securing mutable state by making it immutable • An immutable representation of a mutable entity • Solves many of the security problems with regular entities
  • 18. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Entity Snapshots public final class Order { private final OrderId id; private final List<OrderItem> orderItems; public Order(final OrderId id, final List<OrderItem> orderItems) { noNullElements(orderItems); notNull(id); this.id = id; this.orderItems = unmodifiableList(new ArrayList<>(orderItems)); } public List<OrderItem> orderItems() { return orderItems; } // ... }
  • 19. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Entity Snapshots public final class WritableOrder { private final OrderId id; private final OrderRepository repository; public WritableOrder(final OrderId id, final OrderRepository repository) { this.id = notNull(id); this.repository = notNull(repository); } public void addOrderItem(final OrderItem orderItem) { notNull(orderItem); isOkToAdd(orderItem); repository.addItemToOrder(id, orderItem); } private void isOkToAdd(final OrderItem orderItem) { // domain validation logic to ensure it's ok to add order } }
  • 20. @DanielDeogun @DanielSawano DevDays 2017, Vilnius What we’ll cover today… ✓ Domain Primitives ✓ Entity Snapshots • Dealing with Legacy Code • Security in your Pipelines Design Patterns Security & tests
  • 21. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Dealing with Legacy Code 3 good design patterns [6] Declutter EntitiesHarden your APIsDraw the Line [7] [8]
  • 22. @DanielDeogun @DanielSawano DevDays 2017, Vilnius “Draw the Line” [6] • 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
  • 23. @DanielDeogun @DanielSawano DevDays 2017, Vilnius “Harden the API” • Create a library of domain primitives • Express your APIs with your domain primitives • Never accept generic input if you have specific requirements Generic Specific [7] void buyBook(ISBN, Quantity)void buyBook(String, int)
  • 24. @DanielDeogun @DanielSawano DevDays 2017, Vilnius “Decluttering Entities” [8] import static org.apache.commons.lang3.Validate.notNull; import static org.apache.commons.lang3.Validate.isTrue; public class Order {
 
 private final List<Object> items;
 private boolean paid;
 
 public void addItem(String isbn, int qty) {
 if (this.paid == false) {
 notNull(isbn);
 isTrue(isbn.length() == 10);
 isTrue(isbn.matches("[0-9X]*"));
 isTrue(isbn.matches(“[0-9]{9}[0-9X]”)); if (inventory.avaliableBooks(isbn, qty)) { Book book = bookcatalogue.findBy(isbn);
 items.add(new OrderLine(book, qty));
 }
 }
 }
  • 25. @DanielDeogun @DanielSawano DevDays 2017, Vilnius “Decluttering Entities” [8] import static org.apache.commons.lang3.Validate.notNull; import static org.apache.commons.lang3.Validate.isTrue; public class Order {
 
 private final List<Object> items;
 private boolean paid;
 
 public void addItem(final ISBN isbn, final Quantity quantity) { notNull(isbn); notNull(quantity); isTrue(notPaid()); if (inventory.avaliableBooks(isbn, quantity)) { Book book = bookcatalogue.findBy(isbn);
 items.add(new OrderLine(book, quantity));
 }
 }
  • 26. @DanielDeogun @DanielSawano DevDays 2017, Vilnius What we’ll cover today… ✓ Domain Primitives ✓ Entity Snapshots ✓ Dealing with Legacy Code • Security in your Pipelines Design Patterns Security & tests
  • 27. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Security in your Pipelines [10] [12] - Unit testing
  • 28. @DanielDeogun @DanielSawano DevDays 2017, Vilnius The Hospital Case [9]
  • 29. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Email Domain Primitive External context Your context Email Email Defined by RFC Defined by you
  • 30. @DanielDeogun @DanielSawano DevDays 2017, Vilnius The Domain Rules • The format of an email address must be local-part@domain • The local part cannot be longer than 64 characters • The domain must be hospital.com • Subdomains are not accepted • The minimum length of an email address is 15 characters • The maximum length of an email address is 77 characters • The local part may only contain alphabetic characters (a-z), digits (0-9), and one period • The local part may not start or end by a period [5]
  • 31. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Testing Normal Behavior • Focus on input that clearly meets the domain rules class EmailAddressTest { @TestFactory Stream<DynamicTest> should_be_a_valid_address() { return Stream.of( "jane@hospital.com", "jane01@hospital.com", "jane.doe@hospital.com") .map(input -> dynamicTest("Accepted: " + input, () -> new EmailAddress(input))); } }
  • 32. @DanielDeogun @DanielSawano DevDays 2017, Vilnius 1st version of EmailAddress public final class EmailAddress { public final String value; public EmailAddress(final String value) { matchesPattern(value.toLowerCase(), "^[a-z0-9]+.?[a-z0-9]+@bhospital.com$"); this.value = value.toLowerCase(); } ... }
  • 33. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Testing Boundary Behavior - Acceptance • Accept an address that's exactly 15 characters long. • Accept an address with a local part that's 64 characters long. • Accept an address that's exactly 77 characters long. @TestFactory Stream<DynamicTest> should_be_accepted() { return Stream.of( "aa@hospital.com", repeat("X", 64) + "@hospital.com") .map(input -> dynamicTest("Accepted: " + input, () -> new EmailAddress(input))); } Email
  • 34. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Testing Boundary Behavior - Rejection • Reject an address that's 14 characters long • Reject an address with a local part that's 65 characters long • Reject an address with a local part containing an invalid character • Reject an address with multiple '@' symbols • Reject an address with a domain other than hospital.com • Reject an address with a subdomain • Reject an address with a local part that starts with a period • Reject an address with a local part that ends with a period • Reject an address with sequential periods in the local part
  • 35. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Testing Boundary Behavior - Rejection @TestFactory Stream<DynamicTest> should_be_rejected() { return Stream.of( "a@hospital.com", repeat("X", 65) + "@hospital.com", "address_with_invalid_char_in_local_part@hospital.com", "jane@doe@hospital.com", "jane.doe@hospital.lt", "jane.doe@hospital.io", "jane.doe@hospital.gov", "jane.doe@example.com", "jane.doe@cardio.hospital.com", ".jane.doe@hospital.com", "jane.doe.@hospital.com", "jane..doe@hospital.com") .map(input -> dynamicTest("Rejected: " + input, assertInvalidEmail(input))); }
  • 36. @DanielDeogun @DanielSawano DevDays 2017, Vilnius 2nd version of EmailAddress public final class EmailAddress { public final String value; public EmailAddress(final String value) { matchesPattern(value.toLowerCase(), "^(?=[a-z0-9.@]{15,77}$)[a-z0-9]+.?[a-z0-9]+@bhospital.com$"); this.value = value.toLowerCase(); } ... }
  • 37. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Testing with Invalid Input • Any input that doesn't satisfy the domain rules is considered invalid • For some reason, `null`, empty strings, or "strange" characters tend to result in unexpected behavior Email
  • 38. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Testing with Invalid Input @TestFactory Stream<DynamicTest> should_reject_invalid_input() { return Stream.of( null, "null", "nil", "0", "", " ", "t", "n", "john.doen@hospital.com", " @hospital.com", "%20@hospital.com", "john.d%20e@hospital.com", "john.doe.jane@hospital.com", "--", "e x a m p l e @ hospital . c o m", "=0@$*^%;<!->.:()&#"") .map(input -> dynamicTest("Rejected: " + input, assertInvalidEmail(input))); }
  • 39. @DanielDeogun @DanielSawano DevDays 2017, Vilnius 3rd version of EmailAddress public final class EmailAddress { public final String value; public EmailAddress(final String value) { notNull(value, "Input cannot be null"); matchesPattern(value.toLowerCase(), "^(?=[a-z0-9.@]{15,77}$)[a-z0-9]+.?[a-z0-9]+@bhospital.com$"); this.value = value.toLowerCase(); } ... }
  • 40. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Testing with Extreme Input • Testing the extreme is all about identifying weaknesses in the design that makes the application break or behave strangely when handling extreme values. @TestFactory Stream<DynamicTest> should_reject_extreme_input() { return Stream.<Supplier<String>>of( () -> repeat("x", 10000), () -> repeat("x", 100000), () -> repeat("x", 1000000), () -> repeat("x", 10000000), () -> repeat("x", 20000000), () -> repeat("x", 40000000)) .map(input -> dynamicTest("Rejecting extreme input", assertInvalidEmail(input.get()))); }
  • 41. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Security weaknesses caused by inefficient backtracking v.s "^[a-z0-9]+.?[a-z0-9]+@bhospital.com$" "^(?=[a-z0-9.@]{15,77}$)[a-z0-9]+.?[a-z0-9]+@bhospital.com$"
  • 42. @DanielDeogun @DanielSawano DevDays 2017, Vilnius What we have covered… ✓ Domain Primitives ✓ Entity Snapshots ✓ Dealing with Legacy Code ✓ Security in your Pipelines Design Patterns Security & tests
  • 43. @DanielDeogun @DanielSawano DevDays 2017, Vilnius URL https://manning.com Discount code: ctwdevdays Part 1: Introduction 1. Why Design Matters for Security 2. Case-Study: An Anti-Hamlet for sale Part 2: Fundamentals 3. Core concepts of Domain Driven Design 4. Code Constructs Promoting Security 5. Securing mutable state 6. Leveraging your delivery pipeline for security 7. Handling failures in a secure way 8. Case-study: Insurance policy for free 9. Integrating system of systems with security in mind 10. Benefits from cloud thinking Part 3: Applying the Fundamentals 11. Getting a fresh start in a legacy codebase 12. The subtle issues in a pretty monolith 13. Getting microservices right for security 14. A final word: don’t forget about security [1]
  • 44. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Q&A [2]
  • 45. @DanielDeogun @DanielSawano DevDays 2017, Vilnius Thank you!
 @DanielSawano @DanielDeogun
  • 46. @DanielDeogun @DanielSawano DevDays 2017, Vilnius References [1] Book cover, Secure by Design, Manning Publication [2] Question mark, https://flic.kr/p/9ksxQa by Damián Navas under license https://creativecommons.org/licenses/by-nc-nd/2.0/ [3] DDos Attack, Secure by Design, Manning Publication [4] Uber vs Ola, https://www.bloomberg.com/news/articles/2016-03-23/uber-sues-ola-claiming-fake-bookings-as-india-fight-escalates [5] Lyft vs Uber, http://time.com/3102548/lyft-uber-cancelling-rides/ [6] Boundary, https://flic.kr/p/nEZKMd by Graeme Fowler under license https://creativecommons.org/licenses/by/2.0/ [7] 3d key, https://flic.kr/p/e9qfrf by Yoel Ben-Avraham under license https://creativecommons.org/licenses/by-nd/2.0/ [8] Building blocks, https://flic.kr/p/agPw7C by Tiffany Terry under license https://creativecommons.org/licenses/by/2.0/ [9] Doctors Stock Photo, https://flic.kr/p/HNJUzV, by Sergio Santos under license https://creativecommons.org/licenses/by/2.0/ [10] Anonymous, https://flic.kr/p/a2eniw, by Lio Leiser under license https://creativecommons.org/licenses/by-nd/2.0/ [11] CIA, https://goo.gl/images/DRzRcp [12] Bilfinger - Natural gas pipeline USA, https://flic.kr/p/nrFHFz by Bilfinger SE under license https://creativecommons.org/licenses/by-nd/2.0/