Skip to content

Commit

Permalink
Merge branch 'master' of github.com:vert-x3/vertx-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
pmlopes committed Feb 13, 2017
2 parents 9101dc0 + f9f3fac commit 07fb272
Show file tree
Hide file tree
Showing 51 changed files with 390 additions and 160 deletions.
1 change: 1 addition & 0 deletions vertx-auth-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
Import-Package: \
groovy.lang.*;resolution:=optional,\
org.codehaus.groovy.*;resolution:=optional,\
kotlin.*;resolution:=optional,\
io.vertx.groovy.*;resolution:=optional,\
io.vertx.lang.rxjava.*;resolution:=optional,\
io.vertx.lang.groovy.*;resolution:=optional,\
Expand Down
4 changes: 2 additions & 2 deletions vertx-auth-common/src/main/asciidoc/groovy/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ To use this project, add the following dependency to the _dependencies_ section
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-common</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0.Beta1</version>
</dependency>
----

* Gradle (in your `build.gradle` file):
[source,groovy,subs="+attributes"]
----
compile 'io.vertx:vertx-auth-common:3.4.0-SNAPSHOT'
compile 'io.vertx:vertx-auth-common:3.4.0.Beta1'
----

== Basic concepts
Expand Down
4 changes: 2 additions & 2 deletions vertx-auth-common/src/main/asciidoc/java/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ To use this project, add the following dependency to the _dependencies_ section
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-common</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0.Beta1</version>
</dependency>
----

* Gradle (in your `build.gradle` file):
[source,groovy,subs="+attributes"]
----
compile 'io.vertx:vertx-auth-common:3.4.0-SNAPSHOT'
compile 'io.vertx:vertx-auth-common:3.4.0.Beta1'
----

== Basic concepts
Expand Down
4 changes: 2 additions & 2 deletions vertx-auth-common/src/main/asciidoc/js/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ To use this project, add the following dependency to the _dependencies_ section
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-common</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0.Beta1</version>
</dependency>
----

* Gradle (in your `build.gradle` file):
[source,groovy,subs="+attributes"]
----
compile 'io.vertx:vertx-auth-common:3.4.0-SNAPSHOT'
compile 'io.vertx:vertx-auth-common:3.4.0.Beta1'
----

== Basic concepts
Expand Down
4 changes: 2 additions & 2 deletions vertx-auth-common/src/main/asciidoc/ruby/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ To use this project, add the following dependency to the _dependencies_ section
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-common</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0.Beta1</version>
</dependency>
----

* Gradle (in your `build.gradle` file):
[source,groovy,subs="+attributes"]
----
compile 'io.vertx:vertx-auth-common:3.4.0-SNAPSHOT'
compile 'io.vertx:vertx-auth-common:3.4.0.Beta1'
----

== Basic concepts
Expand Down
1 change: 1 addition & 0 deletions vertx-auth-htdigest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
Import-Package: \
groovy.lang.*;resolution:=optional,\
org.codehaus.groovy.*;resolution:=optional,\
kotlin.*;resolution:=optional,\
io.vertx.groovy.*;resolution:=optional,\
io.vertx.lang.rxjava.*;resolution:=optional,\
io.vertx.lang.groovy.*;resolution:=optional,\
Expand Down
4 changes: 2 additions & 2 deletions vertx-auth-htdigest/src/main/asciidoc/groovy/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ dependency to the _dependencies_ section of your build descriptor:
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-htdigest</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0.Beta1</version>
</dependency>
----

* Gradle (in your `build.gradle` file):
[source,groovy,subs="+attributes"]
----
compile 'io.vertx:vertx-auth-htdigest:3.4.0-SNAPSHOT'
compile 'io.vertx:vertx-auth-htdigest:3.4.0.Beta1'
----

To create an instance you first need an .htdigest file. This file is created using the apache htdigest tool.
Expand Down
4 changes: 2 additions & 2 deletions vertx-auth-htdigest/src/main/asciidoc/java/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ dependency to the _dependencies_ section of your build descriptor:
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-htdigest</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0.Beta1</version>
</dependency>
----

* Gradle (in your `build.gradle` file):
[source,groovy,subs="+attributes"]
----
compile 'io.vertx:vertx-auth-htdigest:3.4.0-SNAPSHOT'
compile 'io.vertx:vertx-auth-htdigest:3.4.0.Beta1'
----

To create an instance you first need an .htdigest file. This file is created using the apache htdigest tool.
Expand Down
4 changes: 2 additions & 2 deletions vertx-auth-htdigest/src/main/asciidoc/js/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ dependency to the _dependencies_ section of your build descriptor:
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-htdigest</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0.Beta1</version>
</dependency>
----

* Gradle (in your `build.gradle` file):
[source,groovy,subs="+attributes"]
----
compile 'io.vertx:vertx-auth-htdigest:3.4.0-SNAPSHOT'
compile 'io.vertx:vertx-auth-htdigest:3.4.0.Beta1'
----

To create an instance you first need an .htdigest file. This file is created using the apache htdigest tool.
Expand Down
4 changes: 2 additions & 2 deletions vertx-auth-htdigest/src/main/asciidoc/ruby/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ dependency to the _dependencies_ section of your build descriptor:
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-htdigest</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0.Beta1</version>
</dependency>
----

* Gradle (in your `build.gradle` file):
[source,groovy,subs="+attributes"]
----
compile 'io.vertx:vertx-auth-htdigest:3.4.0-SNAPSHOT'
compile 'io.vertx:vertx-auth-htdigest:3.4.0.Beta1'
----

