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

box / box-java-sdk / #5762

01 Dec 2025 10:27AM UTC coverage: 13.282% (-0.02%) from 13.3%
#5762

push

github

web-flow
feat(boxsdkgen): Support new sign request metadata (box/box-openapi#565) (#1598)

0 of 48 new or added lines in 3 files covered. (0.0%)

15 existing lines in 9 files now uncovered.

8368 of 63001 relevant lines covered (13.28%)

0.13 hits per line

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

0.0
/src/main/java/com/box/sdkgen/box/jwtauth/JWTConfig.java
1
package com.box.sdkgen.box.jwtauth;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.readTextFromFile;
4
import static com.box.sdkgen.serialization.json.JsonManager.jsonToSerializedData;
5

6
import com.box.sdkgen.box.tokenstorage.InMemoryTokenStorage;
7
import com.box.sdkgen.box.tokenstorage.TokenStorage;
8
import com.box.sdkgen.internal.utils.DefaultPrivateKeyDecryptor;
9
import com.box.sdkgen.internal.utils.JwtAlgorithm;
10
import com.box.sdkgen.internal.utils.PrivateKeyDecryptor;
11
import com.box.sdkgen.serialization.json.EnumWrapper;
12
import com.box.sdkgen.serialization.json.JsonManager;
13

14
public class JWTConfig {
15

16
  /** App client ID */
17
  public final String clientId;
18

19
  /** App client secret */
20
  public final String clientSecret;
21

22
  /** Public key ID */
23
  public final String jwtKeyId;
24

25
  /** Private key */
26
  public final String privateKey;
27

28
  /** Passphrase */
29
  public final String privateKeyPassphrase;
30

31
  /** Enterprise ID */
32
  public String enterpriseId;
33

34
  /** User ID */
35
  public String userId;
36

37
  public EnumWrapper<JwtAlgorithm> algorithm;
38

39
  public TokenStorage tokenStorage;
40

41
  public PrivateKeyDecryptor privateKeyDecryptor;
42

43
  public JWTConfig(
44
      String clientId,
45
      String clientSecret,
46
      String jwtKeyId,
47
      String privateKey,
48
      String privateKeyPassphrase) {
×
49
    this.clientId = clientId;
×
50
    this.clientSecret = clientSecret;
×
51
    this.jwtKeyId = jwtKeyId;
×
52
    this.privateKey = privateKey;
×
53
    this.privateKeyPassphrase = privateKeyPassphrase;
×
54
    this.algorithm = new EnumWrapper<JwtAlgorithm>(JwtAlgorithm.RS256);
×
55
    this.tokenStorage = new InMemoryTokenStorage();
×
56
    this.privateKeyDecryptor = new DefaultPrivateKeyDecryptor();
×
57
  }
×
58

59
  protected JWTConfig(Builder builder) {
×
60
    this.clientId = builder.clientId;
×
61
    this.clientSecret = builder.clientSecret;
×
62
    this.jwtKeyId = builder.jwtKeyId;
×
63
    this.privateKey = builder.privateKey;
×
64
    this.privateKeyPassphrase = builder.privateKeyPassphrase;
×
65
    this.enterpriseId = builder.enterpriseId;
×
66
    this.userId = builder.userId;
×
67
    this.algorithm = builder.algorithm;
×
68
    this.tokenStorage = builder.tokenStorage;
×
69
    this.privateKeyDecryptor = builder.privateKeyDecryptor;
×
70
  }
×
71

72
  /**
73
   * Create an auth instance as defined by a string content of JSON file downloaded from the Box
74
   * Developer Console. See https://developer.box.com/en/guides/authentication/jwt/ for more
75
   * information.
76
   *
77
   * @param configJsonString String content of JSON file containing the configuration.
78
   */
79
  public static JWTConfig fromConfigJsonString(String configJsonString) {
80
    return fromConfigJsonString(configJsonString, null, null);
×
81
  }
82

83
  /**
84
   * Create an auth instance as defined by a string content of JSON file downloaded from the Box
85
   * Developer Console. See https://developer.box.com/en/guides/authentication/jwt/ for more
86
   * information.
87
   *
88
   * @param configJsonString String content of JSON file containing the configuration.
89
   * @param tokenStorage Object responsible for storing token. If no custom implementation provided,
90
   *     the token will be stored in memory
91
   */
92
  public static JWTConfig fromConfigJsonString(String configJsonString, TokenStorage tokenStorage) {
93
    return fromConfigJsonString(configJsonString, tokenStorage, null);
×
94
  }
95

96
  /**
97
   * Create an auth instance as defined by a string content of JSON file downloaded from the Box
98
   * Developer Console. See https://developer.box.com/en/guides/authentication/jwt/ for more
99
   * information.
100
   *
101
   * @param configJsonString String content of JSON file containing the configuration.
102
   * @param privateKeyDecryptor Object responsible for decrypting private key for jwt auth. If no
103
   *     custom implementation provided, the DefaultPrivateKeyDecryptor will be used.
104
   */
105
  public static JWTConfig fromConfigJsonString(
106
      String configJsonString, PrivateKeyDecryptor privateKeyDecryptor) {
107
    return fromConfigJsonString(configJsonString, null, privateKeyDecryptor);
×
108
  }
109

110
  /**
111
   * Create an auth instance as defined by a string content of JSON file downloaded from the Box
112
   * Developer Console. See https://developer.box.com/en/guides/authentication/jwt/ for more
113
   * information.
114
   *
115
   * @param configJsonString String content of JSON file containing the configuration.
116
   * @param tokenStorage Object responsible for storing token. If no custom implementation provided,
117
   *     the token will be stored in memory
118
   * @param privateKeyDecryptor Object responsible for decrypting private key for jwt auth. If no
119
   *     custom implementation provided, the DefaultPrivateKeyDecryptor will be used.
120
   */
121
  public static JWTConfig fromConfigJsonString(
122
      String configJsonString, TokenStorage tokenStorage, PrivateKeyDecryptor privateKeyDecryptor) {
123
    JwtConfigFile configJson =
×
124
        JsonManager.deserialize(jsonToSerializedData(configJsonString), JwtConfigFile.class);
×
UNCOV
125
    TokenStorage tokenStorageToUse =
×
126
        (tokenStorage == null ? new InMemoryTokenStorage() : tokenStorage);
UNCOV
127
    PrivateKeyDecryptor privateKeyDecryptorToUse =
×
128
        (privateKeyDecryptor == null ? new DefaultPrivateKeyDecryptor() : privateKeyDecryptor);
129
    JWTConfig newConfig =
×
130
        new JWTConfig.Builder(
131
                configJson.getBoxAppSettings().getClientId(),
×
132
                configJson.getBoxAppSettings().getClientSecret(),
×
133
                configJson.getBoxAppSettings().getAppAuth().getPublicKeyId(),
×
134
                configJson.getBoxAppSettings().getAppAuth().getPrivateKey(),
×
135
                configJson.getBoxAppSettings().getAppAuth().getPassphrase())
×
136
            .enterpriseId(configJson.getEnterpriseId())
×
137
            .userId(configJson.getUserId())
×
138
            .tokenStorage(tokenStorageToUse)
×
139
            .privateKeyDecryptor(privateKeyDecryptorToUse)
×
140
            .build();
×
141
    return newConfig;
×
142
  }
143

144
  /**
145
   * Create an auth instance as defined by a JSON file downloaded from the Box Developer Console.
146
   * See https://developer.box.com/en/guides/authentication/jwt/ for more information.
147
   *
148
   * @param configFilePath Path to the JSON file containing the configuration.
149
   */
150
  public static JWTConfig fromConfigFile(String configFilePath) {
151
    return fromConfigFile(configFilePath, null, null);
×
152
  }
153

154
  /**
155
   * Create an auth instance as defined by a JSON file downloaded from the Box Developer Console.
156
   * See https://developer.box.com/en/guides/authentication/jwt/ for more information.
157
   *
158
   * @param configFilePath Path to the JSON file containing the configuration.
159
   * @param tokenStorage Object responsible for storing token. If no custom implementation provided,
160
   *     the token will be stored in memory.
161
   */
162
  public static JWTConfig fromConfigFile(String configFilePath, TokenStorage tokenStorage) {
163
    return fromConfigFile(configFilePath, tokenStorage, null);
×
164
  }
165

166
  /**
167
   * Create an auth instance as defined by a JSON file downloaded from the Box Developer Console.
168
   * See https://developer.box.com/en/guides/authentication/jwt/ for more information.
169
   *
170
   * @param configFilePath Path to the JSON file containing the configuration.
171
   * @param privateKeyDecryptor Object responsible for decrypting private key for jwt auth. If no
172
   *     custom implementation provided, the DefaultPrivateKeyDecryptor will be used.
173
   */
174
  public static JWTConfig fromConfigFile(
175
      String configFilePath, PrivateKeyDecryptor privateKeyDecryptor) {
176
    return fromConfigFile(configFilePath, null, privateKeyDecryptor);
×
177
  }
178

179
  /**
180
   * Create an auth instance as defined by a JSON file downloaded from the Box Developer Console.
181
   * See https://developer.box.com/en/guides/authentication/jwt/ for more information.
182
   *
183
   * @param configFilePath Path to the JSON file containing the configuration.
184
   * @param tokenStorage Object responsible for storing token. If no custom implementation provided,
185
   *     the token will be stored in memory.
186
   * @param privateKeyDecryptor Object responsible for decrypting private key for jwt auth. If no
187
   *     custom implementation provided, the DefaultPrivateKeyDecryptor will be used.
188
   */
189
  public static JWTConfig fromConfigFile(
190
      String configFilePath, TokenStorage tokenStorage, PrivateKeyDecryptor privateKeyDecryptor) {
191
    String configJsonString = readTextFromFile(configFilePath);
×
192
    return JWTConfig.fromConfigJsonString(configJsonString, tokenStorage, privateKeyDecryptor);
×
193
  }
194

195
  public String getClientId() {
196
    return clientId;
×
197
  }
198

199
  public String getClientSecret() {
200
    return clientSecret;
×
201
  }
202

203
  public String getJwtKeyId() {
204
    return jwtKeyId;
×
205
  }
206

207
  public String getPrivateKey() {
208
    return privateKey;
×
209
  }
210

211
  public String getPrivateKeyPassphrase() {
212
    return privateKeyPassphrase;
×
213
  }
214

215
  public String getEnterpriseId() {
216
    return enterpriseId;
×
217
  }
218

219
  public String getUserId() {
220
    return userId;
×
221
  }
222

223
  public EnumWrapper<JwtAlgorithm> getAlgorithm() {
224
    return algorithm;
×
225
  }
226

227
  public TokenStorage getTokenStorage() {
228
    return tokenStorage;
×
229
  }
230

231
  public PrivateKeyDecryptor getPrivateKeyDecryptor() {
232
    return privateKeyDecryptor;
×
233
  }
234

235
  public static class Builder {
236

237
    protected final String clientId;
238

239
    protected final String clientSecret;
240

241
    protected final String jwtKeyId;
242

243
    protected final String privateKey;
244

245
    protected final String privateKeyPassphrase;
246

247
    protected String enterpriseId;
248

249
    protected String userId;
250

251
    protected EnumWrapper<JwtAlgorithm> algorithm;
252

253
    protected TokenStorage tokenStorage;
254

255
    protected PrivateKeyDecryptor privateKeyDecryptor;
256

257
    public Builder(
258
        String clientId,
259
        String clientSecret,
260
        String jwtKeyId,
261
        String privateKey,
262
        String privateKeyPassphrase) {
×
263
      this.clientId = clientId;
×
264
      this.clientSecret = clientSecret;
×
265
      this.jwtKeyId = jwtKeyId;
×
266
      this.privateKey = privateKey;
×
267
      this.privateKeyPassphrase = privateKeyPassphrase;
×
268
      this.algorithm = new EnumWrapper<JwtAlgorithm>(JwtAlgorithm.RS256);
×
269
      this.tokenStorage = new InMemoryTokenStorage();
×
270
      this.privateKeyDecryptor = new DefaultPrivateKeyDecryptor();
×
271
    }
×
272

273
    public Builder enterpriseId(String enterpriseId) {
274
      this.enterpriseId = enterpriseId;
×
275
      return this;
×
276
    }
277

278
    public Builder userId(String userId) {
279
      this.userId = userId;
×
280
      return this;
×
281
    }
282

283
    public Builder algorithm(JwtAlgorithm algorithm) {
284
      this.algorithm = new EnumWrapper<JwtAlgorithm>(algorithm);
×
285
      return this;
×
286
    }
287

288
    public Builder algorithm(EnumWrapper<JwtAlgorithm> algorithm) {
289
      this.algorithm = algorithm;
×
290
      return this;
×
291
    }
292

293
    public Builder tokenStorage(TokenStorage tokenStorage) {
294
      this.tokenStorage = tokenStorage;
×
295
      return this;
×
296
    }
297

298
    public Builder privateKeyDecryptor(PrivateKeyDecryptor privateKeyDecryptor) {
299
      this.privateKeyDecryptor = privateKeyDecryptor;
×
300
      return this;
×
301
    }
302

303
    public JWTConfig build() {
304
      return new JWTConfig(this);
×
305
    }
306
  }
307
}
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