如何使用 Java 代码示例补充 SharePoint 网站驱动器安全性

全球有超过 250,000 家公司/组织依靠 SharePoint 来安全地管理其最有价值的文档,用户总数超过 300 万。这种广泛的受欢迎程度使该平台成为市场领先的文档管理解决方案 - 这使其成为有动机的威胁行为者的一个有价值的目标。

当然,绕过 SharePoint 的内置安全性是一项极其艰巨的任务。O365 环境在每个入口点为租户提供强大的保护,从详尽的物理数据中心安全性到先进的应用程序安全策略。使用 SSL 和 TLS 连接的顶级文件加密来确保用户数据在传输过程中的安全,并使用具有唯一加密密钥的 BitLocker 磁盘级加密来保护静态文件。此外,随着受感染的文件上传发展成为一种极其常见的攻击媒介,O365 提供了内置的病毒和恶意软件检测策略(以及反网络钓鱼策略和各种额外的电子邮件链接和附件安全措施),这些策略可以根据个人或组织租户的需求进行广泛定制。这样的例子不胜枚举,每个租户的特定订阅级别最终决定了其内置保护的程度。

然而,尽管 SharePoint 的可自定义内置安全策略非常强大,但没有任何存储平台的策略旨在用作敏感数据的单点保护。与网络安全的任何分支一样,文档存储安全是一个不断变化的目标,需要无数解决方案协同工作,共同创建强大的防御措施,以应对不断变化的攻击媒介。换言之,任何租户的威胁配置文件始终可以通过在内置安全策略之上选择性地分层外部安全策略来改进。

在本文的其余部分,我将演示一个免费使用的病毒扫描 API 解决方案,该解决方案可以与 SharePoint 站点驱动器实例集成,以扫描文件中的病毒、恶意软件和各种非恶意软件内容威胁,并与 O365 的内置异步扫描协同工作,以根除各种文件上传威胁类型。

示范
下面的高级病毒扫描 API 旨在与 SharePoint 的内置可自定义策略结合使用,作为强大的文档存储安全层,直接扫描目标站点驱动器实例中的新文件上传,以查找不断增长的 1700 万+ 病毒和恶意软件签名列表(包括勒索软件、间谍软件、特洛伊木马等),同时还执行完整的内容验证以识别隐藏在误导性文件名和非法文件扩展名。

此 API 还允许开发人员在 API 请求正文中针对不需要的文件类型设置自定义限制,因此可以直接检测和删除各种不必要和具有潜在威胁的文件类型,而不管其内容的合法性如何。例如,存储合同文档的站点驱动器可能只需要常见的文件类型,如.DOCX或.PDF:将文件限制为这些类型有助于在不影响工作流效率的情况下最大限度地降低风险。

下面,我概述了将此 API 与 SharePoint Online Site Drive 实例集成所需的信息,并提供了可运行的 Java 代码示例,以帮助你轻松构建 API 调用。

首先,需要收集以下 SharePoint 信息,以满足 API 请求正文中的必需参数:

客户端 ID(客户端 ID 访问凭据;可从 Azure Active Directory 门户获取)Client ID (Client ID access credentials; can be obtain from Azure Active Directory portal)
客户端密码(客户端密码访问凭据;也从 Azure Active Directory 门户获取)
SharePoint 域名(即 yourdomain.sharepoint.com)
网站 ID(要从中检索和扫描文件的网站驱动器的特定 SharePoint ID)
(可选)还可以收集以下 SharePoint 信息:

租户 ID(与 Azure Active Directory 相关)Tenant ID (pertaining to your Azure Active Directory)
文件路径(站点驱动器中特定文件的路径)
项目 ID(例如,DriveItem ID)
一旦你得到了所有的必填信息,你就可以通过在Maven POM文件中添加以下对存储库的引用来开始客户端SDK的安装(JitPack用于动态编译库):

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

然后,您可以通过添加对依赖项的以下引用来结束:

<dependencies>
<dependency>
    <groupId>com.github.Cloudmersive</groupId>
    <artifactId>Cloudmersive.APIClient.Java</artifactId>
    <version>v4.25</version>
</dependency>
</dependencies>

此时,您可以添加导入并复制 Java 代码示例来构建 API 调用:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.ScanCloudStorageApi;

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");