To create an instance you first need an .htdigest file. This file is created using the apache htdigest tool.
Expand Down
2 changes: 2 additions & 0 deletions vertx-auth-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
<bnd><![CDATA[
Import-Package: \
groovy.lang.*;resolution:=optional,\
org.codehaus.groovy.*;resolution:=optional,\
kotlin.*;resolution:=optional,\
io.vertx.codegen.annotations;resolution:=optional,\
io.vertx.rxjava.*;resolution:=optional,\
io.vertx.lang.groovy.*;resolution:=optional,\
Expand Down
42 changes: 35 additions & 7 deletions vertx-auth-jdbc/src/main/asciidoc/groovy/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ add the following dependency to the _dependencies_ section of your build descrip
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-jdbc</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0.Beta1</version>
</dependency>
----

* Gradle (in your `build.gradle` file):
[source,groovy,subs="+attributes"]
----
compile 'io.vertx:vertx-auth-jdbc:3.4.0-SNAPSHOT'
compile 'io.vertx:vertx-auth-jdbc:3.4.0.Beta1'
----

To create an instance you first need an instance of `link:../../apidocs/io/vertx/ext/jdbc/JDBCClient.html[JDBCClient]`. To learn how to create one
of those please consult the documentation for the JDBC client.

Once you've got one of those you can create a `link:../../apidocs/io/vertx/ext/auth/jdbc/JDBCAuth.html[JDBCAuth]` instance as follows:

[source,java]
[source,groovy]
----
import io.vertx.ext.jdbc.JDBCClient
import io.vertx.ext.auth.jdbc.JDBCAuth
def jdbcClient = JDBCClient.createShared(vertx, jdbcClientConfig)
def authProvider = JDBCAuth.create(jdbcClient)
def authProvider = JDBCAuth.create(vertx, jdbcClient)
----

Expand Down Expand Up @@ -90,12 +90,40 @@ WARNING: It is advised to always store your passwords as hashes in your database
with a salt which should be stored in the row too. A strong hashing algorithm should be used. It is strongly advised
never to store your passwords as plain text.

== Hashing passwords

Like any application there will be a time where you need to store new users into the database. Has you have learn
passwords are not stored in plain text but hashed according to the hashing strategy. The same strategy is required
to hash new password before storing it to the database. Doing it is a 3 step task.

1. Generate a salt string
2. Hash the password given the salt string
3. Store it to the database

[source,groovy]
----
def salt = auth.generateSalt()
def hash = auth.computeHash("sausages", salt)
// save to the database
conn.updateWithParams("INSERT INTO user VALUES (?, ?, ?)", [
"tim",
hash,
salt
], { res ->
if (res.succeeded()) {
// success!
}
})
----

== Authentication

When authenticating using this implementation, it assumes `username` and `password` fields are present in the
authentication info:

[source,java]
[source,groovy]
----
def authInfo = [
Expand All @@ -122,7 +150,7 @@ can have zero or more permissions.
If validating if a user has a particular permission simply pass the permission into.
`link:../../apidocs/io/vertx/ext/auth/User.html#isAuthorised-java.lang.String-io.vertx.core.Handler-[isAuthorised]` as follows:

[source,java]
[source,groovy]
----
user.isAuthorised("commit_code", { res ->
Expand All @@ -138,7 +166,7 @@ user.isAuthorised("commit_code", { res ->

If validating that a user has a particular _role_ then you should prefix the argument with the role prefix.

[source,java]
[source,groovy]
----
user.isAuthorised("role:manager", { res ->
Expand Down
28 changes: 25 additions & 3 deletions vertx-auth-jdbc/src/main/asciidoc/java/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ add the following dependency to the _dependencies_ section of your build descrip
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-jdbc</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0.Beta1</version>
</dependency>
----

* Gradle (in your `build.gradle` file):
[source,groovy,subs="+attributes"]
----
compile 'io.vertx:vertx-auth-jdbc:3.4.0-SNAPSHOT'
compile 'io.vertx:vertx-auth-jdbc:3.4.0.Beta1'
----

To create an instance you first need an instance of `link:../../apidocs/io/vertx/ext/jdbc/JDBCClient.html[JDBCClient]`. To learn how to create one
Expand All @@ -33,7 +33,7 @@ Once you've got one of those you can create a `link:../../apidocs/io/vertx/ext/a
----
JDBCClient jdbcClient = JDBCClient.createShared(vertx, jdbcClientConfig);
JDBCAuth authProvider = JDBCAuth.create(jdbcClient);
JDBCAuth authProvider = JDBCAuth.create(vertx, jdbcClient);
----

Once you've got your instance you can authenticate and authorise with it just like any `link:../../apidocs/io/vertx/ext/auth/AuthProvider.html[AuthProvider]`.
Expand Down Expand Up @@ -86,6 +86,28 @@ WARNING: It is advised to always store your passwords as hashes in your database
with a salt which should be stored in the row too. A strong hashing algorithm should be used. It is strongly advised
never to store your passwords as plain text.

== Hashing passwords

Like any application there will be a time where you need to store new users into the database. Has you have learn
passwords are not stored in plain text but hashed according to the hashing strategy. The same strategy is required
to hash new password before storing it to the database. Doing it is a 3 step task.

1. Generate a salt string
2. Hash the password given the salt string
3. Store it to the database

[source,java]
----
String salt = auth.generateSalt();
String hash = auth.computeHash("sausages", salt);
// save to the database
conn.updateWithParams("INSERT INTO user VALUES (?, ?, ?)", new JsonArray().add("tim").add(hash).add(salt), res -> {
if (res.succeeded()) {
// success!
}
});
----

== Authentication

When authenticating using this implementation, it assumes `username` and `password` fields are present in the
Expand Down

0 comments on commit 07fb272

Please sign in to comment.