PageRenderTime 46ms CodeModel.GetById 4ms RepoModel.GetById 0ms app.codeStats 0ms

/README.md

http://github.com/box/box-java-sdk
Markdown | 221 lines | 155 code | 66 blank | 0 comment | 0 complexity | 4c58879d644c448bc41d5aaf8410ed9f MD5 | raw file
Possible License(s): Apache-2.0
  1. [![Project Status](http://opensource.box.com/badges/active.svg)](http://opensource.box.com/badges)
  2. Box Java SDK
  3. ============
  4. The Box Java SDK for interacting with the
  5. [Box Content API](https://developers.box.com/docs/).
  6. Getting Started Docs: https://developer.box.com/guides/tooling/sdks/java/
  7. Quickstart
  8. ----------
  9. The SDK can be obtained by adding it as a [maven dependency](http://opensource.box.com/box-java-sdk/),
  10. cloning the source into your project, or by downloading one of the precompiled JARs from the
  11. [releases page on GitHub](https://github.com/box/box-java-sdk/releases).
  12. **IF YOU USE THE JAR, you'll also need to include several dependencies:**
  13. 1. [minimal-json v0.9.5](https://github.com/ralfstx/minimal-json)
  14. Maven: `com.eclipsesource.minimal-json:minimal-json:0.9.5`
  15. 2. [jose4j v0.7.9](https://bitbucket.org/b_c/jose4j/wiki/Home)
  16. Maven: `org.bitbucket.b_c:jose4j:0.7.9`
  17. 3. [bouncycastle bcprov-jdk15on v1.60](http://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on)
  18. Maven: `org.bouncycastle:bcprov-jdk15on:1.60`
  19. 4. [bouncycastle bcpkix-jdk15on v1.60](http://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk15on)
  20. Maven: `org.bouncycastle:bcpkix-jdk15on:1.60`
  21. 5. [Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 7](http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html)
  22. If you don't install this, you'll get an exception about key length or exception about parsing PKCS private key for Box Developer Edition. This is not a Box thing, this is a U.S. Government requirement concerning strong encryption.
  23. The listed jar is for Oracle JRE. There might be other similar JARs for different JRE versions like the one below for IBM JDK
  24. [Java Cryptography Extension for IBM JDK](https://www14.software.ibm.com/webapp/iwm/web/preLogin.do?source=jcesdk)
  25. An app has to be authorized by the admin of the enterprise before these tests. It's always good to begin with the
  26. [Getting Started Section](https://developer.box.com/docs/setting-up-a-jwt-app) at Box's developer website
  27. ## Quick Test
  28. **Following things work only if the app has been configured and authorized as mentioned [here](https://developer.box.com/docs/setting-up-a-jwt-app)**
  29. Here is a simple example of how to authenticate with the API using a developer
  30. token and then print the ID and name of each item in your root folder.
  31. ```java
  32. BoxAPIConnection api = new BoxAPIConnection("developer-token");
  33. BoxFolder rootFolder = BoxFolder.getRootFolder(api);
  34. for (BoxItem.Info itemInfo : rootFolder) {
  35. System.out.format("[%s] %s\n", itemInfo.getID(), itemInfo.getName());
  36. }
  37. ```
  38. For more details on how to get started, check out the [overview guide](doc/overview.md).
  39. It has a short explanation of how the SDK works and how you can get started using it.
  40. ### Sample Projects
  41. Three sample projects can be found in `src/example`.
  42. #### Main
  43. This project will output your name and a list of the files and folders in your root directory.
  44. To run the project, first provide a developer token in
  45. `src/example/java/com/box/sdk/example/Main.java`. You can obtain a developer
  46. token from your application's [developer console](https://app.box.com/developers/services).
  47. ```java
  48. public final class Main {
  49. private static final String DEVELOPER_TOKEN = "<YOUR_DEVELOPER_TOKEN>";
  50. // ...
  51. }
  52. ```
  53. Then just invoke `gradle runExample` to run the Main example!
  54. ### Other projects
  55. Below projects need app configurations stored in JSON format in `config.json` file at location `src/example/config/`.
  56. This configuration file can be downloaded from your application's `Configuration` tab in the
  57. [developer console](https://app.box.com/developers/console)
  58. #### CreateAppUser
  59. This project will output the user id of enterprise admin and will create a new App User for the enterprise.
  60. To run the project, first provide the name of the app user in `src/example/java/com/box/sdk/example/CreateAppUser.java`.
  61. ```java
  62. public final class CreateAppUser {
  63. private static final String APP_USER_NAME = "";
  64. private static final String EXTERNAL_APP_USER_ID = "";
  65. // ...
  66. }
  67. ```
  68. Then just invoke `gradle runCreateAppUser` to run the CreateAppUser example!
  69. Note: The JCE bundled with oracle JRE supports keys upto 128 bit length only. To use larger cryptographic keys, install [JCE Unlimited Strength Jurisdiction Policy Files](http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html).
  70. #### AccessAsAppUser
  71. This project will retrieve the information of the given App User and will list the files/folders under root folder.
  72. To run the project, first provide the Id of the app user in `src/example/java/com/box/sdk/example/CreateAppUser.java`.
  73. ```java
  74. public final class AccessAsAppUser {
  75. private static final String USER_ID = "";
  76. // ...
  77. }
  78. ```
  79. Then just invoke `gradle runAccessAsAppUser` to run the AccessAsAppUser example!
  80. Note: The JCE bundled with oracle JRE supports keys upto 128 bit length only. To use larger cryptographic keys, install [JCE Unlimited Strength Jurisdiction Policy Files](http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html).
  81. #### BoxDeveloperEditionAPIConnectionAsEnterpriseUser
  82. This example shows how to get tokens for an enterprise user, say admin of the enterprise and do actions on behalf of admin.
  83. To run the project, follow below steps
  84. 1. Turn on `Enterprise` in `Application Access` section in Developer Console for the app
  85. 2. Turn on `Generate User Access Tokens` in `Advanced Features` section in Developer Console for the app
  86. 3. Provide the Id of the admin user (or any enterprise user) in `src/example/java/com/box/sdk/example/BoxDeveloperEditionAPIConnectionAsEnterpriseUser.java`.
  87. ```java
  88. public final class BoxDeveloperEditionAPIConnectionAsEnterpriseUser {
  89. private static final String USER_ID = "";
  90. ...
  91. Reader reader = new FileReader("src/example/config/config.json");
  92. BoxConfig boxConfig = BoxConfig.readFrom(reader);
  93. api = new BoxDeveloperEditionAPIConnection(USER_ID, DeveloperEditionEntityType.USER, boxConfig,
  94. accessTokenCache);
  95. ```
  96. Compatibility
  97. -------------
  98. The Box Java SDK is compatible with Java 7 and up.
  99. Building
  100. --------
  101. The SDK uses Gradle for its build system. SDK comes with Gradle wrapper. Running `./gradlew build` from the root
  102. of the repository will compile, lint, and test the SDK.
  103. ```bash
  104. $ ./gradlew build
  105. ```
  106. The SDK also includes integration tests which make real API calls, and therefore
  107. are run separately from unit tests. Integration tests should be run against a
  108. test account since they create and delete data. To run the integration tests,
  109. remove the `.template` extension from
  110. `src/test/config/config.properties.template` and fill in your test account's
  111. information. Then run:
  112. ```bash
  113. $ ./gradlew integrationTest
  114. ```
  115. Documentation
  116. -------------
  117. You can find guides and tutorials in the `doc` directory.
  118. * [BUILD ON BOX PLATFORM](https://developer.box.com/v2.0/docs/getting-started-box-platform)
  119. * [Javadocs](http://box.github.io/box-java-sdk/javadoc/com/box/sdk/package-summary.html)
  120. * [Overview](doc/overview.md)
  121. * [Authentication](doc/authentication.md)
  122. * [Files](doc/files.md)
  123. * [Folders](doc/folders.md)
  124. * [Comments](doc/comments.md)
  125. * [Collaborations](doc/collaborations.md)
  126. * [Events](doc/events.md)
  127. * [Search](doc/search.md)
  128. * [Users](doc/users.md)
  129. * [Groups](doc/groups.md)
  130. * [Tasks](doc/tasks.md)
  131. * [Trash](doc/trash.md)
  132. * [Collections](doc/collections.md)
  133. * [Devices](doc/devices.md)
  134. * [Retention Policies](doc/retention_policies.md)
  135. * [Legal Holds Policy](doc/legal_holds.md)
  136. * [Watermarking](doc/watermarking.md)
  137. * [Webhooks](doc/webhooks.md)
  138. * [Web Links](doc/weblinks.md)
  139. * [Metadata Templates](doc/metadata_template.md)
  140. * [Classifications](doc/classifications.md)
  141. * [Recent Items](doc/recent_items.md)
  142. Javadocs are generated when `gradle javadoc` is run and can be found in
  143. `build/doc/javadoc`.
  144. Copyright and License
  145. ---------------------
  146. Copyright 2019 Box, Inc. All rights reserved.
  147. Licensed under the Apache License, Version 2.0 (the "License");
  148. you may not use this file except in compliance with the License.
  149. You may obtain a copy of the License at
  150. http://www.apache.org/licenses/LICENSE-2.0
  151. Unless required by applicable law or agreed to in writing, software
  152. distributed under the License is distributed on an "AS IS" BASIS,
  153. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  154. See the License for the specific language governing permissions and
  155. limitations under the License.