0
管理者以外のユーザーが自分のデータだけにアクセスできるようにするユーザーリソースがあるDropwizardアプリケーションがあります。私はまた、 "管理者"が任意のユーザーのデータにアクセスできるようにしたい。Dropwizardでパス内のIDに基づいてリソースへのアクセスを制御する方法
@GET
@Path("https://stackoverflow.com/users/{userId}")
@RolesAllowed(value="admin")
public Response getUser(@Auth final Client client, @PathParam("userId") final String userId)
throws InterruptedException {
return userDAO.getUser(userId);
}
私はDropwizardのAuthorizer<Principal>
インターフェイスを実装しているし、これは、少なくともリソースにアクセスするには、「管理者」の役割を持つユーザーを許可します。
@Override
public boolean authorize(Principal principal, String allowedRolesForResource) {
Set<Roles> userRoles = ((Client) principal).getRoles();
String userId = ((Client) principal).getUserId();
// Create set of all the allowed roles for the resource
Set<Roles> allowedRoles = Arrays.asList(allowedRolesForResource.split("\\s*,\\s*"))
.stream()
.map(Roles::fromName)
.collect(Collectors.toSet());
if(Collections.disjoint(userRoles, allowedRoles)) {
LOGGER.info("User {} does not have any of the allowed roles [{}] for the resource", userId, allowedRolesForResource);
return false;
}
return true;
}
しかし、管理者以外のユーザーが自分のuserIdのリソースにアクセスする権限をどのように認めることができるかわかりません。私はauthorize
メソッドの範囲に個人のuserIdを持っていますが、要求されているリソースパスはありません。つまり/ users/123です。
要求されたリソースパスとユーザーのIDに基づいてアクセスを許可できるように、要求コンテキストをAuthorizerクラスのスコープに取得する方法はありますか?