Skip to content

Commit 5fa295a

Browse files
committed
typesafe config examples
1 parent 4fdd479 commit 5fa295a

5 files changed

Lines changed: 35 additions & 10 deletions

File tree

‎gradle/dependencies.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ext {
55
okhttp : '3.6.0', // HTTP Client
66
slf4j : '1.7.21', // Logging
77
logback : '1.1.8', // Logging
8-
undertow : '1.4.8.Final', // Webserver
8+
undertow : '1.4.18.Final', // Webserver
99
metrics : '3.1.2', // Metrics
1010
guava : '22.0', // Common / Helper libraries
1111
typesafeConfig : '1.3.1', // Configuration

‎stubbornjava-common/src/main/java/com/stubbornjava/common/HttpClient.java‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
2020

21+
import okhttp3.Dispatcher;
2122
import okhttp3.Interceptor;
2223
import okhttp3.Interceptor.Chain;
2324
import okhttp3.JavaNetCookieJar;
@@ -56,12 +57,20 @@ public static Interceptor getHeaderInterceptor(String name, String value) {
5657
}
5758

5859
// {{start:client}}
59-
private static final OkHttpClient client = new OkHttpClient.Builder()
60-
.connectTimeout(2, TimeUnit.SECONDS)
61-
.writeTimeout(1, TimeUnit.MINUTES)
62-
.readTimeout(1, TimeUnit.MINUTES)
63-
.addNetworkInterceptor(loggingInterceptor)
64-
.build()
60+
private static final OkHttpClient client;
61+
static {
62+
Dispatcher dispatcher = new Dispatcher();
63+
dispatcher.setMaxRequestsPerHost(15);
64+
65+
client = new OkHttpClient.Builder()
66+
.connectTimeout(2, TimeUnit.SECONDS)
67+
.writeTimeout(1, TimeUnit.MINUTES)
68+
.readTimeout(1, TimeUnit.MINUTES)
69+
.dispatcher(dispatcher)
70+
.addNetworkInterceptor(loggingInterceptor)
71+
.build();
72+
}
73+
6574
;
6675

6776
/*

‎stubbornjava-webapp/src/main/java/com/stubbornjava/webapp/post/PostData.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,21 @@ public class PostData {
595595
))
596596
.build()
597597
);
598+
posts.add(PostRaw.builder()
599+
.postId(897427147384949867L)
600+
.title("Typesafe Config Features and Example Usage.")
601+
.metaDesc("Using Typesafe Config fallback handlers, lists, memory helper, duration helper and configuration resolution.")
602+
.dateCreated(LocalDateTime.parse("2017-08-15T01:15:30"))
603+
.dateUpdated(LocalDateTime.parse("2017-08-15T01:15:30"))
604+
.javaLibs(Lists.newArrayList(JavaLib.TypesafeConfig, JavaLib.Logback))
605+
.tags(Lists.newArrayList(Tags.Configuration))
606+
.gitFileReferences(Lists.newArrayList(
607+
FileReference.stubbornJava(
608+
"config",
609+
"stubbornjava-examples/src/main/java/com/stubbornjava/examples/common/TypesafeConfigExamples.java")
610+
))
611+
.build()
612+
);
598613
}
599614

600615
public static List<PostRaw> getPosts() {

‎stubbornjava-webapp/ui/src/posts/hashing-passwords-in-java-with-bcrypt.hbs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{{#assign "s1"}}
2-
BCrypt is a one way salted hash function based on the [Blowfish cipher](https://en.wikipedia.org/wiki/Blowfish_(cipher)). It provides several enhancements over plain text passwords (unfortunately this still happens quite often) and traditional hashing algorithms (md5). It wouldn't be accurate to say BCrypt is the best way to store passwords but it should be good enough. Algorithms such as [PBKDF2](https://en.wikipedia.org/wiki/PBKDF2) could be used as a more thoroughly tested algorithm but BCrypt is commonly used as well. `jBCrypt` is a Java implementation of BCrypt.
2+
BCrypt is a one way salted hash function based on the <a href="https://en.wikipedia.org/wiki/Blowfish_(cipher)">Blowfish cipher</a>. It provides several enhancements over plain text passwords (unfortunately this still happens quite often) and traditional hashing algorithms (md5). It wouldn't be accurate to say BCrypt is the best way to store passwords but it should be good enough. Algorithms such as [PBKDF2](https://en.wikipedia.org/wiki/PBKDF2) could be used as a more thoroughly tested algorithm but BCrypt is commonly used as well. `jBCrypt` is a Java implementation of BCrypt.
33

44
## BCrypt features
55
* **Not plain text** - Not only do plain text passwords compromise your website if the database is breached but they can also compromise other websites for the users. Unfortunately a lot of users share passwords across websites.
66
* **One way hashing** - BCrypt is a one way hash function to obfuscate the password such that it is not stored in plain text.
77
* **Salted hashing** - Generating random bytes (the salt) and combining it with the password before hashing creates unique hashes across each users password. If two users have the same password they will not have the same password hash. This is to prevent [rainbow table](https://en.wikipedia.org/wiki/Rainbow_table) attacks which can reverse hashed passwords using common hashing functions that do not utilize a salt.
88
* **Logarithmic iterations** - The hashing function is executed many times sequentially which can be increased exponentially known as [key stretching](https://en.wikipedia.org/wiki/Key_stretching). This is to make the function CPU intensive which makes it more secure against brute force attacks.
99
* **Updatable iterations** - As CPUs become faster so do brute force attacks. Since BCrypt stores the number of iterations as part of the hash it's possible to verify a password and then increase its strength by generating a new hash with a higher number of iterations.
10+
{{> templates/src/widgets/code/code-snippet file=bcrypt section=bcrypt.sections.UpdatableBCrypt}}
11+
1012

1113
## jBCrypt Example Wrapper.
1214
We will be wrapping the standard `jBCrypt` with our own methods to allow auto updating the iterations on the fly.
1315
{{/assign}}
1416
{{md s1}}
15-
{{> templates/src/widgets/code/code-snippet file=bcrypt section=bcrypt.sections.UpdatableBCrypt}}
1617

1718
{{#assign "s2"}}
1819
## Static Hashing Utility Class

‎stubbornjava-webapp/ui/src/widgets/code/code-snippet.hbs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<pre class="language-{{#if language}}{{language}}{{else}}java{{/if}} line-numbers" data-start="{{section.lineStart}}"><code>{{section.content}}</code></pre>
1+
<pre class="language-{{#if language}}{{language}}{{else}}java{{/if}} line-numbers" data-start="{{section.lineStart}}"><code>{{{section.content}}}</code></pre>
22
<div>
33
<div class="code-gh-link pull-right">
44
<a href="{{file.url}}#L{{section.lineStart}}">

0 commit comments

Comments
 (0)