diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/OzoneTokenIdentifier.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/OzoneTokenIdentifier.java index 84ee0464f91..610be844fc2 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/OzoneTokenIdentifier.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/OzoneTokenIdentifier.java @@ -31,7 +31,6 @@ import org.apache.hadoop.hdds.annotation.InterfaceAudience; import org.apache.hadoop.hdds.annotation.InterfaceStability; import org.apache.hadoop.io.DataInputBuffer; -import org.apache.hadoop.io.DataOutputBuffer; import org.apache.hadoop.io.Text; import org.apache.hadoop.io.WritableUtils; import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMTokenProto; @@ -89,35 +88,6 @@ public Text getKind() { return KIND_NAME; } - /** Instead of relying on proto serialization, this - * provides explicit serialization for OzoneTokenIdentifier. - * @return byte[] - */ - public byte[] toUniqueSerializedKey() { - DataOutputBuffer buf = new DataOutputBuffer(); - try { - super.write(buf); - WritableUtils.writeVInt(buf, getTokenType().getNumber()); - // Set s3 specific fields. - if (getTokenType().equals(S3AUTHINFO)) { - WritableUtils.writeString(buf, getAwsAccessId()); - WritableUtils.writeString(buf, getSignature()); - WritableUtils.writeString(buf, getStrToSign()); - } else { - if (StringUtils.isNotEmpty(getOmCertSerialId())) { - WritableUtils.writeString(buf, getOmCertSerialId()); - } else { - WritableUtils.writeString(buf, getSecretKeyId()); - } - WritableUtils.writeString(buf, getOmServiceId()); - } - } catch (java.io.IOException e) { - throw new IllegalArgumentException( - "Can't encode the the raw data ", e); - } - return buf.getData(); - } - /** Instead of relying on proto deserialization, this * provides explicit deserialization for OzoneTokenIdentifier. * @return byte[] @@ -148,14 +118,7 @@ public OzoneTokenIdentifier fromUniqueSerializedKey(byte[] rawData) return this; } - /** - * Overrides default implementation to write using Protobuf. - * - * @param out output stream - * @throws IOException - */ - @Override - public void write(DataOutput out) throws IOException { + public OMTokenProto toProtoBuf() throws IOException { OMTokenProto.Builder builder = OMTokenProto.newBuilder() .setMaxDate(getMaxDate()) .setType(getTokenType()) @@ -182,9 +145,18 @@ public void write(DataOutput out) throws IOException { builder.setOmServiceId(getOmServiceId()); } } + return builder.build(); + } - OMTokenProto token = builder.build(); - out.write(token.toByteArray()); + /** + * Overrides default implementation to write using Protobuf. + * + * @param out output stream + * @throws IOException + */ + @Override + public void write(DataOutput out) throws IOException { + out.write(toProtoBuf().toByteArray()); } /** diff --git a/hadoop-ozone/interface-client/src/main/proto/OmClientProtocol.proto b/hadoop-ozone/interface-client/src/main/proto/OmClientProtocol.proto index a83ff9cc974..c24b1a01296 100644 --- a/hadoop-ozone/interface-client/src/main/proto/OmClientProtocol.proto +++ b/hadoop-ozone/interface-client/src/main/proto/OmClientProtocol.proto @@ -1457,7 +1457,7 @@ message OMTokenProto { optional string accessKeyId = 12; optional string signature = 13; optional string strToSign = 14; - optional string omServiceId = 15; + optional string omServiceId = 15 [deprecated = true]; optional string secretKeyId = 16; } diff --git a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/TokenIdentifierCodec.java b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/TokenIdentifierCodec.java index edf65ae2247..84203b1f65a 100644 --- a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/TokenIdentifierCodec.java +++ b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/TokenIdentifierCodec.java @@ -48,10 +48,10 @@ public Class getTypeClass() { } @Override - public byte[] toPersistedFormat(OzoneTokenIdentifier object) { + public byte[] toPersistedFormat(OzoneTokenIdentifier object) throws IOException { Preconditions .checkNotNull(object, "Null object can't be converted to byte array."); - return object.toUniqueSerializedKey(); + return object.toProtoBuf().toByteArray(); } @Override @@ -60,11 +60,11 @@ public OzoneTokenIdentifier fromPersistedFormat(byte[] rawData) Preconditions.checkNotNull(rawData, "Null byte array can't converted to real object."); try { - OzoneTokenIdentifier object = OzoneTokenIdentifier.newInstance(); - return object.fromUniqueSerializedKey(rawData); + return OzoneTokenIdentifier.readProtoBuf(rawData); } catch (IOException ex) { try { - return OzoneTokenIdentifier.readProtoBuf(rawData); + OzoneTokenIdentifier object = OzoneTokenIdentifier.newInstance(); + return object.fromUniqueSerializedKey(rawData); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException( "Can't encode the the raw data from the byte array", e);