Skip to content

Commit 6c01b81

Browse files
committed
Unwrap log guard condition.
1 parent 695cd8e commit 6c01b81

File tree

8 files changed

+22
-66
lines changed

8 files changed

+22
-66
lines changed

hub/src/main/java/ch/iterate/hub/crypto/wot/WoT.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ public static int computeTrustLevel(final UserDto trustedUser, final TrustedUser
134134
return signatureChain.size();
135135
}
136136
catch(SecurityFailure | NoSuchAlgorithmException | InvalidKeySpecException | NotECKeyException e) {
137-
if(log.isWarnEnabled()) {
138-
log.warn("WoT signature verification failed.", e);
139-
}
137+
log.warn("Web of Trust signature chain verification failed for user {}", trustedUser, e);
140138
return -1; // unverified
141139
}
142140
}
@@ -157,27 +155,21 @@ public static Map<TrustedUserDto, Integer> verifyTrusts(final List<TrustedUserDt
157155
for(final TrustedUserDto trust : trusts) {
158156
final String trustedUserId = trust.getTrustedUserId();
159157
if(trustedUserId == null) {
160-
if(log.isWarnEnabled()) {
161-
log.warn("Verification for {} failed. No ID found for trustee.", trust);
162-
}
158+
log.warn("Verification for {} failed. No ID found for trustee.", trust);
163159
continue;
164160
}
165161
final UserDto user = users.stream().filter(u -> trustedUserId.equals(u.getId())).findFirst().orElse(null);
166162
final List<String> signatureChain = trust.getSignatureChain();
167163
if(user == null || signatureChain == null) {
168-
if(log.isWarnEnabled()) {
169-
log.warn("Verification for {} failed. No user or no signature chain found.", trust);
170-
}
164+
log.warn("Verification for {} failed. No user or no signature chain found.", trust);
171165
continue;
172166
}
173167
try {
174168
WoT.verifyRecursive(signatureChain, signerPublicKey, SignedKeys.fromUser(user));
175169
verified.put(trust, signatureChain.size());
176170
}
177171
catch(SecurityFailure e) {
178-
if(log.isWarnEnabled()) {
179-
log.warn("Verification for {} failed - not granting access.", trust, e);
180-
}
172+
log.warn("Verification for {} failed - not granting access.", trust, e);
181173
}
182174
}
183175
return verified;

hub/src/main/java/ch/iterate/hub/protocols/hub/HubCryptoVault.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ public HubCryptoVault(final Path home, final String masterkey, final String conf
6464
// TODO https://github.com/shift7-ch/cipherduck-hub/issues/19 review @dko check method signature?
6565
public synchronized Path create(final Session<?> session, final String region, final VaultCredentials credentials, final int version, final String metadata, final String rootDirHash) throws BackgroundException {
6666
final Path home = new Path(session.getHost().getDefaultPath(), EnumSet.of(AbstractPath.Type.directory));
67-
if(log.isDebugEnabled()) {
68-
log.debug("Uploading vault template {} in {} ", home, session.getHost());
69-
}
67+
log.debug("Uploading vault template {} in {} ", home, session.getHost());
7068

7169
// N.B. there seems to be no API to check write permissions without actually writing.
7270
if(!session.getFeature(ListService.class).list(home, new DisabledListProgressListener()).isEmpty()) {
@@ -84,9 +82,7 @@ public synchronized Path create(final Session<?> session, final String region, f
8482
final Path secondLevel = new Path(String.format("/%s/d/%s/%s/", session.getHost().getDefaultPath(), rootDirHash.substring(0, 2), rootDirHash.substring(2)), EnumSet.of(AbstractPath.Type.directory));
8583
final Path firstLevel = secondLevel.getParent();
8684
final Path dataDir = firstLevel.getParent();
87-
if(log.isDebugEnabled()) {
88-
log.debug("Create vault root directory at {}", secondLevel);
89-
}
85+
log.debug("Create vault root directory at {}", secondLevel);
9086
final TransferStatus status = (new TransferStatus()).withRegion(region);
9187

9288
directory.mkdir(dataDir, status);

hub/src/main/java/ch/iterate/hub/protocols/hub/HubStorageProfileSyncSchedulerService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ public Optional<ProfileDescription> compare(final Set<ProfileDescription> reposi
6262
if(p.isInstalled()) {
6363
continue;
6464
}
65-
if(log.isInfoEnabled()) {
66-
log.info("Register {}", p);
67-
}
65+
log.info("Register {}", p);
6866
p.getFile().ifPresent(registry::register);
6967
}
7068
return profiles;

hub/src/main/java/ch/iterate/hub/protocols/hub/HubStorageVaultSyncSchedulerService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ public List<VaultDto> operate(final PasswordCallback callback) throws Background
8787
bookmark.getCredentials().reset();
8888
}
8989
bookmarks.add(bookmark);
90-
if(log.isInfoEnabled()) {
91-
log.info("Added bookmark {} for vault {} for hub {}", bookmarks, vaultDto, session.getHost());
92-
}
90+
log.info("Added bookmark {} for vault {} for hub {}", bookmarks, vaultDto, session.getHost());
9391
}
9492
}
9593
catch(AccessDeniedException e) {

hub/src/main/java/ch/iterate/hub/protocols/s3/STSChainedAssumeRoleRequestInterceptor.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ public void refresh() {
8585
// nothing to do
8686
}
8787
});
88-
if(log.isDebugEnabled()) {
89-
log.debug("Chained assume role for {}", bookmark);
90-
}
88+
log.debug("Chained assume role for {}", bookmark);
9189
log.debug("Assume role with temporary credentials {}", tokens);
9290
final PreferencesReader preferences = new HostPreferences(bookmark);
9391
if(preferences.getInteger(S3AutoLoadVaultProtocol.S3_ASSUMEROLE_DURATIONSECONDS) != -1) {
@@ -124,13 +122,9 @@ public void refresh() {
124122
.withValue(preferences.getProperty(S3AutoLoadVaultProtocol.OAUTH_TOKENEXCHANGE_ADDITIONAL_SCOPES))));
125123
}
126124
try {
127-
if(log.isDebugEnabled()) {
128-
log.debug("Use request {}", request);
129-
}
125+
log.debug("Use request {}", request);
130126
final AssumeRoleResult result = service.assumeRole(request);
131-
if(log.isDebugEnabled()) {
132-
log.debug("Received assume role result {} for host {}", result, bookmark);
133-
}
127+
log.debug("Received assume role result {} for host {}", result, bookmark);
134128
return new TemporaryAccessTokens(result.getCredentials().getAccessKeyId(),
135129
result.getCredentials().getSecretAccessKey(),
136130
result.getCredentials().getSessionToken(),

hub/src/main/java/ch/iterate/hub/protocols/s3/TokenExchangeRequestInterceptor.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,14 @@ public OAuthTokens exchange(final OAuthTokens previous) throws BackgroundExcepti
9292
scopes.addAll(Arrays.asList(preferences.getProperty(S3AutoLoadVaultProtocol.OAUTH_TOKENEXCHANGE_ADDITIONAL_SCOPES).split(" ")));
9393
}
9494
request.setScopes(scopes);
95-
if(log.isDebugEnabled()) {
96-
log.debug("Token exchange request {} for {}", request, bookmark);
97-
}
95+
log.debug("Token exchange request {} for {}", request, bookmark);
9896
try {
9997
final TokenResponse tokenExchangeResponse = request.execute();
10098
// N.B. token exchange with Id token does not work!
10199
final OAuthTokens tokens = new OAuthTokens(tokenExchangeResponse.getAccessToken(),
102100
tokenExchangeResponse.getRefreshToken(),
103101
System.currentTimeMillis() + tokenExchangeResponse.getExpiresInSeconds() * 1000);
104-
if(log.isDebugEnabled()) {
105-
log.debug("Received exchanged token {} for {}", tokens, bookmark);
106-
}
102+
log.debug("Received exchanged token {} for {}", tokens, bookmark);
107103
return tokens;
108104
}
109105
catch(TokenResponseException e) {

hub/src/main/java/ch/iterate/hub/workflows/CreateVaultService.java

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ public void createVault(final StorageProfileDtoWrapper storageProfileWrapper, fi
8585
.enabled(vaultModel.automaticAccessGrant())
8686
.maxWotDepth(vaultModel.maxWotLevel())
8787
);
88-
if(log.isDebugEnabled()) {
89-
log.debug("Created metadata JWE {}", metadataJWE);
90-
}
88+
log.debug("Created metadata JWE {}", metadataJWE);
9189
final String uvfMetadataFile = metadataJWE.encrypt(
9290
String.format("%s/api", new HostUrlProvider(false, true).get(hubSession.getHost())),
9391
vaultModel.vaultId(),
@@ -109,9 +107,7 @@ public void createVault(final StorageProfileDtoWrapper storageProfileWrapper, fi
109107
// TODO https://github.com/shift7-ch/cipherduck-hub/issues/19 do we need to store here?
110108
.rootDirHash(metadataJWE.computeRootDirIdHash(metadataJWE.computeRootDirId()))
111109
.region(metadataJWE.storage().getRegion());
112-
if(log.isDebugEnabled()) {
113-
log.debug("Created storage dto {}", storageDto);
114-
}
110+
log.debug("Created storage dto {}", storageDto);
115111
final Host bookmark = HubStorageVaultSyncSchedulerService.toBookmark(hubSession.getHost(), vaultDto.getId(), metadataJWE.storage());
116112
if(storageProfileWrapper.getStsEndpoint() == null) {
117113
// permanent: template upload into existing bucket
@@ -134,24 +130,18 @@ public void createVault(final StorageProfileDtoWrapper storageProfileWrapper, fi
134130
String.format("%s%s", storageProfileWrapper.getBucketPrefix(), vaultDto.getId()),
135131
storageProfileWrapper.getBucketAcceleration()
136132
);
137-
if(log.isDebugEnabled()) {
138-
log.debug("Create STS bucket {} for vault {}", storageDto, vaultDto);
139-
}
133+
log.debug("Create STS bucket {} for vault {}", storageDto, vaultDto);
140134
new StorageResourceApi(hubSession.getClient()).apiStorageVaultIdPut(vaultDto.getId(),
141135
storageDto.awsAccessKey(stsTokens.getAccessKeyId())
142136
.awsSecretKey(stsTokens.getSecretAccessKey())
143137
.sessionToken(stsTokens.getSessionToken()));
144138
}
145139
// create vault in hub
146-
if(log.isDebugEnabled()) {
147-
log.debug("Create vault {}", vaultDto);
148-
}
140+
log.debug("Create vault {}", vaultDto);
149141
new VaultResourceApi(hubSession.getClient()).apiVaultsVaultIdPut(vaultDto.getId(), vaultDto);
150142

151143
// upload JWE
152-
if(log.isDebugEnabled()) {
153-
log.debug("Upload JWE {} for vault {}", uvfMetadataFile, vaultDto);
154-
}
144+
log.debug("Upload JWE {} for vault {}", uvfMetadataFile, vaultDto);
155145
final UserDto userDto = new UsersResourceApi(hubSession.getClient()).apiUsersMeGet(false);
156146
new VaultResourceApi(hubSession.getClient()).apiVaultsVaultIdAccessTokensPost(vaultDto.getId(), Collections.singletonMap(userDto.getId(), jwks.toOwnerAccessToken().encryptForUser(userKeys.ecdhKeyPair().getPublic())));
157147
}
@@ -164,9 +154,7 @@ public void createVault(final StorageProfileDtoWrapper storageProfileWrapper, fi
164154
}
165155

166156
private static TemporaryAccessTokens getSTSTokensFromAccessTokenWithCreateBucketInlinePoliy(final String token, final String roleArn, final String roleSessionName, final String stsEndpoint, final String bucketName, final Boolean bucketAcceleration) throws IOException {
167-
if(log.isDebugEnabled()) {
168-
log.debug("Get STS tokens from {} to pass to backend {} with role {} and session name {}", token, stsEndpoint, roleArn, roleSessionName);
169-
}
157+
log.debug("Get STS tokens from {} to pass to backend {} with role {} and session name {}", token, stsEndpoint, roleArn, roleSessionName);
170158

171159
final AssumeRoleWithWebIdentityRequest request = new AssumeRoleWithWebIdentityRequest();
172160

@@ -191,13 +179,9 @@ private static TemporaryAccessTokens getSTSTokensFromAccessTokenWithCreateBucket
191179
.build();
192180

193181

194-
if(log.isDebugEnabled()) {
195-
log.debug("Use request {}", request);
196-
}
182+
log.debug("Use request {}", request);
197183
final AssumeRoleWithWebIdentityResult result = service.assumeRoleWithWebIdentity(request);
198-
if(log.isDebugEnabled()) {
199-
log.debug("Received assume role identity result {}", result);
200-
}
184+
log.debug("Received assume role identity result {}", result);
201185
return new TemporaryAccessTokens(result.getCredentials().getAccessKeyId(),
202186
result.getCredentials().getSecretAccessKey(),
203187
result.getCredentials().getSessionToken(),

hub/src/main/java/ch/iterate/hub/workflows/GrantAccessServiceImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ public void grantAccessToUsersRequiringAccessGrant(final Host hub, final UUID va
131131
}
132132
// 3. Bulk-upload the collection of these JWEs to the server. (POST /vaults/${vaultId}/access-tokens, {"user1": "jwe1", "user2": "jwe2", ...)
133133
vaultResourceApi.apiVaultsVaultIdAccessTokensPost(vaultId, accessTokens);
134-
if(log.isInfoEnabled()) {
135-
log.info("Uploaded JWE for users {} and vault {}", accessTokens.keySet(), vaultId);
136-
}
134+
log.info("Uploaded JWE for users {} and vault {}", accessTokens.keySet(), vaultId);
137135
}
138136
}

0 commit comments

Comments
 (0)