Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
centralize auth logic
public static authorize(JsonObject authInfo, Handler<User> onAuthorized, Handler<Throwable> onFailure) {
return res -> {
if (res.succeeded()) {
User user = res.result();
user.isAuthorised("newsletter:edit:13", res2 -> {
if (res2.succeeded()) {
boolean hasPermission = res2.result();
if(hasPermission){
onAuthorized.handle(user);
}
else{
onFailure.handle(new AuthorizationException());
}
} else {
onFailure.handle(res2.cause());
}
});
} else {
onFailure.handle(res.cause());
}
}
}
import static AuthorizationLogic.authorize;
authorize(authInfo, user -> {
user.greet();
// do what you want to
}, failure -> {
if (!(failure instanceof AuthorizationException)) {
log.error("Something went wrong");
// notify client (503 ?)
} else {
// context.fail(401);
// insult user
// ban him...
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.