use of org.apache.hadoop.ozone.om.response.s3.security.S3RevokeSecretResponse in project ozone by apache.
the class S3RevokeSecretRequest method validateAndUpdateCache.
@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
OMClientResponse omClientResponse = null;
OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
boolean acquiredLock = false;
IOException exception = null;
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
final RevokeS3SecretRequest revokeS3SecretRequest = getOmRequest().getRevokeS3SecretRequest();
String kerberosID = revokeS3SecretRequest.getKerberosID();
try {
acquiredLock = omMetadataManager.getLock().acquireWriteLock(S3_SECRET_LOCK, kerberosID);
// Remove if entry exists in table
if (omMetadataManager.getS3SecretTable().isExist(kerberosID)) {
// Invalid entry in table cache immediately
omMetadataManager.getS3SecretTable().addCacheEntry(new CacheKey<>(kerberosID), new CacheValue<>(Optional.absent(), transactionLogIndex));
omClientResponse = new S3RevokeSecretResponse(kerberosID, omResponse.setStatus(Status.OK).build());
} else {
omClientResponse = new S3RevokeSecretResponse(null, omResponse.setStatus(Status.S3_SECRET_NOT_FOUND).build());
}
} catch (IOException ex) {
exception = ex;
omClientResponse = new S3RevokeSecretResponse(null, createErrorOMResponse(omResponse, ex));
} finally {
addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
if (acquiredLock) {
omMetadataManager.getLock().releaseWriteLock(S3_SECRET_LOCK, kerberosID);
}
}
Map<String, String> auditMap = new HashMap<>();
auditMap.put(OzoneConsts.S3_REVOKESECRET_USER, kerberosID);
auditLog(ozoneManager.getAuditLogger(), buildAuditMessage(OMAction.REVOKE_S3_SECRET, auditMap, exception, getOmRequest().getUserInfo()));
if (exception == null) {
if (omResponse.getStatus() == Status.OK) {
LOG.info("Secret for {} is revoked.", kerberosID);
} else {
LOG.info("Secret for {} doesn't exist.", kerberosID);
}
} else {
LOG.error("Error when revoking secret for {}.", kerberosID, exception);
}
return omClientResponse;
}
Aggregations