55
66import com .box .sdkgen .box .tokenstorage .InMemoryTokenStorage ;
77import com .box .sdkgen .box .tokenstorage .TokenStorage ;
8+ import com .box .sdkgen .internal .utils .DefaultPrivateKeyDecryptor ;
89import com .box .sdkgen .internal .utils .JwtAlgorithm ;
10+ import com .box .sdkgen .internal .utils .PrivateKeyDecryptor ;
911import com .box .sdkgen .serialization .json .EnumWrapper ;
1012import com .box .sdkgen .serialization .json .JsonManager ;
1113
@@ -29,6 +31,8 @@ public class JWTConfig {
2931
3032 public TokenStorage tokenStorage ;
3133
34+ public PrivateKeyDecryptor privateKeyDecryptor ;
35+
3236 public JWTConfig (
3337 String clientId ,
3438 String clientSecret ,
@@ -42,6 +46,7 @@ public JWTConfig(
4246 this .privateKeyPassphrase = privateKeyPassphrase ;
4347 this .algorithm = new EnumWrapper <JwtAlgorithm >(JwtAlgorithm .RS256 );
4448 this .tokenStorage = new InMemoryTokenStorage ();
49+ this .privateKeyDecryptor = new DefaultPrivateKeyDecryptor ();
4550 }
4651
4752 protected JWTConfig (Builder builder ) {
@@ -54,46 +59,62 @@ protected JWTConfig(Builder builder) {
5459 this .userId = builder .userId ;
5560 this .algorithm = builder .algorithm ;
5661 this .tokenStorage = builder .tokenStorage ;
62+ this .privateKeyDecryptor = builder .privateKeyDecryptor ;
5763 }
5864
5965 public static JWTConfig fromConfigJsonString (String configJsonString ) {
60- return fromConfigJsonString (configJsonString , null );
66+ return fromConfigJsonString (configJsonString , null , null );
6167 }
6268
6369 public static JWTConfig fromConfigJsonString (String configJsonString , TokenStorage tokenStorage ) {
70+ return fromConfigJsonString (configJsonString , tokenStorage , null );
71+ }
72+
73+ public static JWTConfig fromConfigJsonString (
74+ String configJsonString , PrivateKeyDecryptor privateKeyDecryptor ) {
75+ return fromConfigJsonString (configJsonString , null , privateKeyDecryptor );
76+ }
77+
78+ public static JWTConfig fromConfigJsonString (
79+ String configJsonString , TokenStorage tokenStorage , PrivateKeyDecryptor privateKeyDecryptor ) {
6480 JwtConfigFile configJson =
6581 JsonManager .deserialize (jsonToSerializedData (configJsonString ), JwtConfigFile .class );
82+ TokenStorage tokenStorageToUse =
83+ (tokenStorage == null ? new InMemoryTokenStorage () : tokenStorage );
84+ PrivateKeyDecryptor privateKeyDecryptorToUse =
85+ (privateKeyDecryptor == null ? new DefaultPrivateKeyDecryptor () : privateKeyDecryptor );
6686 JWTConfig newConfig =
67- (!(tokenStorage == null )
68- ? new JWTConfig .Builder (
69- configJson .getBoxAppSettings ().getClientId (),
70- configJson .getBoxAppSettings ().getClientSecret (),
71- configJson .getBoxAppSettings ().getAppAuth ().getPublicKeyId (),
72- configJson .getBoxAppSettings ().getAppAuth ().getPrivateKey (),
73- configJson .getBoxAppSettings ().getAppAuth ().getPassphrase ())
74- .enterpriseId (configJson .getEnterpriseId ())
75- .userId (configJson .getUserId ())
76- .tokenStorage (tokenStorage )
77- .build ()
78- : new JWTConfig .Builder (
79- configJson .getBoxAppSettings ().getClientId (),
80- configJson .getBoxAppSettings ().getClientSecret (),
81- configJson .getBoxAppSettings ().getAppAuth ().getPublicKeyId (),
82- configJson .getBoxAppSettings ().getAppAuth ().getPrivateKey (),
83- configJson .getBoxAppSettings ().getAppAuth ().getPassphrase ())
84- .enterpriseId (configJson .getEnterpriseId ())
85- .userId (configJson .getUserId ())
86- .build ());
87+ new JWTConfig .Builder (
88+ configJson .getBoxAppSettings ().getClientId (),
89+ configJson .getBoxAppSettings ().getClientSecret (),
90+ configJson .getBoxAppSettings ().getAppAuth ().getPublicKeyId (),
91+ configJson .getBoxAppSettings ().getAppAuth ().getPrivateKey (),
92+ configJson .getBoxAppSettings ().getAppAuth ().getPassphrase ())
93+ .enterpriseId (configJson .getEnterpriseId ())
94+ .userId (configJson .getUserId ())
95+ .tokenStorage (tokenStorageToUse )
96+ .privateKeyDecryptor (privateKeyDecryptorToUse )
97+ .build ();
8798 return newConfig ;
8899 }
89100
90101 public static JWTConfig fromConfigFile (String configFilePath ) {
91- return fromConfigFile (configFilePath , null );
102+ return fromConfigFile (configFilePath , null , null );
92103 }
93104
94105 public static JWTConfig fromConfigFile (String configFilePath , TokenStorage tokenStorage ) {
106+ return fromConfigFile (configFilePath , tokenStorage , null );
107+ }
108+
109+ public static JWTConfig fromConfigFile (
110+ String configFilePath , PrivateKeyDecryptor privateKeyDecryptor ) {
111+ return fromConfigFile (configFilePath , null , privateKeyDecryptor );
112+ }
113+
114+ public static JWTConfig fromConfigFile (
115+ String configFilePath , TokenStorage tokenStorage , PrivateKeyDecryptor privateKeyDecryptor ) {
95116 String configJsonString = readTextFromFile (configFilePath );
96- return JWTConfig .fromConfigJsonString (configJsonString , tokenStorage );
117+ return JWTConfig .fromConfigJsonString (configJsonString , tokenStorage , privateKeyDecryptor );
97118 }
98119
99120 public String getClientId () {
@@ -132,6 +153,10 @@ public TokenStorage getTokenStorage() {
132153 return tokenStorage ;
133154 }
134155
156+ public PrivateKeyDecryptor getPrivateKeyDecryptor () {
157+ return privateKeyDecryptor ;
158+ }
159+
135160 public static class Builder {
136161
137162 protected final String clientId ;
@@ -152,6 +177,8 @@ public static class Builder {
152177
153178 protected TokenStorage tokenStorage ;
154179
180+ protected PrivateKeyDecryptor privateKeyDecryptor ;
181+
155182 public Builder (
156183 String clientId ,
157184 String clientSecret ,
@@ -165,6 +192,7 @@ public Builder(
165192 this .privateKeyPassphrase = privateKeyPassphrase ;
166193 this .algorithm = new EnumWrapper <JwtAlgorithm >(JwtAlgorithm .RS256 );
167194 this .tokenStorage = new InMemoryTokenStorage ();
195+ this .privateKeyDecryptor = new DefaultPrivateKeyDecryptor ();
168196 }
169197
170198 public Builder enterpriseId (String enterpriseId ) {
@@ -192,6 +220,11 @@ public Builder tokenStorage(TokenStorage tokenStorage) {
192220 return this ;
193221 }
194222
223+ public Builder privateKeyDecryptor (PrivateKeyDecryptor privateKeyDecryptor ) {
224+ this .privateKeyDecryptor = privateKeyDecryptor ;
225+ return this ;
226+ }
227+
195228 public JWTConfig build () {
196229 return new JWTConfig (this );
197230 }
0 commit comments