• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-java-sdk / #3909

12 Jul 2024 01:30PM CUT coverage: 72.476% (+0.04%) from 72.438%
#3909

Pull #1258

github

web-flow
Merge 6eb7aa968 into f08844889
Pull Request #1258: test: Add test for uploading file using stream

7681 of 10598 relevant lines covered (72.48%)

0.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/box/sdk/BoxConfig.java
1
package com.box.sdk;
2

3
import com.eclipsesource.json.Json;
4
import com.eclipsesource.json.JsonObject;
5
import java.io.IOException;
6
import java.io.Reader;
7

8
/**
9
 * Contains Box configurations.
10
 */
11
public class BoxConfig {
12

13
    private String clientId;
14
    private String clientSecret;
15
    private String enterpriseId;
16
    private JWTEncryptionPreferences jwtEncryptionPreferences;
17

18
    /**
19
     * Creates a configuration with a clientId and clientSecret.
20
     *
21
     * @param clientId     the client ID of the application
22
     * @param clientSecret the client secret of the application
23
     */
24
    public BoxConfig(String clientId, String clientSecret) {
×
25
        this.clientId = clientId;
×
26
        this.clientSecret = clientSecret;
×
27
    }
×
28

29
    /**
30
     * Creates a configuration with clientId, clientSecret and JWTEncryptionPreferences.
31
     *
32
     * @param clientId                 the client ID of the application
33
     * @param clientSecret             the client secret of the application
34
     * @param enterpriseId             the enterprise ID of the box account
35
     * @param jwtEncryptionPreferences the JWTEncryptionPreferences of the application
36
     */
37
    public BoxConfig(String clientId, String clientSecret, String enterpriseId,
38
                     JWTEncryptionPreferences jwtEncryptionPreferences) {
×
39
        this.clientId = clientId;
×
40
        this.clientSecret = clientSecret;
×
41
        this.enterpriseId = enterpriseId;
×
42
        this.jwtEncryptionPreferences = jwtEncryptionPreferences;
×
43
    }
×
44

45
    /**
46
     * Creates a configuration with clientId, clientSecret, publicKeyID, privateKey, privateKeyPassword.
47
     * and an encryptionAlgorithm.
48
     *
49
     * @param clientId            the client ID of the application
50
     * @param clientSecret        the client secret of the application
51
     * @param enterpriseId        the enterprise ID of the box account
52
     * @param publicKeyID         the unique ID of the uploaded public key
53
     * @param privateKey          the private key used to sign JWT requests
54
     * @param privateKeyPassword  the passphrase for the private key
55
     * @param encryptionAlgorithm the encryption algorithm that has to be used for signing JWT requests
56
     */
57
    public BoxConfig(String clientId, String clientSecret, String enterpriseId, String publicKeyID,
58
                     String privateKey, String privateKeyPassword, EncryptionAlgorithm encryptionAlgorithm) {
×
59
        this.clientId = clientId;
×
60
        this.clientSecret = clientSecret;
×
61
        this.enterpriseId = enterpriseId;
×
62
        this.jwtEncryptionPreferences = new JWTEncryptionPreferences();
×
63
        this.jwtEncryptionPreferences.setPublicKeyID(publicKeyID);
×
64
        this.jwtEncryptionPreferences.setPrivateKey(privateKey);
×
65
        this.jwtEncryptionPreferences.setPrivateKeyPassword(privateKeyPassword);
×
66
        this.jwtEncryptionPreferences.setEncryptionAlgorithm(encryptionAlgorithm);
×
67
    }
×
68

69
    /**
70
     * Creates a configuration with RSA_SHA_256 as the encryption algorithm.
71
     *
72
     * @param clientId           the client ID of the application
73
     * @param clientSecret       the client secret of the application
74
     * @param enterpriseId       the enterprise ID of the box account
75
     * @param publicKeyID        the unique ID of the uploaded public key
76
     * @param privateKey         the private key used to sign JWT requests
77
     * @param privateKeyPassword the passphrase for the private key
78
     */
79
    public BoxConfig(String clientId, String clientSecret, String enterpriseId, String publicKeyID,
80
                     String privateKey, String privateKeyPassword) {
×
81
        this.clientId = clientId;
×
82
        this.clientSecret = clientSecret;
×
83
        this.enterpriseId = enterpriseId;
×
84
        this.jwtEncryptionPreferences = new JWTEncryptionPreferences();
×
85
        this.jwtEncryptionPreferences.setPublicKeyID(publicKeyID);
×
86
        this.jwtEncryptionPreferences.setPrivateKey(privateKey);
×
87
        this.jwtEncryptionPreferences.setPrivateKeyPassword(privateKeyPassword);
×
88
        this.jwtEncryptionPreferences.setEncryptionAlgorithm(EncryptionAlgorithm.RSA_SHA_256);
×
89
    }
×
90

91
    /**
92
     * Reads OAuth 2.0 with JWT app configurations from the reader. The file should be in JSON format.
93
     *
94
     * @param reader a reader object which points to a JSON formatted configuration file
95
     * @return a new Instance of BoxConfig
96
     * @throws IOException when unable to access the mapping file's content of the reader
97
     */
98
    public static BoxConfig readFrom(Reader reader) throws IOException {
99
        return createConfigFrom(Json.parse(reader).asObject());
×
100
    }
101

102
    /**
103
     * Reads OAuth 2.0 with JWT app configurations from the Json string.
104
     *
105
     * @param jsonString a Json stringrepresenting formatted configuration file
106
     * @return a new Instance of BoxConfig
107
     */
108
    public static BoxConfig readFrom(String jsonString) {
109
        return createConfigFrom(Json.parse(jsonString).asObject());
×
110
    }
111

112
    private static BoxConfig createConfigFrom(JsonObject config) {
113
        JsonObject settings = (JsonObject) config.get("boxAppSettings");
×
114
        String clientId = settings.get("clientID").asString();
×
115
        String clientSecret = settings.get("clientSecret").asString();
×
116
        JsonObject appAuth = (JsonObject) settings.get("appAuth");
×
117
        String publicKeyId = appAuth.get("publicKeyID").asString();
×
118
        String privateKey = appAuth.get("privateKey").asString();
×
119
        String passphrase = appAuth.get("passphrase").asString();
×
120
        String enterpriseId = config.get("enterpriseID").asString();
×
121
        return new BoxConfig(clientId, clientSecret, enterpriseId, publicKeyId, privateKey, passphrase);
×
122
    }
123

124
    /**
125
     * @return client secret
126
     */
127
    public String getClientSecret() {
128
        return this.clientSecret;
×
129
    }
130

131
    /**
132
     * @param clientSecret client secret of the application
133
     */
134
    public void setClientSecret(String clientSecret) {
135
        this.clientSecret = clientSecret;
×
136
    }
×
137

138
    /**
139
     * @return enterprise ID
140
     */
141
    public String getEnterpriseId() {
142
        return this.enterpriseId;
×
143
    }
144

145
    /**
146
     * @param enterpriseId enterprise ID of the application
147
     */
148
    public void setEnterpriseId(String enterpriseId) {
149
        this.enterpriseId = enterpriseId;
×
150
    }
×
151

152
    /**
153
     * @return JWT Encryption Preferences
154
     */
155
    public JWTEncryptionPreferences getJWTEncryptionPreferences() {
156
        return this.jwtEncryptionPreferences;
×
157
    }
158

159
    /**
160
     * @param jwtEncryptionPreferences encryption preferences for JWT based authentication
161
     */
162
    public void setJWTEncryptionPreferences(JWTEncryptionPreferences jwtEncryptionPreferences) {
163
        this.jwtEncryptionPreferences = jwtEncryptionPreferences;
×
164
    }
×
165

166
    /**
167
     * @return client ID
168
     */
169
    public String getClientId() {
170
        return this.clientId;
×
171
    }
172

173
    /**
174
     * @param clientId client ID of the Application
175
     */
176
    public void setClientId(String clientId) {
177
        this.clientId = clientId;
×
178
    }
×
179

180
    /**
181
     * Sets a custom decryptor used for decrypting the private key.
182
     *
183
     * @param privateKeyDecryptor privateKeyDecryptor the decryptor used for decrypting the private key.
184
     */
185
    public void setPrivateKeyDecryptor(IPrivateKeyDecryptor privateKeyDecryptor) {
186
        this.jwtEncryptionPreferences.setPrivateKeyDecryptor(privateKeyDecryptor);
×
187
    }
×
188
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc