@Test public void trustedUserCanAlterOtherAllAttributes() { AuthenticatedUser performer = givenTrustedUser(); RoleResource grantee = givenOtherRole(); RoleOptions options = givenAllOptions(); permissionChecker.checkAlterRoleAccess(performer, grantee, options); }
void checkAlterRoleAccess(AuthenticatedUser performer, RoleResource role, RoleOptions options) { if (performer.isSuper()) { return; } if (isPermissionRequired(performer, role, options) && !hasPermissionToAlterRole(performer, role)) { throw new UnauthorizedException(String.format("User %s is not authorized to alter role %s", performer.getName(), role.getRoleName())); } }
PermissionChecker { void checkAlterRoleAccess(AuthenticatedUser performer, RoleResource role, RoleOptions options) { if (performer.isSuper()) { return; } if (isPermissionRequired(performer, role, options) && !hasPermissionToAlterRole(performer, role)) { throw new UnauthorizedException(String.format("User %s is not authorized to alter role %s", performer.getName(), role.getRoleName())); } } }
PermissionChecker { void checkAlterRoleAccess(AuthenticatedUser performer, RoleResource role, RoleOptions options) { if (performer.isSuper()) { return; } if (isPermissionRequired(performer, role, options) && !hasPermissionToAlterRole(performer, role)) { throw new UnauthorizedException(String.format("User %s is not authorized to alter role %s", performer.getName(), role.getRoleName())); } } PermissionChecker();   PermissionChecker(IAuthorizer authorizer); }
PermissionChecker { void checkAlterRoleAccess(AuthenticatedUser performer, RoleResource role, RoleOptions options) { if (performer.isSuper()) { return; } if (isPermissionRequired(performer, role, options) && !hasPermissionToAlterRole(performer, role)) { throw new UnauthorizedException(String.format("User %s is not authorized to alter role %s", performer.getName(), role.getRoleName())); } } PermissionChecker();   PermissionChecker(IAuthorizer authorizer);  }
PermissionChecker { void checkAlterRoleAccess(AuthenticatedUser performer, RoleResource role, RoleOptions options) { if (performer.isSuper()) { return; } if (isPermissionRequired(performer, role, options) && !hasPermissionToAlterRole(performer, role)) { throw new UnauthorizedException(String.format("User %s is not authorized to alter role %s", performer.getName(), role.getRoleName())); } } PermissionChecker();   PermissionChecker(IAuthorizer authorizer);   }