@@ -167,10 +167,12 @@ private OkHttpClient getHttpClient(PrintWriter traceStream) {
167167 }
168168
169169 private Response httpExecute (
170- Http .Method method , Command command , Multimap <String , String > queryParamMap , byte [] body )
170+ Http .Method method ,
171+ Command command ,
172+ Multimap <String , String > queryParamMap ,
173+ byte [] body ,
174+ Credentials creds )
171175 throws IOException , MinioException {
172- Credentials creds = getCredentials ();
173-
174176 HttpUrl .Builder urlBuilder =
175177 this .baseUrl
176178 .newBuilder ()
@@ -224,7 +226,21 @@ private Response execute(
224226 Http .Method method , Command command , Multimap <String , String > queryParamMap , byte [] body )
225227 throws MinioException {
226228 try {
227- return httpExecute (method , command , queryParamMap , body );
229+ return httpExecute (method , command , queryParamMap , body , getCredentials ());
230+ } catch (IOException e ) {
231+ throw new MinioException (e );
232+ }
233+ }
234+
235+ private Response execute (
236+ Http .Method method ,
237+ Command command ,
238+ Multimap <String , String > queryParamMap ,
239+ byte [] body ,
240+ Credentials creds )
241+ throws MinioException {
242+ try {
243+ return httpExecute (method , command , queryParamMap , body , creds );
228244 } catch (IOException e ) {
229245 throw new MinioException (e );
230246 }
@@ -258,7 +274,8 @@ public void addUser(
258274 Http .Method .PUT ,
259275 Command .ADD_USER ,
260276 ImmutableMultimap .of ("accessKey" , accessKey ),
261- Crypto .encrypt (OBJECT_MAPPER .writeValueAsBytes (userInfo ), creds .secretKey ()))) {
277+ Crypto .encrypt (OBJECT_MAPPER .writeValueAsBytes (userInfo ), creds .secretKey ()),
278+ creds )) {
262279 } catch (JsonProcessingException e ) {
263280 throw new MinioException (e );
264281 }
@@ -292,8 +309,8 @@ public UserInfo getUserInfo(String accessKey) throws MinioException {
292309 * @throws MinioException thrown to indicate SDK exception.
293310 */
294311 public Map <String , UserInfo > listUsers () throws MinioException {
295- try ( Response response = execute ( Http . Method . GET , Command . LIST_USERS , null , null )) {
296- Credentials creds = getCredentials ();
312+ Credentials creds = getCredentials ();
313+ try ( Response response = execute ( Http . Method . GET , Command . LIST_USERS , null , null , creds )) {
297314 byte [] jsonData = Crypto .decrypt (response .body ().byteStream (), creds .secretKey ());
298315 MapType mapType =
299316 OBJECT_MAPPER
@@ -459,8 +476,8 @@ public long getBucketQuota(String bucketName) throws MinioException {
459476 .stream ()
460477 .filter (entry -> "quota" .equals (entry .getKey ()))
461478 .findFirst ()
462- .map (entry -> Long . valueOf ( entry .getValue ().toString () ))
463- .orElseThrow (() -> new IllegalArgumentException ("found not quota " ));
479+ .map (entry -> entry .getValue ().asLong ( ))
480+ .orElseThrow (() -> new IllegalArgumentException ("quota not found in response " ));
464481 } catch (IOException e ) {
465482 throw new MinioException (e );
466483 }
@@ -676,7 +693,8 @@ public Credentials addServiceAccount(
676693 Http .Method .PUT ,
677694 Command .ADD_SERVICE_ACCOUNT ,
678695 null ,
679- Crypto .encrypt (OBJECT_MAPPER .writeValueAsBytes (serviceAccount ), creds .secretKey ()))) {
696+ Crypto .encrypt (OBJECT_MAPPER .writeValueAsBytes (serviceAccount ), creds .secretKey ()),
697+ creds )) {
680698 byte [] jsonData = Crypto .decrypt (response .body ().byteStream (), creds .secretKey ());
681699 return OBJECT_MAPPER .readValue (jsonData , AddServiceAccountResponse .class ).credentials ();
682700 } catch (JsonProcessingException e ) {
@@ -691,7 +709,7 @@ public Credentials addServiceAccount(
691709 *
692710 * @param accessKey Access key.
693711 * @param newSecretKey New secret key.
694- * @param newPolicy New policy as JSON string .
712+ * @param newPolicy New policy as JSON string.
695713 * @param newStatus New service account status.
696714 * @param newName New service account name.
697715 * @param newDescription New description.
@@ -702,7 +720,7 @@ public void updateServiceAccount(
702720 @ Nonnull String accessKey ,
703721 @ Nullable String newSecretKey ,
704722 @ Nullable Map <String , Object > newPolicy ,
705- @ Nullable boolean newStatus ,
723+ @ Nullable Boolean newStatus ,
706724 @ Nullable String newName ,
707725 @ Nullable String newDescription ,
708726 @ Nullable ZonedDateTime newExpiration )
@@ -724,7 +742,7 @@ public void updateServiceAccount(
724742 serviceAccount .put ("newSecretKey" , newSecretKey );
725743 }
726744 if (newPolicy != null && !newPolicy .isEmpty ()) serviceAccount .put ("newPolicy" , newPolicy );
727- serviceAccount .put ("newStatus" , newStatus ? "on" : "off" );
745+ if ( newStatus != null ) serviceAccount .put ("newStatus" , newStatus ? "on" : "off" );
728746 if (newName != null && !newName .isEmpty ()) serviceAccount .put ("newName" , newName );
729747 if (newDescription != null && !newDescription .isEmpty ()) {
730748 serviceAccount .put ("newDescription" , newDescription );
@@ -739,7 +757,8 @@ public void updateServiceAccount(
739757 Http .Method .POST ,
740758 Command .UPDATE_SERVICE_ACCOUNT ,
741759 ImmutableMultimap .of ("accessKey" , accessKey ),
742- Crypto .encrypt (OBJECT_MAPPER .writeValueAsBytes (serviceAccount ), creds .secretKey ()))) {
760+ Crypto .encrypt (OBJECT_MAPPER .writeValueAsBytes (serviceAccount ), creds .secretKey ()),
761+ creds )) {
743762 } catch (JsonProcessingException e ) {
744763 throw new MinioException (e );
745764 }
@@ -777,13 +796,14 @@ public ListServiceAccountResponse listServiceAccount(@Nonnull String username)
777796 throw new IllegalArgumentException ("user name must be provided" );
778797 }
779798
799+ Credentials creds = getCredentials ();
780800 try (Response response =
781801 execute (
782802 Http .Method .GET ,
783803 Command .LIST_SERVICE_ACCOUNTS ,
784804 ImmutableMultimap .of ("user" , username ),
785- null )) {
786- Credentials creds = getCredentials ();
805+ null ,
806+ creds )) {
787807 byte [] jsonData = Crypto .decrypt (response .body ().byteStream (), creds .secretKey ());
788808 return OBJECT_MAPPER .readValue (jsonData , ListServiceAccountResponse .class );
789809 } catch (IOException e ) {
@@ -804,13 +824,14 @@ public GetServiceAccountInfoResponse getServiceAccountInfo(@Nonnull String acces
804824 if (accessKey == null || accessKey .isEmpty ()) {
805825 throw new IllegalArgumentException ("access key must be provided" );
806826 }
827+ Credentials creds = getCredentials ();
807828 try (Response response =
808829 execute (
809830 Http .Method .GET ,
810831 Command .INFO_SERVICE_ACCOUNT ,
811832 ImmutableMultimap .of ("accessKey" , accessKey ),
812- null )) {
813- Credentials creds = getCredentials ();
833+ null ,
834+ creds )) {
814835 byte [] jsonData = Crypto .decrypt (response .body ().byteStream (), creds .secretKey ());
815836 return OBJECT_MAPPER .readValue (jsonData , GetServiceAccountInfoResponse .class );
816837 } catch (IOException e ) {
@@ -824,7 +845,7 @@ private PolicyAssociationResponse attachDetachPolicy(
824845 @ Nullable String user ,
825846 @ Nullable String group )
826847 throws MinioException {
827- if (!(user != null ^ group != null )) {
848+ if (!Utils . xor (user , group )) {
828849 throw new IllegalArgumentException ("either user or group must be provided" );
829850 }
830851
@@ -842,7 +863,8 @@ private PolicyAssociationResponse attachDetachPolicy(
842863 Http .Method .POST ,
843864 command ,
844865 null ,
845- Crypto .encrypt (OBJECT_MAPPER .writeValueAsBytes (map ), creds .secretKey ()))) {
866+ Crypto .encrypt (OBJECT_MAPPER .writeValueAsBytes (map ), creds .secretKey ()),
867+ creds )) {
846868 return OBJECT_MAPPER .readValue (
847869 Crypto .decrypt (response .body ().byteStream (), creds .secretKey ()),
848870 PolicyAssociationResponse .class );
0 commit comments