-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'Tesco/master'
- Loading branch information
Showing
74 changed files
with
2,318 additions
and
898 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/tesco/mewbase/auth/MewbaseAuthProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.tesco.mewbase.auth; | ||
|
||
import com.tesco.mewbase.bson.BsonObject; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* | ||
* User-facing interface for authenticating users. | ||
* | ||
*/ | ||
public interface MewbaseAuthProvider { | ||
|
||
/** | ||
* Authenticate a user. | ||
* <p> | ||
* The first argument is a Bson object containing information for authenticating the user. What this actually contains | ||
* depends on the specific implementation. In the case of a simple username/password based | ||
* authentication it is likely to contain a JSON object with the following structure: | ||
* <pre> | ||
* { | ||
* "username": "tim", | ||
* "password": "mypassword" | ||
* } | ||
* </pre> | ||
* | ||
* @param authInfo the auth information | ||
* @return a CompletableFuture containing a MewbaseUser where authorization operations can be performed | ||
* on it | ||
*/ | ||
CompletableFuture<MewbaseUser> authenticate(BsonObject authInfo); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.tesco.mewbase.auth; | ||
|
||
/** | ||
* Contains all authorization info in order to perform operations | ||
* in the Mewbase code. | ||
*/ | ||
public interface MewbaseUser { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.tesco.mewbase.auth.impl; | ||
|
||
import com.tesco.mewbase.auth.MewbaseUser; | ||
|
||
public class DummyUser implements MewbaseUser { | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/tesco/mewbase/auth/impl/MewbaseVertxAuthProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.tesco.mewbase.auth.impl; | ||
|
||
import com.tesco.mewbase.auth.MewbaseAuthProvider; | ||
import com.tesco.mewbase.auth.MewbaseUser; | ||
import com.tesco.mewbase.bson.BsonObject; | ||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.ext.auth.AuthProvider; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* | ||
* This class serves as an adapter for the {@link io.vertx.ext.auth.AuthProvider} | ||
* | ||
* It will container a {@link io.vertx.ext.auth.AuthProvider} attribute, which is then used | ||
* in the authenticate method. | ||
* | ||
* For the authentication information, the attributes just need to be inserted in the BsonObject. | ||
* | ||
* The mapping to {@link io.vertx.core.json.JsonObject} is done inside the authenticate method. | ||
* | ||
*/ | ||
public class MewbaseVertxAuthProvider implements MewbaseAuthProvider { | ||
|
||
private final static Logger log = LoggerFactory.getLogger(MewbaseVertxAuthProvider.class); | ||
|
||
private AuthProvider authProvider; | ||
|
||
public MewbaseVertxAuthProvider(AuthProvider authProvider) { | ||
this.authProvider = authProvider; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<MewbaseUser> authenticate(BsonObject authInfo) { | ||
CompletableFuture<MewbaseUser> cf = new CompletableFuture<>(); | ||
|
||
JsonObject jsonAuthInfo = new JsonObject(); | ||
authInfo.stream().forEach(entry -> { | ||
jsonAuthInfo.put(entry.getKey(), entry.getValue()); | ||
}); | ||
|
||
authProvider.authenticate(jsonAuthInfo, vertxRes -> { | ||
if (vertxRes.succeeded()) { | ||
cf.complete(new VertxUser(vertxRes.result())); | ||
} else { | ||
cf.completeExceptionally(vertxRes.cause()); | ||
} | ||
}); | ||
|
||
return cf; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/tesco/mewbase/auth/impl/NoAuthAuthProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.tesco.mewbase.auth.impl; | ||
|
||
import com.tesco.mewbase.auth.MewbaseAuthProvider; | ||
import com.tesco.mewbase.auth.MewbaseUser; | ||
import com.tesco.mewbase.bson.BsonObject; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* The default auth provider implementation that does not enforce any authentication | ||
*/ | ||
public class NoAuthAuthProvider implements MewbaseAuthProvider { | ||
|
||
@Override | ||
public CompletableFuture<MewbaseUser> authenticate(BsonObject authInfo) { | ||
return CompletableFuture.completedFuture(new DummyUser()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.tesco.mewbase.auth.impl; | ||
|
||
import com.tesco.mewbase.auth.MewbaseUser; | ||
import io.vertx.ext.auth.User; | ||
|
||
public class VertxUser implements MewbaseUser { | ||
|
||
private User user; | ||
|
||
public VertxUser(User user) { | ||
this.user = user; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
bf21b0d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging