6.2. 承認アプリケーションの移行
承認は Eclipse Vert.x 4 の新機能です。以前のリリースでは、ユーザーが User オブジェクトでタスクを実行することが許可されているかどうかを確認できました。そのため、プロバイダーはユーザーの認証と承認の両方を行います。
Eclipse Vert.x 4 では、User オブジェクトインスタンスは特定の認証プロバイダーに関連付けられていません。そのため、異なるプロバイダーを使用してユーザーを認証および承認できます。たとえば、OAuth2 を使用してユーザーを認証し、MongoDB または SQL データベースに対して承認チェックを実行できます。
以下の例は、ユーザーが Eclipse Vert.x 3.x リリースでプリンター #1234 を使用できるかどうかについてアプリケーションをチェックする方法を示しています。
// omitting the error handling for brevity
user.isAuthorized("printers:printer1234", res -> {
if (res.succeeded()) {
boolean hasAuthority = res.result();
if (hasAuthority) {
System.out.println("User can use the printer");
} else {
System.out.println("User cannot use the printer");
}
}
});
この承認は JDBC および MongoDB で有効にしました。しかし、プロバイダーは承認チェックを実行しなかったため、OAuth2 などのプロバイダーでは機能しませんでした。Eclipse Vert.x 4 以降では、異なるプロバイダーを使用してこのような承認チェックを実行できます。
// omitting the error handling for brevity
provider.getAuthorizations(user, res -> {
if (res.succeeded()) {
if (PermissionBasedAuthorization.create("printer1234").match(user)) {
System.out.println("User can use the printer");
} else {
System.out.println("User cannot use the printer");
}
}
});
承認は、ロール、パーミッション、ロジック操作、ワイルドカード、および追加するその他の実装で確認することができます。