ScanCloudStorageApi apiInstance = new ScanCloudStorageApi();
String clientID = "clientID_example"; // String | Client ID access credentials; see description above for instructions on how to get the Client ID from the Azure Active Directory portal.
String clientSecret = "clientSecret_example"; // String | Client Secret access credentials; see description above for instructions on how to get the Client Secret from the Azure Active Directory portal
String sharepointDomainName = "sharepointDomainName_example"; // String | SharePoint Online domain name, such as mydomain.sharepoint.com
String siteID = "siteID_example"; // String | Site ID (GUID) of the SharePoint site you wish to retrieve the file from
String tenantID = "tenantID_example"; // String | Optional; Tenant ID of your Azure Active Directory
String filePath = "filePath_example"; // String | Path to the file within the drive, such as 'hello.pdf' or '/folder/subfolder/world.pdf'.  If the file path contains Unicode characters, you must base64 encode the file path and prepend it with 'base64:', such as: 'base64:6ZWV6ZWV6ZWV6ZWV6ZWV6ZWV'.
String itemID = "itemID_example"; // String | SharePoint itemID, such as a DriveItem Id
Boolean allowExecutables = true; // Boolean | Set to false to block executable files (program code) from being allowed in the input file.  Default is false (recommended).
Boolean allowInvalidFiles = true; // Boolean | Set to false to block invalid files, such as a PDF file that is not really a valid PDF file, or a Word Document that is not a valid Word Document.  Default is false (recommended).
Boolean allowScripts = true; // Boolean | Set to false to block script files, such as a PHP files, Python scripts, and other malicious content or security threats that can be embedded in the file.  Set to true to allow these file types.  Default is false (recommended).
Boolean allowPasswordProtectedFiles = true; // Boolean | Set to false to block password protected and encrypted files, such as encrypted zip and rar files, and other files that seek to circumvent scanning through passwords.  Set to true to allow these file types.  Default is false (recommended).
Boolean allowMacros = true; // Boolean | Set to false to block macros and other threats embedded in document files, such as Word, Excel and PowerPoint embedded Macros, and other files that contain embedded content threats.  Set to true to allow these file types.  Default is false (recommended).
Boolean allowXmlExternalEntities = true; // Boolean | Set to false to block XML External Entities and other threats embedded in XML files, and other files that contain embedded content threats. Set to true to allow these file types. Default is false (recommended).
String restrictFileTypes = "restrictFileTypes_example"; // String | Specify a restricted set of file formats to allow as clean as a comma-separated list of file formats, such as .pdf,.docx,.png would allow only PDF, PNG and Word document files.  All files must pass content verification against this list of file formats, if they do not, then the result will be returned as CleanResult=false.  Set restrictFileTypes parameter to null or empty string to disable; default is disabled.
try {
    CloudStorageAdvancedVirusScanResult result = apiInstance.scanCloudStorageScanSharePointOnlineFileAdvanced(clientID, clientSecret, sharepointDomainName, siteID, tenantID, filePath, itemID, allowExecutables, allowInvalidFiles, allowScripts, allowPasswordProtectedFiles, allowMacros, allowXmlExternalEntities, restrictFileTypes);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling ScanCloudStorageApi#scanCloudStorageScanSharePointOnlineFileAdvanced");
    e.printStackTrace();
}

若要满足请求身份验证参数,需要提供免费层 API 密钥,该密钥允许你每月扫描多达 800 个文件。

在此请求正文中,可以将布尔值设置为对包含可执行文件、无效文件、脚本、受密码保护的文件、宏、XML 外部实体、不安全的反序列化和 HTML 的文件应用自定义非恶意软件威胁策略,并且可以在参数中提供可接受的文件类型的逗号分隔列表,以禁止不需要的文件扩展名。任何违反这些政策的文件都将自动在 API 响应正文中收到一个值,该值与分配给包含病毒和恶意软件的文件的值相同。这个想法是在单个请求中实施 360 度内容保护,以便您可以快速删除(或隔离/分析)可能对系统构成严重风险的文件。restrictFileTypesCleanResult: False

下面,我提供了一个完整的示例 API 响应供您参考:

{
  "Successful": true,
  "CleanResult": true,
  "ContainsExecutable": true,
  "ContainsInvalidFile": true,
  "ContainsScript": true,
  "ContainsPasswordProtectedFile": true,
  "ContainsRestrictedFileFormat": true,
  "ContainsMacros": true,
  "VerifiedFileFormat": "string",
  "FoundViruses": [
    {
      "FileName": "string",
      "VirusName": "string"
    }
  ],
  "ErrorDetailedDescription": "string",
  "FileSize": 0,
  "ContentInformation": {
    "ContainsJSON": true,
    "ContainsXML": true,
    "ContainsImage": true,
    "RelevantSubfileName": "string"
  }
}

值得注意的是,无论您选择如何设置自定义威胁规则,包含 JSON、XML 或嵌入式图像的文件也将在 API 响应中标记为此类。

  • 16
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小徐博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值