1 package org.kuali.common.aws.json.jackson; 2 3 import static org.kuali.common.aws.model.ImmutableAWSSessionCredentials.copyOf; 4 import static org.kuali.common.util.encrypt.Encryption.getDefaultEncryptor; 5 6 import java.io.IOException; 7 8 import org.kuali.common.aws.model.ImmutableAWSSessionCredentials; 9 import org.kuali.common.util.encrypt.Encryptor; 10 11 import com.amazonaws.auth.AWSSessionCredentials; 12 import com.fasterxml.jackson.core.JsonGenerationException; 13 import com.fasterxml.jackson.core.JsonGenerator; 14 import com.fasterxml.jackson.databind.SerializerProvider; 15 import com.fasterxml.jackson.databind.ser.std.StdSerializer; 16 17 public final class AWSSessionCredentialsSerializer extends StdSerializer<AWSSessionCredentials> { 18 19 public AWSSessionCredentialsSerializer() { 20 super(AWSSessionCredentials.class); 21 } 22 23 private final Encryptor enc = getDefaultEncryptor(); 24 25 @Override 26 public void serialize(AWSSessionCredentials credentials, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { 27 ImmutableAWSSessionCredentials immutable = copyOf(credentials); 28 jgen.writeStartObject(); 29 jgen.writeFieldName("credentials"); 30 jgen.writeObject(immutable.getCredentials()); 31 jgen.writeStringField("sessionToken", enc.encrypt(immutable.getSessionToken())); 32 jgen.writeEndObject(); 33 } 34 35 }